Requirements
E.g. resourceA.attribute1 = "CAT" AND resourceA.subResourceB.attribute2 >= 42 AND resourceA.attribute3 IN ("WHIZ","BANG")
I've investigated four solutions - each getting closer to the goal. Is there some other solution I haven't found or is there no such complete solution out of the box - is the answer to build upon the "REST query language with RSQL" outlined below?
1) spring-data-rest queries
There is plenty of support in spring data for developing complex queries in code, however this requires the developer to be aware of the structure of queries beforehand and to construct the code accordingly. https://docs.spring.io/spring-data/rest/docs/current/reference/html/#repository-resources.query-method-resource
2) spring-data, spring-data-rest, query-dsl
http://www.baeldung.com/rest-api-search-querydsl-web-in-spring-data-jpa
+ve An excellent fit - thoroughly capable solution with almost zero coding out of the box
+ve deeply nested queries can be constructed and the server generates correct SQL on the fly.
-ve the only operator is EQUALS '=' in order to apply additional operators you need to implement QuerydslBinderCustomizer instances which once again requires the server code to be aware of the complexity of the query in advance.
https://docs.spring.io/spring-data/commons/docs/current/api/org/springframework/data/querydsl/binding/QuerydslBinderCustomizer.html
3) Baeldung - "building a rest query language"
http://www.baeldung.com/spring-rest-api-query-search-language-tutorial
+ve - getting closer to generic query language
-ve - feels like a demo / POC
4) REST Query Language with RSQL
http://www.baeldung.com/rest-api-search-language-rsql-fiql
+ve - feels like a more complete Query language & associated parser
-ve - unsure of spring integration
Crud Repository is the base interface and it acts as a marker interface. JPA also provides some extra methods related to JPA such as delete records in batch and flushing data directly to a database. It provides only CRUD functions like findOne, saves, etc. JPA repository also extends the PagingAndSorting repository.
SPring Data Jpa Specifications helps us to create dynamic queries based on the requirement at run time. Spring Data Jpa Specifications allows a combination of the attributes or properties of a domain or entity class and creates a query.
This repository is an interface that lets you perform various operations involving Person objects. It gets these operations by extending the PagingAndSortingRepository interface that is defined in Spring Data Commons. At runtime, Spring Data REST automatically creates an implementation of this interface.
Spring Data REST builds on top of Spring Data repositories, analyzes your application's domain model and exposes hypermedia-driven HTTP resources for aggregates contained in the model.
There is no generic REST query language for JPA. What you've identified seems to be what is out there, however the low recent activity on querydsl and rsql suggests that you should use caution when adopting them. You will most likely have to support additional changes yourself by forking the projects, especially 5 years from now when for sure the author has moved on to other things.
Some other interesting links:
5) Use annotations to dynamically build queries
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With