Guest User

Untitled

a guest
Jan 23rd, 2018
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. /**
  2. * Extend this class if you intend on implementing EntityRepository with a JPA persistent context.
  3. *
  4. * This class requires all sub classes to have a constructor that sets an instance of JpaRepository and the entity's type.
  5. *
  6. * @param <I> The class that represents the id of the entity.
  7. * @param <E> The entity class.
  8. */
  9. public abstract class JpaEntityRepository<I,E> implements EntityRepository<I,E>{
  10. protected final JpaRepository repository;
  11. protected final Class<E> entityType;
  12.  
  13. protected JpaEntityRepository(JpaRepository repository, Class<E> entityType){
  14. this.repository = repository;
  15. this.entityType = entityType;
  16. }
  17.  
  18. @Override
  19. public boolean contains(E entity){
  20. return repository.contains(entity);
  21. }
  22.  
  23. @Override
  24. public void detach(E entity){
  25. repository.detach(entity);
  26. }
  27.  
  28. @Override
  29. public E find(I id){
  30. return repository.find(entityType, id);
  31. }
  32.  
  33. @Override
  34. public void persist(E entity){
  35. repository.persist(entity);
  36. }
  37.  
  38. @Override
  39. public void refresh(E entity){
  40. repository.refresh(entity);
  41. }
  42.  
  43. @Override
  44. public void remove(E entity){
  45. repository.remove(entity);
  46. }
  47.  
  48. @Override
  49. public E merge(E entity){
  50. return repository.merge(entity);
  51. }
  52. }
Add Comment
Please, Sign In to add comment