lundi 6 avril 2015

Implementing CrudRepository in Spring. What's the best design I should follow?

I have the User Repository extend from the CrudRepository as below



public interface UserRepository extends CrudRepository<User, Long>, DatatablesCriteriasRepository<User>


DatatablesCriteriasRepository has a function which need to be implmented separately for different repositories.


So I created the repository implementation class like this. In the impl package.



public class UserRepositoryImpl implements DatatablesCriteriasRepository<User>


Please note this is to implement the functions in DatatablesCriteriasRepository only. I dont want to override the default functionalities presented in CrudRepository by the framework.


But If I do something like this, it will suit more in the code design, as UserRepositoryImpl actually implements UserRepository as the name suggests.



public class UserRepositoryImpl implements UserRepository


But again this will force me to extend all the functions in the UserRepository interface. How can I solve this issue by the way in a good code design?


Aucun commentaire:

Enregistrer un commentaire