mercredi 27 février 2019

Is it a good idea to create a CRUD Manager?

Environment: I am working with microservice architecture with java programming language. In my project, there are couple of service classes and each service class have a separate controller class above. The project also uses Spring data, so we have repository classes, too.

The job of the controller classes is just providing the rest path and calling the related service class.

Service classes do all the work with help of some manager classes for complex computations. Each service class has more than 15 methods.

Repository classes just do the db calling as a standard usage in every project.

The db has approximately 10 tables.

The problem: When I do many repository calls from a service class I need to create so many try and catch blocks to handle exceptions coming from the db. I created some private methods in the service classes to do these calls from one point to prevent creating more try and catch blocks. But I still need to copy these private methods to make the same repository call from another service class. This causes code repetition.

My solution: I think to create a CRUD Manager which handles the repository calls and exceptions coming from the db using static methods. So that I can handle the exceptions at one point and can do the same repository call without duplicating my code.

The Question: Is it a good practice to create a CRUD Manager? Is there any cons to create a CRUD Manager? Do you have other suggestions?

Aucun commentaire:

Enregistrer un commentaire