Advertisement
ballchaichana

DocumentDAO

Oct 3rd, 2018
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.83 KB | None | 0 0
  1. package th.in.oneauthen.object.DAO;
  2.  
  3. import java.util.List;
  4.  
  5. import javax.persistence.TemporalType;
  6.  
  7. import java.util.Date;
  8.  
  9. import org.apache.log4j.Logger;
  10.  
  11. import th.athichitsakul.dao.impl.StandardDAOImpl;
  12. import th.in.oneauthen.object.DocumentDB;
  13. import th.in.oneauthen.object.UserUidDB;
  14. import th.in.oneauthen.util.SystemLogger;
  15.  
  16. public class DocumentDAO extends StandardDAOImpl<DocumentDB>{
  17.  
  18.     private Logger logger = SystemLogger.generateSystemLogger(DocumentDAO.class);
  19.    
  20.     public DocumentDAO() {
  21.         super("esigning");
  22.     }
  23.    
  24.     public List<DocumentDB> findByUserUID ( UserUidDB userUID ) {
  25.         List<DocumentDB> history = null;
  26.         try {
  27. //          UserUidDB user = new UserUidDAO().find(userUID);;
  28. //          if ( user == null ) {
  29. //              logger.error("User not found with ID "+userUID);
  30. //          } else {
  31.                 DAO.begin();
  32.                 history = (List<DocumentDB>) DAO.getEntityManager().createNamedQuery("gethistoryByOwner")
  33.                         .setParameter("creator", userUID)
  34.                         .getResultList();
  35. //          }
  36.            
  37.         } catch (Exception e) {
  38.             logger.error("Invalid user loading with ID "+userUID , e);
  39.         } finally {
  40.             DAO.close();
  41.         }
  42.         return history;
  43.     }
  44.    
  45.     public List<DocumentDB> findByDateAndYear2 (int month ,int year ,UserUidDB userUID) {
  46.         List<DocumentDB> historyTotal = null;
  47.         try {
  48.  
  49.                 DAO.begin();
  50.                 historyTotal = (List<DocumentDB>) DAO.getEntityManager().createNamedQuery("getHistoryTotalByMonthAndYear2")
  51.                         .setParameter("monthDoc", month)
  52.                         .setParameter("yearDoc", year)
  53.                         .setParameter("creator", userUID)
  54.                         .getResultList();
  55.  
  56.            
  57.         } catch (Exception e) {
  58.             logger.error("Invalid month/year loading with "+month+"/"+year , e);
  59.         } finally {
  60.             DAO.close();
  61.         }
  62.         return historyTotal;
  63.     }
  64.    
  65.     public List<DocumentDB> findCountTotalByMonth (int month ,int year ,UserUidDB userUID) {
  66.         List<DocumentDB> historyTotal = null;
  67.         try {
  68.  
  69.                 DAO.begin();
  70.                 historyTotal = (List<DocumentDB>) DAO.getEntityManager().createNamedQuery("getHistoryTotalByMonthAndYear3")
  71.                         .setParameter("monthDoc", month)
  72.                         .setParameter("yearDoc", year)
  73.                         .setParameter("creator", userUID)
  74.                         .getResultList();
  75.  
  76.            
  77.         } catch (Exception e) {
  78.             logger.error("Invalid month/year loading with "+month+"/"+year , e);
  79.         } finally {
  80.             DAO.close();
  81.         }
  82.         return historyTotal;
  83.     }
  84.    
  85.     public List<DocumentDB> findMinDate (UserUidDB userUID) {
  86.         List<DocumentDB> historyTotal = null;
  87.         try {
  88.  
  89.                 DAO.begin();
  90.                 historyTotal = (List<DocumentDB>) DAO.getEntityManager().createNamedQuery("getMinDate")
  91.                         .setParameter("creator", userUID)
  92.                         .getResultList();
  93.  
  94.            
  95.         } catch (Exception e) {
  96.             logger.error("Invalid minDate loading with  userUid" , e);
  97.         } finally {
  98.             DAO.close();
  99.         }
  100.         return historyTotal;
  101.     }
  102.    
  103.     public List<DocumentDB> findBetweenDate (Date fristDate,Date lastDate, UserUidDB userUID) {
  104.         List<DocumentDB> historyTotal = null;
  105.         try {
  106.  
  107.                 DAO.begin();
  108.                 historyTotal = (List<DocumentDB>) DAO.getEntityManager().createNamedQuery("getBetweenDate")
  109.                         .setParameter("stDate", fristDate)
  110.                         .setParameter("edDate", lastDate)
  111.                         .setParameter("creator", userUID)
  112.                         .getResultList();
  113.  
  114.            
  115.         } catch (Exception e) {
  116.             logger.error("Invalid loading with "+lastDate +"and"+fristDate , e);
  117.         } finally {
  118.             DAO.close();
  119.         }
  120.         return historyTotal;
  121.     }
  122.    
  123.     public List<DocumentDB> findInDate (Date dateFind, UserUidDB userUID) {
  124.         List<DocumentDB> historyTotal = null;
  125.         try {
  126.  
  127.                 DAO.begin();
  128.                 historyTotal = (List<DocumentDB>) DAO.getEntityManager().createNamedQuery("getInDate")
  129.                         .setParameter("dateFind", dateFind,TemporalType.DATE)
  130.                         .setParameter("creator", userUID)
  131.                         .getResultList();
  132.  
  133.            
  134.         } catch (Exception e) {
  135.             logger.error("Invalid loading with "+ dateFind +"and userID"+userUID , e);
  136.         } finally {
  137.             DAO.close();
  138.         }
  139.         return historyTotal;
  140.     }
  141. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement