I'm trying to migrate spring boot application from mssql to CosmosDb.
We have the below repository implementation using org.springframework.data.jpa.domain.Specification;
which can fetch data based on any (one or more) columns requested by the user.
static Specification<User> isMatching(final Map<String, String> parameters) {
return new Specification<User>() {
private static final long serialVersionUID = 1L;
public Predicate toPredicate(Root<User> root, CriteriaQuery<?> query, CriteriaBuilder builder) {
List<Predicate> predicates = new ArrayList<>();
parameters.entrySet().forEach(e -> {
predicates.add(builder.and(builder.equal(root.get(e.getKey()), e.getValue())));
});
return builder.and(predicates.toArray(new Predicate[predicates.size()]));
}
};
}
and then we are calling this as below:
repo.findAll(UserRepo.isMatching(parameters));
I had to remove spring-boot-starter-data-jpa from classpath as it will not support CosmosDb. I'm using the below spring and spring data cosmos references in classpath as that is the only combination working for me.
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.3.RELEASE</version>
<relativePath />
</parent>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-spring-data-cosmos</artifactId>
<version>3.0.0</version>
</dependency>
I couldn't really figure out how I can implement the above Specification logic for CosmosDb. I would really appreciate any guidance regarding this. Thanks in advance!