List of usage examples for org.hibernate Session clear
void clear();
From source file:com.orig.gls.group.dao.Group.java
public static void verifyGroup(int groupId) { Session session = HibernateUtil.getSessionFactory().openSession(); Transaction tx = null;/*from ww w. j a va 2 s . c o m*/ try { tx = session.beginTransaction(); Criteria cr = session.createCriteria(GroupsTableMod.class); cr.add(Restrictions.eq("groupId", groupId)); int count = 0; ScrollableResults items = cr.scroll(); while (items.next()) { GroupsTableMod group = (GroupsTableMod) items.get(0); session.delete(group); if (++count % 100 == 0) { session.flush(); session.clear(); } } tx.commit(); } catch (Exception asd) { log.debug(asd.getMessage()); if (tx != null) { tx.rollback(); } } finally { session.close(); } }
From source file:com.orig.gls.subgroup.dao.SubGroup.java
public static void verifySubGroup(int groupId) { Session session = HibernateUtil.getSessionFactory().openSession(); Transaction tx = null;//from www . j a v a 2s.c o m try { tx = session.beginTransaction(); Criteria cr = session.createCriteria(SubGrpTableMod.class); cr.add(Restrictions.eq("subGroupId", groupId)); int count = 0; ScrollableResults items = cr.scroll(); while (items.next()) { SubGrpTableMod group = (SubGrpTableMod) items.get(0); session.delete(group); if (++count % 100 == 0) { session.flush(); session.clear(); } } tx.commit(); } catch (Exception asd) { log.debug(asd.getMessage()); if (tx != null) { tx.rollback(); } } finally { session.close(); } }
From source file:com.project.framework.dao.GenericDao.java
License:Apache License
/** * ?//from w w w.ja v a 2s . c o m * * @param entitys ?? * @param flushSize ORM????? */ public void save(final List<T> entitys, int flushSize) { Assert.notNull(entitys, "entitys Can not NULL"); Assert.notEmpty(entitys, "entitys Can not EMPTY"); Session session = getSession(); int count = 1; for (T entity : entitys) { session.saveOrUpdate(entity); if (count++ % flushSize == 0) { session.flush(); session.clear(); } } logger.debug("batch save {}, number of rows affected: {}", entityClass.getSimpleName(), count - 1); }
From source file:com.project.framework.dao.GenericDao.java
License:Apache License
/** * ?/*from w w w . ja v a 2 s.c o m*/ * * @param entitys * @param flushSize ORM????? */ public void delete(final List<T> entitys, int flushSize) { Assert.notNull(entitys, "entity Can not NULL"); Assert.notEmpty(entitys, "entitys Can not EMPTY"); Session session = getSession(); int count = 1; for (T entity : entitys) { session.delete(entity); if (count++ % flushSize == 0) { session.flush(); session.clear(); } } logger.debug("batch delete {}, number of rows affected: {}", entityClass.getSimpleName(), count - 1); }
From source file:com.quix.aia.cn.imo.mapper.AddressBookMaintenance.java
License:Open Source License
/** * <p>/*from ww w . j ava 2 s .co m*/ * This method performs insert or update of AddressBook from List of * AddressBook called from rest. When addressCode is 0, it performs insert * otherwise performs update. * </p> * * @param List * <AddressBook/> List of Class Object * @return List<AddressBook/> List of Class Object * */ public String insertOrUpdateRestBatch(List<AddressBook> addressBookList) { Session session = null; Transaction tx = null; int key = 0; String returnJsonString = ""; String deleteString = ""; CandidateEducationMaintenance candidateEducationMaintenance = new CandidateEducationMaintenance(); CandidateESignatureMaintenance candidateESignatureMaintenance = new CandidateESignatureMaintenance(); CandidateFamilyInfoMaintenance candidateFamilyInfoMaintenance = new CandidateFamilyInfoMaintenance(); CandidateGroupMaintenance candidateGroupMaintenance = new CandidateGroupMaintenance(); CandidateProfessionalCertificationMaintenance candidateProfessionalCertificationMaintenance = new CandidateProfessionalCertificationMaintenance(); CandidateWorkExperienceMaintenance candidateWorkExperienceMaintenance = new CandidateWorkExperienceMaintenance(); CandidateNoteMaintenance candidateNoteMaintenance = new CandidateNoteMaintenance(); try { session = HibernateFactory.openSession(); int count = 0; boolean flag = true; for (AddressBook addressBook : addressBookList) { deleteString = ""; tx = session.beginTransaction(); key = (int) addressBook.getAddressCode(); if (0 == key) { addressBook.setAddressCode(null); } if (addressBook.getDeleteStatus()) { addressBook = getAddressBook(addressBook); addressBook.setDeleteStatus(true); deleteString = ",\"deleteStatus\":" + addressBook.getDeleteStatus(); } session.saveOrUpdate(addressBook); tx.commit(); if ("".equals(deleteString)) { candidateEducationMaintenance.saveOrUpdate(addressBook); candidateESignatureMaintenance.saveOrUpdate(addressBook); candidateFamilyInfoMaintenance.saveOrUpdate(addressBook); candidateGroupMaintenance.saveOrUpdate(addressBook); candidateProfessionalCertificationMaintenance.saveOrUpdate(addressBook); candidateWorkExperienceMaintenance.saveOrUpdate(addressBook); candidateNoteMaintenance.saveOrUpdate(addressBook); } if (flag) { flag = false; } else { returnJsonString += ","; } returnJsonString += "{\"iosAddressCode\":\"" + addressBook.getIosAddressCode() + "\",\"addressCode\":" + addressBook.getAddressCode() + deleteString + "}"; if (++count % 10 == 0) { session.flush(); session.clear(); } } } catch (Exception ex) { log.log(Level.SEVERE, ex.getMessage()); ex.printStackTrace(); } finally { try { HibernateFactory.close(session); } catch (Exception e) { log.log(Level.SEVERE, e.getMessage()); e.printStackTrace(); } tx = null; session = null; candidateEducationMaintenance = null; candidateESignatureMaintenance = null; candidateFamilyInfoMaintenance = null; candidateGroupMaintenance = null; candidateProfessionalCertificationMaintenance = null; candidateWorkExperienceMaintenance = null; candidateNoteMaintenance = null; } return returnJsonString; }
From source file:com.quix.aia.cn.imo.utilities.ImoUtilityData.java
License:Open Source License
public void getRefresh() { log.log(Level.INFO, "ImoUtilityDate --> getRefresh"); Session session = null; Transaction tx;/*from w w w.j ava 2 s .co m*/ List<Holiday> listHoliday = null; List<E_Greeting> listEGreeting = null; List<Interview> listInterview = null; List<Presenter> listPresenter = null; List<Announcement> listAnnouncement = null; List<Event> listEvent = null; List<Bu> listbu = null; List<District> listdist = null; List<Branch> listbranch = null; List<City> listcity = null; List<Ssc> listSsc = null; List<Office> listOffice = null; ArrayList al = new ArrayList(); try { Query query = null; session = HibernateFactory.openSession(); Date sdate = new Date(); log.log(Level.INFO, "Start Time " + sdate.getTime()); listbu = session.createQuery("FROM Bu where status = 1").setCacheable(true).list(); listdist = session.createQuery("FROM District where status = 1").setCacheable(true).list(); listbranch = session.createQuery("FROM Branch where status = 1").setCacheable(true).list(); listcity = session.createQuery("FROM City where status = 1").setCacheable(true).list(); listSsc = session.createQuery("FROM Ssc where status = 1").setCacheable(true).list(); listOffice = session.createQuery("FROM Office where status = 1").setCacheable(true).list(); listbu = session.createQuery("FROM Bu where status = 1 order by buName").setCacheable(true).list(); listdist = session.createQuery("FROM District where status = 1 order by districtName") .setCacheable(true).list(); listbranch = session.createQuery("FROM Branch where status = 1 order by branchName").setCacheable(true) .list(); listcity = session.createQuery("FROM City where status = 1 order by cityName").setCacheable(true) .list(); listSsc = session.createQuery("FROM Ssc where status = 1 order by sscName").setCacheable(true).list(); listOffice = session.createQuery("FROM Office where status = 1 order by sscName").setCacheable(true) .list(); for (int i = 0; i < listbu.size(); i++) { Bu bu = listbu.get(i); // query= session.createQuery("FROM Holiday where status = 1 and buCode=:bucode and district=0 "); // query.setParameter("bucode", bu.getBuCode()); // listHoliday=query.setCacheable(true).list(); query = session.createQuery("FROM Interview where status = 1 and buCode=:bucode and district=0 "); query.setParameter("bucode", bu.getBuCode()); listInterview = query.setCacheable(true).list(); // listHoliday = session.createQuery("FROM Holiday where status = 1 and buCode="+ bu.getBuCode()+" and district=0 ").setFirstResult(0).setCacheable(true).list(); // al.add(listHoliday); listInterview = session .createQuery( "FROM Interview where status = 1 and buCode=" + bu.getBuCode() + " and district=0 ") .setFirstResult(0).setCacheable(true).list(); listPresenter = session .createQuery( "FROM Presenter where status = 1 and buCode=" + bu.getBuCode() + " and district=0 ") .setFirstResult(0).setCacheable(true).list(); listAnnouncement = session.createQuery( "FROM Announcement where status = 1 and buCode=" + bu.getBuCode() + " and district=0 ") .setFirstResult(0).setCacheable(true).list(); listEvent = session .createQuery( "FROM Event where status = 1 and buCode=" + bu.getBuCode() + " and district=0 ") .setFirstResult(0).setCacheable(true).list(); query = session.createQuery("FROM Presenter where status = 1 and buCode=:bucode and district=0 "); query.setParameter("bucode", bu.getBuCode()); listPresenter = query.setCacheable(true).list(); query = session .createQuery("FROM Announcement where status = 1 and buCode=:bucode and district=0 "); query.setParameter("bucode", bu.getBuCode()); listAnnouncement = query.setCacheable(true).list(); query = session.createQuery("FROM Event where status = 1 and buCode=:bucode and district=0 "); query.setParameter("bucode", bu.getBuCode()); listEvent = query.setCacheable(true).list(); query = session.createQuery("FROM Bu where status = 1 and buCode=:bucode "); query.setParameter("bucode", bu.getBuCode()); ArrayList<Bu> bulist = (ArrayList<Bu>) query.setCacheable(true).list(); for (int j = 0; j < listdist.size(); j++) { District dist = listdist.get(j); // query= session.createQuery("FROM Holiday where status = 1 and district=:distcode and branchCode=0 "); // query.setParameter("distcode", dist.getDistrictCode()); // listHoliday=query.setCacheable(true).list(); query = session.createQuery( "FROM Interview where status = 1 and district=:distcode and branchCode=0 "); query.setParameter("distcode", dist.getDistrictCode()); listInterview = query.setCacheable(true).list(); query = session.createQuery( "FROM Presenter where status = 1 and district=:distcode and branchCode=0 "); query.setParameter("distcode", dist.getDistrictCode()); listPresenter = query.setCacheable(true).list(); query = session.createQuery( "FROM Announcement where status = 1 and district=:distcode and branchCode=0 "); query.setParameter("distcode", dist.getDistrictCode()); listAnnouncement = query.setCacheable(true).list(); query = session .createQuery("FROM Event where status = 1 and district=:distcode and branchCode=0 "); query.setParameter("distcode", dist.getDistrictCode()); listEvent = query.setCacheable(true).list(); query = session.createQuery("FROM District where status = 1 and districtCode=:distcode "); query.setParameter("distcode", dist.getDistrictCode()); ArrayList<District> distlist = (ArrayList<District>) query.setCacheable(true).list(); for (int a = 0; a < listbranch.size(); a++) { Branch branch = listbranch.get(a); // query= session.createQuery("FROM Holiday where status = 1 and branchCode=:branch and cityCode=0 "); // query.setParameter("branch", branch.getBranchCode()); // listHoliday=query.setCacheable(true).list(); query = session.createQuery( "FROM Interview where status = 1 and branchCode=:branch and cityCode=0 "); query.setParameter("branch", branch.getBranchCode()); listInterview = query.setCacheable(true).list(); query = session.createQuery( "FROM Presenter where status = 1 and branchCode=:branch and cityCode=0 "); query.setParameter("branch", branch.getBranchCode()); listPresenter = query.setCacheable(true).list(); query = session.createQuery( "FROM Announcement where status = 1 and branchCode=:branch and cityCode=0 "); query.setParameter("branch", branch.getBranchCode()); listAnnouncement = query.setCacheable(true).list(); query = session .createQuery("FROM Event where status = 1 and branchCode=:branch and cityCode=0 "); query.setParameter("branch", branch.getBranchCode()); listEvent = query.setCacheable(true).list(); query = session.createQuery("FROM Branch where status = 1 and branchCode=:branch "); query.setParameter("branch", branch.getBranchCode()); for (int k = 0; k < listcity.size(); k++) { City city = listcity.get(k); // query= session.createQuery("FROM Holiday where status = 1 and cityCode=:citycode and sscCode=0 "); // query.setParameter("citycode", city.getCityCode()); // listHoliday=query.setCacheable(true).list(); query = session.createQuery( "FROM Interview where status = 1 and cityCode=:citycode and sscCode=0 "); query.setParameter("citycode", city.getCityCode()); listInterview = query.setCacheable(true).list(); query = session.createQuery( "FROM Presenter where status = 1 and cityCode=:citycode and sscCode=0 "); query.setParameter("citycode", city.getCityCode()); listPresenter = query.setCacheable(true).list(); query = session.createQuery( "FROM Announcement where status = 1 and cityCode=:citycode and sscCode=0 "); query.setParameter("citycode", city.getCityCode()); listAnnouncement = query.setCacheable(true).list(); query = session.createQuery( "FROM Event where status = 1 and cityCode=:citycode and sscCode=0 "); query.setParameter("citycode", city.getCityCode()); listEvent = query.setCacheable(true).list(); query = session.createQuery("FROM City where status = 1 and cityCode=:citycode "); query.setParameter("citycode", city.getCityCode()); ArrayList<City> citylist = (ArrayList<City>) query.setCacheable(true).list(); for (int l = 0; l < listSsc.size(); l++) { Ssc ssc = listSsc.get(l); // query= session.createQuery("FROM Holiday where status = 1 and sscCode=:ssccode "); // query.setParameter("ssccode", ssc.getSscCode()); // listHoliday=query.setCacheable(true).list(); // query = session .createQuery("FROM Interview where status = 1 and sscCode=:ssccode "); query.setParameter("ssccode", ssc.getSscCode()); listInterview = query.setCacheable(true).list(); query = session .createQuery("FROM Presenter where status = 1 and sscCode=:ssccode "); query.setParameter("ssccode", ssc.getSscCode()); listPresenter = query.setCacheable(true).list(); query = session .createQuery("FROM Announcement where status = 1 and sscCode=:ssccode "); query.setParameter("ssccode", ssc.getSscCode()); listAnnouncement = query.setCacheable(true).list(); query = session.createQuery("FROM Event where status = 1 and sscCode=:ssccode "); query.setParameter("ssccode", ssc.getSscCode()); listEvent = query.setCacheable(true).list(); query = session.createQuery("FROM Ssc where status = 1 and sscCode=:ssccode"); query.setParameter("ssccode", ssc.getSscCode()); ArrayList<Ssc> ssclist = (ArrayList<Ssc>) query.setCacheable(true).list(); for (int m = 0; m < listOffice.size(); m++) { Office office = listOffice.get(m); // query= session.createQuery("FROM Holiday where status = 1 and officeCode=:code "); // query.setParameter("ssccode", ssc.getSscCode()); // listHoliday=query.setCacheable(true).list(); query = session.createQuery( "FROM Interview where status = 1 and officeCode=:code "); query.setParameter("code", office.getOfficeCode()); listInterview = query.setCacheable(true).list(); query = session .createQuery("FROM Presenter where status = 1 and officeCode=:code "); query.setParameter("code", office.getOfficeCode()); listPresenter = query.setCacheable(true).list(); query = session.createQuery( "FROM Announcement where status = 1 and officeCode=:code "); query.setParameter("code", office.getOfficeCode()); listAnnouncement = query.setCacheable(true).list(); query = session .createQuery("FROM Event where status = 1 and officeCode=:code "); query.setParameter("code", office.getOfficeCode()); listEvent = query.setCacheable(true).list(); query = session .createQuery("FROM Office where status = 1 and officeCode=:code"); query.setParameter("code", office.getOfficeCode()); ArrayList<Office> officelist = (ArrayList<Office>) query.setCacheable(true) .list(); } // close Office for loop } // close ssc for loop } //close city for loop } // branch for loop } //close district for loop } //close bu for loop listEGreeting = session.createQuery("FROM E_Greeting where status = 1").setCacheable(true).list(); Date edate = new Date(); log.log(Level.INFO, "Total Time " + (edate.getTime() - sdate.getTime())); session.flush(); session.clear(); session.close(); } catch (Exception e) { log.log(Level.INFO, "ImoUtilityDate --> getRefresh --> Exception " + e); e.printStackTrace(); LogsMaintenance logsMain = new LogsMaintenance(); StringWriter errors = new StringWriter(); e.printStackTrace(new PrintWriter(errors)); logsMain.insertLogs("IMOUtilityData", Level.SEVERE + "", errors.toString()); } finally { try { HibernateFactory.close(session); } catch (Exception e) { e.printStackTrace(); } } }
From source file:com.quix.aia.cn.imo.utilities.ImoUtilityData.java
License:Open Source License
public void getEGreetingCache() { log.log(Level.INFO, "ImoUtilityDate --> getEGreetingCache"); Session session = null; Transaction tx;/*from w w w. j av a 2 s. c o m*/ List<E_Greeting> listEGreeting = null; try { Query query = null; session = HibernateFactory.openSession(); Date sdate = new Date(); log.log(Level.INFO, "Start Time " + sdate.getTime()); listEGreeting = session.createQuery("FROM E_Greeting where status = 1").setCacheable(true).list(); Date edate = new Date(); log.log(Level.INFO, "Total Time " + (edate.getTime() - sdate.getTime())); session.flush(); session.clear(); session.close(); } catch (Exception e) { log.log(Level.INFO, "ImoUtilityDate --> getEGreetingCache --> Exception " + e); e.printStackTrace(); LogsMaintenance logsMain = new LogsMaintenance(); StringWriter errors = new StringWriter(); e.printStackTrace(new PrintWriter(errors)); logsMain.insertLogs("IMOUtilityData", Level.SEVERE + "", errors.toString()); } finally { try { HibernateFactory.close(session); } catch (Exception e) { e.printStackTrace(); } } }
From source file:com.quix.aia.cn.imo.utilities.ImoUtilityData.java
License:Open Source License
public void getEventCache() { log.log(Level.INFO, "ImoUtilityDate --> getEventCache"); Session session = null; Transaction tx;//from w ww . j ava 2 s . c om List<Event> listEvent = null; List<Bu> listbu = null; List<District> listdist = null; List<Branch> listbranch = null; List<City> listcity = null; List<Ssc> listSsc = null; ArrayList al = new ArrayList(); try { Query query = null; session = HibernateFactory.openSession(); Date sdate = new Date(); log.log(Level.INFO, "Start Time " + sdate.getTime()); listbu = session.createQuery("FROM Bu where status = 1").setCacheable(true).list(); listdist = session.createQuery("FROM District where status = 1").setCacheable(true).list(); listbranch = session.createQuery("FROM Branch where status = 1").setCacheable(true).list(); listcity = session.createQuery("FROM City ").setCacheable(true).list(); listSsc = session.createQuery("FROM Ssc ").setCacheable(true).list(); listbu = session.createQuery("FROM Bu where status = 1 order by buName").setCacheable(true).list(); listdist = session.createQuery("FROM District where status = 1 order by districtName") .setCacheable(true).list(); listbranch = session.createQuery("FROM Branch where status = 1 order by branchName").setCacheable(true) .list(); listcity = session.createQuery("FROM City order by cityName").setCacheable(true).list(); listSsc = session.createQuery("FROM Ssc order by sscName").setCacheable(true).list(); for (int i = 0; i < listbu.size(); i++) { Bu bu = listbu.get(i); query = session.createQuery("FROM Event where status = 1 and buCode=:bucode and district=0 "); query.setParameter("bucode", bu.getBuCode()); listEvent = query.setCacheable(true).list(); query = session.createQuery("FROM Bu where status = 1 and buCode=:bucode "); query.setParameter("bucode", bu.getBuCode()); ArrayList<Bu> bulist = (ArrayList<Bu>) query.setCacheable(true).list(); for (int j = 0; j < listdist.size(); j++) { District dist = listdist.get(j); query = session .createQuery("FROM Event where status = 1 and district=:distcode and branchCode=0 "); query.setParameter("distcode", dist.getDistrictCode()); listEvent = query.setCacheable(true).list(); query = session.createQuery("FROM District where status = 1 and districtCode=:distcode "); query.setParameter("distcode", dist.getDistrictCode()); ArrayList<District> distlist = (ArrayList<District>) query.setCacheable(true).list(); for (int a = 0; a < listbranch.size(); a++) { Branch branch = listbranch.get(a); query = session.createQuery( "FROM Event where status = 1 and branchCode=:branch and cityCode=:code "); query.setParameter("branch", branch.getBranchCode()); query.setParameter("code", "0"); listEvent = query.setCacheable(true).list(); query = session.createQuery("FROM Branch where status = 1 and branchCode=:branch "); query.setParameter("branch", branch.getBranchCode()); ArrayList<Branch> branchlist = (ArrayList<Branch>) query.setCacheable(true).list(); for (int k = 0; k < listcity.size(); k++) { City city = listcity.get(k); query = session.createQuery( "FROM Event where status = 1 and cityCode=:citycode and sscCode=:code "); query.setParameter("citycode", city.getCityName()); query.setParameter("code", "0"); listEvent = query.setCacheable(true).list(); query = session.createQuery("FROM City where cityName=:citycode "); query.setParameter("citycode", city.getCityName()); ArrayList<City> citylist = (ArrayList<City>) query.setCacheable(true).list(); for (int l = 0; l < listSsc.size(); l++) { Ssc ssc = listSsc.get(l); query = session.createQuery("FROM Event where status = 1 and sscName=:ssccode "); query.setParameter("ssccode", ssc.getSscName()); listEvent = query.setCacheable(true).list(); query = session.createQuery("FROM Ssc where sscName=:ssccode"); query.setParameter("ssccode", ssc.getSscName()); ArrayList<Ssc> ssclist = (ArrayList<Ssc>) query.setCacheable(true).list(); } // close ssc for loop } //close city for loop } // branch for loop } //close district for loop } //close bu for loop //listEGreeting = session.createQuery("FROM E_Greeting where status = 1").setCacheable(true).list(); Date edate = new Date(); log.log(Level.INFO, "Total Time " + (edate.getTime() - sdate.getTime())); session.flush(); session.clear(); session.close(); } catch (Exception e) { log.log(Level.INFO, "ImoUtilityDate --> getEventCache --> Exception " + e); e.printStackTrace(); LogsMaintenance logsMain = new LogsMaintenance(); StringWriter errors = new StringWriter(); e.printStackTrace(new PrintWriter(errors)); logsMain.insertLogs("IMOUtilityData", Level.SEVERE + "", errors.toString()); } finally { try { HibernateFactory.close(session); } catch (Exception e) { e.printStackTrace(); } } }
From source file:com.quix.aia.cn.imo.utilities.ImoUtilityData.java
License:Open Source License
public void getAnnouncementCache() { log.log(Level.INFO, "ImoUtilityDate --> getAnnouncementCache"); Session session = null; Transaction tx;//from w ww . j a va 2s . c o m List<Announcement> listAnnouncement = null; List<Bu> listbu = null; List<District> listdist = null; List<Branch> listbranch = null; List<City> listcity = null; List<Ssc> listSsc = null; List<Office> listOffice = null; ArrayList al = new ArrayList(); try { Query query = null; session = HibernateFactory.openSession(); Date sdate = new Date(); log.log(Level.INFO, "Start Time " + sdate.getTime()); listbu = session.createQuery("FROM Bu where status = 1").setCacheable(true).list(); listdist = session.createQuery("FROM District where status = 1").setCacheable(true).list(); listbranch = session.createQuery("FROM Branch where status = 1").setCacheable(true).list(); listcity = session.createQuery("FROM City ").setCacheable(true).list(); listSsc = session.createQuery("FROM Ssc").setCacheable(true).list(); listOffice = session.createQuery("FROM Office ").setCacheable(true).list(); listOffice = session.createQuery("FROM Office order by sscName").setCacheable(true).list(); listbu = session.createQuery("FROM Bu where status = 1 order by buName").setCacheable(true).list(); listdist = session.createQuery("FROM District where status = 1 order by districtName") .setCacheable(true).list(); listbranch = session.createQuery("FROM Branch where status = 1 order by branchName").setCacheable(true) .list(); listcity = session.createQuery("FROM City order by cityName").setCacheable(true).list(); listSsc = session.createQuery("FROM Ssc order by sscName").setCacheable(true).list(); for (int i = 0; i < listbu.size(); i++) { Bu bu = listbu.get(i); query = session .createQuery("FROM Announcement where status = 1 and buCode=:bucode and district=0 "); query.setParameter("bucode", bu.getBuCode()); listAnnouncement = query.setCacheable(true).list(); query = session.createQuery("FROM Bu where status = 1 and buCode=:bucode "); query.setParameter("bucode", bu.getBuCode()); ArrayList<Bu> bulist = (ArrayList<Bu>) query.setCacheable(true).list(); for (int j = 0; j < listdist.size(); j++) { District dist = listdist.get(j); query = session.createQuery( "FROM Announcement where status = 1 and district=:distcode and branchCode=0 "); query.setParameter("distcode", dist.getDistrictCode()); listAnnouncement = query.setCacheable(true).list(); query = session.createQuery("FROM District where status = 1 and districtCode=:distcode "); query.setParameter("distcode", dist.getDistrictCode()); ArrayList<District> distlist = (ArrayList<District>) query.setCacheable(true).list(); for (int a = 0; a < listbranch.size(); a++) { Branch branch = listbranch.get(a); query = session.createQuery( "FROM Announcement where status = 1 and branchCode=:branch and cityCode=:code "); query.setParameter("branch", branch.getBranchCode()); query.setParameter("code", "0"); listAnnouncement = query.setCacheable(true).list(); query = session.createQuery("FROM Branch where status = 1 and branchCode=:branch "); query.setParameter("branch", branch.getBranchCode()); ArrayList<Branch> branchlist = (ArrayList<Branch>) query.setCacheable(true).list(); for (int k = 0; k < listcity.size(); k++) { City city = listcity.get(k); query = session.createQuery( "FROM Announcement where status = 1 and cityCode=:citycode and sscCode=:code "); query.setParameter("citycode", city.getCityName()); query.setParameter("code", "0"); listAnnouncement = query.setCacheable(true).list(); query = session.createQuery("FROM City where cityName=:citycode "); query.setParameter("citycode", city.getCityName()); ArrayList<City> citylist = (ArrayList<City>) query.setCacheable(true).list(); for (int l = 0; l < listSsc.size(); l++) { Ssc ssc = listSsc.get(l); query = session .createQuery("FROM Announcement where status = 1 and sscCode=:ssccode "); query.setParameter("ssccode", ssc.getSscName()); listAnnouncement = query.setCacheable(true).list(); query = session.createQuery("FROM Ssc where sscName=:ssccode"); query.setParameter("ssccode", ssc.getSscName()); ArrayList<Ssc> ssclist = (ArrayList<Ssc>) query.setCacheable(true).list(); for (int m = 0; m < listOffice.size(); m++) { Office office = listOffice.get(m); query = session.createQuery( "FROM Announcement where status = 1 and officeCode=:code "); query.setParameter("code", office.getOfficeName()); listAnnouncement = query.setCacheable(true).list(); query = session.createQuery("FROM Office where officeName=:code"); query.setParameter("code", office.getOfficeName()); ArrayList<Office> officelist = (ArrayList<Office>) query.setCacheable(true) .list(); } // close Office for loop } // close ssc for loop } //close city for loop } // branch for loop } //close district for loop } //close bu for loop //listEGreeting = session.createQuery("FROM E_Greeting where status = 1").setCacheable(true).list(); Date edate = new Date(); log.log(Level.INFO, "Total Time " + (edate.getTime() - sdate.getTime())); session.flush(); session.clear(); session.close(); } catch (Exception e) { log.log(Level.INFO, "ImoUtilityDate --> getAnnouncementCache --> Exception " + e); e.printStackTrace(); LogsMaintenance logsMain = new LogsMaintenance(); StringWriter errors = new StringWriter(); e.printStackTrace(new PrintWriter(errors)); logsMain.insertLogs("IMOUtilityData", Level.SEVERE + "", errors.toString()); } finally { try { HibernateFactory.close(session); } catch (Exception e) { e.printStackTrace(); } } }
From source file:com.quix.aia.cn.imo.utilities.ImoUtilityData.java
License:Open Source License
public void getPresenterCache() { log.log(Level.INFO, "ImoUtilityDate --> getPresenterCache"); Session session = null; Transaction tx;/*from ww w . j a v a2 s.c o m*/ List<Presenter> listPresenter = null; List<Bu> listbu = null; List<District> listdist = null; List<City> listcity = null; List<Branch> listbranch = null; List<Ssc> listSsc = null; List<Office> listOffice = null; ArrayList al = new ArrayList(); try { Query query = null; session = HibernateFactory.openSession(); Date sdate = new Date(); log.log(Level.INFO, "Start Time " + sdate.getTime()); listbu = session.createQuery("FROM Bu where status = 1").setCacheable(true).list(); listdist = session.createQuery("FROM District where status = 1").setCacheable(true).list(); listbranch = session.createQuery("FROM Branch where status = 1").setCacheable(true).list(); listcity = session.createQuery("FROM City where status = 1").setCacheable(true).list(); listSsc = session.createQuery("FROM Ssc where status = 1").setCacheable(true).list(); listOffice = session.createQuery("FROM Office where status = 1").setCacheable(true).list(); listbu = session.createQuery("FROM Bu where status = 1 order by buName").setCacheable(true).list(); listdist = session.createQuery("FROM District where status = 1 order by districtName") .setCacheable(true).list(); listbranch = session.createQuery("FROM Branch where status = 1 order by branchName").setCacheable(true) .list(); listcity = session.createQuery("FROM City where status = 1 order by cityName").setCacheable(true) .list(); listSsc = session.createQuery("FROM Ssc where status = 1 order by sscName").setCacheable(true).list(); listOffice = session.createQuery("FROM Office where status = 1 order by sscName").setCacheable(true) .list(); for (int i = 0; i < listbu.size(); i++) { Bu bu = listbu.get(i); query = session.createQuery("FROM Presenter where status = 1 and buCode=:bucode and district=0 "); query.setParameter("bucode", bu.getBuCode()); listPresenter = query.setCacheable(true).list(); query = session.createQuery("FROM Bu where status = 1 and buCode=:bucode "); query.setParameter("bucode", bu.getBuCode()); ArrayList<Bu> bulist = (ArrayList<Bu>) query.setCacheable(true).list(); for (int j = 0; j < listdist.size(); j++) { District dist = listdist.get(j); query = session.createQuery( "FROM Presenter where status = 1 and district=:distcode and branchCode=0 "); query.setParameter("distcode", dist.getDistrictCode()); listPresenter = query.setCacheable(true).list(); query = session.createQuery("FROM District where status = 1 and districtCode=:distcode "); query.setParameter("distcode", dist.getDistrictCode()); ArrayList<District> distlist = (ArrayList<District>) query.setCacheable(true).list(); for (int a = 0; a < listbranch.size(); a++) { Branch branch = listbranch.get(a); query = session.createQuery( "FROM Presenter where status = 1 and branchCode=:branch and cityCode=0 "); query.setParameter("branch", branch.getBranchCode()); listPresenter = query.setCacheable(true).list(); query = session.createQuery("FROM Branch where status = 1 and branchCode=:branch "); query.setParameter("branch", branch.getBranchCode()); ArrayList<Branch> branchlist = (ArrayList<Branch>) query.setCacheable(true).list(); for (int k = 0; k < listcity.size(); k++) { City city = listcity.get(k); query = session.createQuery( "FROM Presenter where status = 1 and cityCode=:citycode and sscCode=0 "); query.setParameter("citycode", city.getCityCode()); listPresenter = query.setCacheable(true).list(); query = session.createQuery("FROM City where status = 1 and cityCode=:citycode "); query.setParameter("citycode", city.getCityCode()); ArrayList<City> citylist = (ArrayList<City>) query.setCacheable(true).list(); for (int l = 0; l < listSsc.size(); l++) { Ssc ssc = listSsc.get(l); query = session .createQuery("FROM Presenter where status = 1 and sscCode=:ssccode "); query.setParameter("ssccode", ssc.getSscCode()); listPresenter = query.setCacheable(true).list(); query = session.createQuery("FROM Ssc where status = 1 and sscCode=:ssccode"); query.setParameter("ssccode", ssc.getSscCode()); ArrayList<Ssc> ssclist = (ArrayList<Ssc>) query.setCacheable(true).list(); for (int m = 0; m < listOffice.size(); m++) { Office office = listOffice.get(m); query = session.createQuery( "FROM Presenter where status = 1 and officeCode=:code "); query.setParameter("code", office.getOfficeCode()); listPresenter = query.setCacheable(true).list(); query = session .createQuery("FROM Office where status = 1 and officeCode=:code"); query.setParameter("code", office.getOfficeCode()); ArrayList<Office> officelist = (ArrayList<Office>) query.setCacheable(true) .list(); } // close Office for loop } // close ssc for loop } //close city for loop } // close branch for loop } //close district for loop } //close bu for loop //listEGreeting = session.createQuery("FROM E_Greeting where status = 1").setCacheable(true).list(); Date edate = new Date(); log.log(Level.INFO, "Total Time " + (edate.getTime() - sdate.getTime())); session.flush(); session.clear(); session.close(); } catch (Exception e) { log.log(Level.INFO, "ImoUtilityDate --> getPresenterCache --> Exception " + e); e.printStackTrace(); LogsMaintenance logsMain = new LogsMaintenance(); StringWriter errors = new StringWriter(); e.printStackTrace(new PrintWriter(errors)); logsMain.insertLogs("IMOUtilityData", Level.SEVERE + "", errors.toString()); } finally { try { HibernateFactory.close(session); } catch (Exception e) { e.printStackTrace(); } } }