mardi 18 août 2020

Implement strategy pattern service layer using spring data JPA

We have a following db structure for a lot of modules in db.

db table A is the main table and there are multiple extensions of this table (B, C, D etc) with no primary key of their own but refer primary key of A. We have used JPA @Inheritence joined table approach to manage these. So a parent entity for A and child entities extending A.

We also created multiple jpa repositories for all implementing entities.

When user sends a request, based on certain fields in the request, we have to identify the correct implementation and do CRUD operations on that particular repo.

In order to make it generic and dynamic I created a strategy factory that accepts user input identifies the correct implementation and returns the specific strategy wrapping the specific repo.

The problem is that I have to do this on every call to service class method to identify the correct strategy. I feel there are flaws in this design. Can you suggest a better design ?

Aucun commentaire:

Enregistrer un commentaire