Advertisement
ballchaichana

logDAO

Oct 18th, 2018
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.73 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.LogReportDB;
  13. import th.in.oneauthen.object.UserUidDB;
  14. import th.in.oneauthen.util.SystemLogger;
  15.  
  16. public class LogReportDAO extends StandardDAOImpl<LogReportDB>{
  17.  
  18.     private Logger logger = SystemLogger.generateSystemLogger(LogReportDAO.class);
  19.    
  20.     public LogReportDAO() {
  21.         super("esigning");
  22.     }
  23.    
  24.     public List<LogReportDB> findByUserUIDLog ( UserUidDB userUID ) {
  25.         List<LogReportDB> history = null;
  26.         try {
  27.  
  28.                 DAO.begin();
  29.                 history = (List<LogReportDB>) DAO.getEntityManager().createNamedQuery("queryByUserId")
  30.                         .setParameter("creator", userUID)
  31.                         .setMaxResults(75)
  32.                         .getResultList();
  33.            
  34.         } catch (Exception e) {
  35.             logger.error("Invalid user loading with ID "+userUID , e);
  36.         } finally {
  37.             DAO.close();
  38.         }
  39.         return history;
  40.     }
  41.    
  42.     public List<LogReportDB> findByDateAndYear2Log (int month ,int year ,UserUidDB userUID) {
  43.         List<LogReportDB> historyTotal = null;
  44.         try {
  45.  
  46.                 DAO.begin();
  47.                 historyTotal = (List<LogReportDB>) DAO.getEntityManager().createNamedQuery("queryByMonthAndYear")
  48.                         .setParameter("monthDoc", month)
  49.                         .setParameter("yearDoc", year)
  50.                         .setParameter("creator", userUID)
  51.                         .getResultList();
  52.  
  53.            
  54.         } catch (Exception e) {
  55.             logger.error("Invalid month/year loading with "+month+"/"+year , e);
  56.         } finally {
  57.             DAO.close();
  58.         }
  59.         return historyTotal;
  60.     }
  61.    
  62.     public List<LogReportDB> findCountTotalByMonthLog (int month ,int year ,UserUidDB userUID) {
  63.         List<LogReportDB> historyTotal = null;
  64.         try {
  65.  
  66.                 DAO.begin();
  67.                 historyTotal = (List<LogReportDB>) DAO.getEntityManager().createNamedQuery("queryByMonthAndYearTotal")
  68.                         .setParameter("monthDoc", month)
  69.                         .setParameter("yearDoc", year)
  70.                         .setParameter("creator", userUID)
  71.                         .getResultList();
  72.  
  73.            
  74.         } catch (Exception e) {
  75.             logger.error("Invalid month/year loading with "+month+"/"+year , e);
  76.         } finally {
  77.             DAO.close();
  78.         }
  79.         return historyTotal;
  80.     }
  81.    
  82.     public List<LogReportDB> findMinDateLog (UserUidDB userUID) {
  83.         List<LogReportDB> historyTotal = null;
  84.         try {
  85.  
  86.                 DAO.begin();
  87.                 historyTotal = (List<LogReportDB>) DAO.getEntityManager().createNamedQuery("queryMinDate")
  88.                         .setParameter("creator", userUID)
  89.                         .getResultList();
  90.  
  91.            
  92.         } catch (Exception e) {
  93.             logger.error("Invalid minDate loading with  userUid" , e);
  94.         } finally {
  95.             DAO.close();
  96.         }
  97.         return historyTotal;
  98.     }
  99.    
  100.     public List<LogReportDB> findBetweenDateLog (Date fristDate,Date lastDate, UserUidDB userUID) {
  101.         List<LogReportDB> historyTotal = null;
  102.         try {
  103.  
  104.                 DAO.begin();
  105.                 historyTotal = (List<LogReportDB>) DAO.getEntityManager().createNamedQuery("queryBetweenDate")
  106.                         .setParameter("stDate", fristDate)
  107.                         .setParameter("edDate", lastDate)
  108.                         .setParameter("creator", userUID)
  109.                         .getResultList();
  110.  
  111.            
  112.         } catch (Exception e) {
  113.             logger.error("Invalid loading with "+lastDate +"and"+fristDate , e);
  114.         } finally {
  115.             DAO.close();
  116.         }
  117.         return historyTotal;
  118.     }
  119.    
  120.     public List<LogReportDB> findInDateLog (Date dateFind, UserUidDB userUID) {
  121.         List<LogReportDB> historyTotal = null;
  122.         try {
  123.  
  124.                 DAO.begin();
  125.                 historyTotal = (List<LogReportDB>) DAO.getEntityManager().createNamedQuery("queryInDate")
  126.                         .setParameter("dateFind", dateFind,TemporalType.DATE)
  127.                         .setParameter("creator", userUID)
  128.                         .getResultList();
  129.  
  130.            
  131.         } catch (Exception e) {
  132.             logger.error("Invalid loading with "+ dateFind +"and userID"+userUID , e);
  133.         } finally {
  134.             DAO.close();
  135.         }
  136.         return historyTotal;
  137.     }
  138. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement