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 the business layer.
- ProjectBusiness: Implements the Facades defined by the client layer as remotes EJBs. It also containes the model and the DAO layer.
The business layer maps entities to DTOs so the client and view only knows about DTOs clases.
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. Changing the model is not an option.
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.
ClientQuery query = new ClientQuery();
QCar qcar = QCar.qcar;
query.and(qcar.model.eq(model)).and(qcar.horsePower.get(minumuHp));
return carService.searchCars(query);
The prototype keeps the layers separated and the dao layer can choose with query builder to use given a generic query.
My Question
This aproach makes sense? I haven't found anything on this subject so I am stating to think that maybe is an anti-pattern or some kind of bad practice. If it makes sense, is there any framework/library or pattern to look further?
I've uploaded the prototype to Github and can share the link if asked to.