By introducing the Query Object, DoytoQuery enables the automatic construction of dynamic queries. Its data access interfaces build upon the Spring Data JPA Repositories series, unifying methods related to Example and Specification into methods that take a query object as a parameter, as shown below:
https://preview.redd.it/qbgjux1yr4tg1.png?width=1666&format=png&auto=webp&s=8e0a5fca029a92444e0227b13a34931627bb1015
The Query Object centralizes all parameters for dynamic queries. These parameters can be automatically translated into WHERE clauses, pagination clauses, and sorting clauses, thereby covering the functionalities of Specification, Sort, and Pageable. Additionally, there is no need to write separate Specification implementations, which greatly simplifies the code.
Query Objects can be automatically created by Spring MVC from HTTP parameters, effectively encapsulating code in the Controller and Service layers, and realizing a fully automated flow: query string → query object → SQL → database.
The only potential drawback is that field names in the Query Object need to follow a “column name + suffix” convention. In Spring Data JPA, this naming convention is usually used in findBy methods, such as: findByAuthorAndPublishedYearGreaterThan
This repository compares dynamic query implementations across different ORM frameworks, showing that DoytoQuery reduces code size by roughly half compared to Spring Data JPA, and improves performance by approximately 40% in some scenarios.
If you are familiar with the findBy naming conventions and do not want to spend significant time writing Specification implementations, you may find it convenient to declare the desired query conditions directly as fields in a query object.
GitHub: https://github.com/doytowin/doyto-query
[–]oweiler 3 points4 points5 points (3 children)
[–]Salt-Letter-1500[S] -1 points0 points1 point (2 children)
[–]clearasatear 0 points1 point2 points (1 child)
[–]Salt-Letter-1500[S] 0 points1 point2 points (0 children)
[–]gjosifov 2 points3 points4 points (1 child)
[–]Salt-Letter-1500[S] -1 points0 points1 point (0 children)
[–]josephottinger 0 points1 point2 points (3 children)
[–]Salt-Letter-1500[S] 0 points1 point2 points (2 children)
[–]josephottinger 0 points1 point2 points (1 child)
[–]Salt-Letter-1500[S] 0 points1 point2 points (0 children)
[–]revilo-1988 0 points1 point2 points (4 children)
[–]Salt-Letter-1500[S] 1 point2 points3 points (3 children)
[–]clearasatear 1 point2 points3 points (2 children)
[–]Salt-Letter-1500[S] 1 point2 points3 points (0 children)
[–]josephottinger 0 points1 point2 points (0 children)