コード例 #1
0
 @Override
 public int countListTrustDistrict(Boolean checkbox, String search) throws Exception {
   logger.info(
       "Execute function countListTrustDistrict with checkbox= "
           + checkbox
           + " search= "
           + search);
   session = HibernateUtil.getSessionFactory().openSession();
   int count = 0;
   try {
     String sql = "SELECT count(row_trustdistrictid) FROM TrustDistrict WHERE 1=1 ";
     if (!checkbox || checkbox == null) {
       sql += " AND ROW_ISACTIVE = true ";
     }
     if (!"".equals(search) || search == null) {
       sql += SearchLib.addSql(search, " row_name ");
     }
     Query query = session.createQuery(sql);
     count = Integer.parseInt(query.list().get(0).toString());
   } catch (HibernateException he) {
     logger.error("Error HibernateException in countListTrustDistrict", he);
     throw new Exception();
   } catch (Exception e) {
     logger.error("Error exception in countListTrustDistrict", e);
     throw new Exception();
   } finally {
     session.close();
   }
   return count;
 }
コード例 #2
0
 @Override
 public List<TrustDistrict> getListTrustDistrict(int pages, Boolean checkbox, String search)
     throws Exception {
   logger.info(
       "Execute function getListTrustDistrict with page ="
           + pages
           + " checkbox= "
           + checkbox
           + " search= "
           + search);
   session = HibernateUtil.getSessionFactory().openSession();
   try {
     String sql = "FROM TrustDistrict WHERE 1=1 ";
     if (!checkbox || checkbox == null) {
       sql += " AND ROW_ISACTIVE = true ";
     }
     if (!"".equals(search) || search == null) {
       sql += SearchLib.addSql(search, " row_name ");
     }
     Query query = session.createQuery(sql);
     query.setFirstResult((pages - 1) * UtilityFuntion.NUMBER_PAGE);
     query.setMaxResults(UtilityFuntion.NUMBER_PAGE);
     arrTrustDistrict = query.list();
   } catch (HibernateException he) {
     logger.error("Error HibernateException in getListTrustDistrict" + he);
     throw new Exception();
   } catch (Exception e) {
     logger.error("Error Exception in getListTrustDistrict" + e);
     throw new Exception();
   } finally {
     session.close();
   }
   return arrTrustDistrict;
 }
コード例 #3
0
 @Override
 public boolean updateTrustDistrict(TrustDistrict district, int id) throws Exception {
   logger.info("Execute function getTrustDistrictById with district= " + district + " id=" + id);
   session = HibernateUtil.getSessionFactory().openSession();
   try {
     transaction = session.beginTransaction();
     trustDistrict = (TrustDistrict) session.get(TrustDistrict.class, id);
     trustDistrict.setName(district.getName());
     trustDistrict.setDescription(district.getDescription());
     trustDistrict.setTrustRegion(district.getTrustRegion());
     trustDistrict.setActive(district.isActive());
     session.update(trustDistrict);
     transaction.commit();
   } catch (HibernateException he) {
     logger.error("Error HibernateException in updateTrustDistrict " + he);
     throw new Exception();
   } catch (Exception e) {
     logger.error("Error Exception in updateTrustDistrict" + e);
     throw new Exception();
   } finally {
     if (session != null) {
       session.close();
     }
   }
   return true;
 }
コード例 #4
0
 @Override
 public TrustDistrict getTrustDistrictById(int id) throws Exception {
   logger.info("Execute function getTrustDistrictById with id=" + id);
   session = HibernateUtil.getSessionFactory().openSession();
   try {
     trustDistrict = (TrustDistrict) session.get(TrustDistrict.class, id);
   } catch (HibernateException he) {
     logger.error("Error HibernateException in getTrustDistrictById " + he);
     throw new Exception();
   } catch (Exception e) {
     logger.error("Error Exception in getTrustDistrictById" + e);
     throw new Exception();
   } finally {
     session.close();
   }
   return trustDistrict;
 }
コード例 #5
0
 @Override
 public List<TrustDistrict> listTrustDistrict() throws Exception {
   logger.info("Execute function listTrustDistrict");
   session = HibernateUtil.getSessionFactory().openSession();
   try {
     String sql = "FROM TrustDistrict";
     Query query = session.createQuery(sql);
     arrTrustDistrict = query.list();
   } catch (HibernateException he) {
     logger.error("Error HibernateException in listTrustDistrict" + he);
     throw new Exception();
   } catch (Exception e) {
     logger.error("Error in listTrustDistrict" + e);
     throw new Exception();
   } finally {
     session.close();
   }
   return arrTrustDistrict;
 }
コード例 #6
0
 @Override
 public boolean insertTrustDistrict(TrustDistrict district) throws Exception {
   logger.info("Execute function insertTrustDistrict with name=" + district.getName());
   session = HibernateUtil.getSessionFactory().openSession();
   try {
     transaction = session.beginTransaction();
     session.save(district);
     transaction.commit();
   } catch (HibernateException he) {
     logger.error("Error HibernateException in insertTrustDistrict " + he);
     throw new Exception();
   } catch (Exception he) {
     logger.error("Error Exception in insertTrustDistrict" + he);
     throw new Exception();
   } finally {
     if (session != null) {
       session.close();
     }
   }
   return true;
 }