Advertisement
kieni17

Untitled

Apr 14th, 2020
432
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.83 KB | None | 0 0
  1. /**
  2.  *
  3.  * @param <IMPL_TYPE> implention of the Model
  4.  * @param <INT_TYPE>  interface of the Model
  5.  */
  6. public class GenericDAOI<IMPL_TYPE extends INT_TYPE , INT_TYPE> implements GenericDAO<INT_TYPE> {
  7.  
  8.     private EntityManager em;
  9.     private Class<INT_TYPE> interfaceType;
  10.     private Class<IMPL_TYPE> implType;
  11.  
  12.     public GenericDAOI(EntityManager em, Class<IMPL_TYPE> tType, Class<INT_TYPE> sType) {
  13.         this.em = em;
  14.         this.implType = tType;
  15.         this.interfaceType = sType;
  16.     }
  17.  
  18.     @Override
  19.     public INT_TYPE findById(Long id) {
  20.         INT_TYPE elem = em.find(implType, id);
  21.         return elem;
  22.     }
  23.  
  24.     @Override
  25.     public List<INT_TYPE> findAll() {
  26.         String sqlQueryAll = "FROM " + implType.getName();
  27.         return em.createQuery(sqlQueryAll, interfaceType).getResultList();
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement