• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Dynamic queries to entities from the view layer

 
Guillermo Gefaell
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

In my current job they are defining a new corporate architecture for java development. It is something like this:

-ProjectView: JSF view layer. Uses delegates on the ProjectClient layer.
-ProjectClient: Defines Delegates and Facades. It does de lookup for the EJBs of the business layer.
-ProjectBusiness: Implements the Facades defined by the client layer as remotes EJBs. It also containes the model and the DAO layer.

One of the main problems of this architecture is that you have to write a lot of code in different layers just to get some query done.

My concern
Let's say we have an entity Car with attributes horsePower, numberOfDoors, engineType and releaseDate. Now, we need in the view to search the cars with 3 doors and more than 120hp. With the initial vision of the architecture I should write the functions needed in all layers that take this to arguments.

But if I need with 3 doors and more than 120hp or diesel engine? The answer was: build another function. Thats one in the delegate, on the facade interface, the facade impl and in the dao.

But our entities don't have 4 fields. More like 30. IMHO is going to be chaos and people dying when we start writing full apps, with hundreds of functions all over the place.

My solution
I've created a prototype inspired in queryDsl to create dynamic queries from the view that follows the layer pattern so you could write something like this in a manager bean from JSF. Just one class needs to be created in the ProjectClient layer.





The prototype generates a JPA query with parameters at the end but, this could be easeily adapted as only the DAO knows what query builder is using.

It has been a nice exercise of abstraction but, Is there any existing framework or library that allows to do this? Any pattern to look for? Have you faced similar problem on your jobs.

I can upload full code with GNU licesing if someone is interested.
 
Guillermo Gefaell
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have uploaded full code and a little, non-working, example to get the idea behind this.
https://github.com/konum/Vidyq
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic