Designing complex query builders in java/jpa/hibernate
- by Ramraj Edagutti
I need to build complex sql queries programatically, based on large filter conditions.
For example, below are few sample/hypothitical filter conditions, based on which i need to fetch users
Country: india
States: Andhra Pradesh(AP), Gujarat(GUJ), karnataka(KTK)
Districts: All districts in AP except 3 district, 5 any districts from GUJ, all district from KTK except 1 district
Cities: All cities in AP, all cities except few, include only 50 specific cities from KTK
Villages: similar conditions like above with varies combinations...
Currently, we have a query builder, which is very complex in nature, and not easy to modify/re-factory for improvements. So, thinking of complete re-design of it.
Any suggesations on how to build this kind of complex query builders programmatically using some best practices/deisgn patterns?