List of usage examples for org.hibernate Query setCacheable
Query<R> setCacheable(boolean cacheable);
From source file:com.quix.aia.cn.imo.utilities.ImoUtilityData.java
License:Open Source License
public void getHolidayCache() { log.log(Level.INFO, "ImoUtilityDate --> getHolidayCache"); Session session = null;// w ww . jav a 2 s . c o m Transaction tx; List<Holiday> listHoliday = null; List<Bu> listbu = null; List<District> listdist = 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(); listcity = session.createQuery("FROM City where status = 1").setCacheable(true).list(); listSsc = session.createQuery("FROM Ssc 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(); 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(); 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(); // listHoliday = session.createQuery("FROM Holiday where status = 1 and buCode="+ bu.getBuCode()+" and district=0 ").setFirstResult(0).setCacheable(true).list(); // al.add(listHoliday); 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 cityCode=0 "); query.setParameter("distcode", dist.getDistrictCode()); listHoliday = 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 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 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 Ssc where status = 1 and sscCode=:ssccode"); query.setParameter("ssccode", ssc.getSscCode()); ArrayList<Ssc> ssclist = (ArrayList<Ssc>) query.setCacheable(true).list(); } // close ssc for loop } //close city 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 --> getHolidayCache --> 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.rapid.develop.core.jersey.features.hibernate.GenericDao.java
License:Apache License
public List<T> list() { String sql = "from " + entityClass.getSimpleName() + " where deleted = false order by createDate"; Query query = this.createQuery(sql); query.setCacheable(true); return query.list(); }
From source file:com.rapid.develop.core.jersey.features.hibernate.GenericDao.java
License:Apache License
public Query createQuery(String sql) { Query query = this.getCurrentSession().createQuery(sql); query.setCacheable(false); return query; }
From source file:com.rapid.develop.core.jersey.features.hibernate.GenericDao.java
License:Apache License
public Query createQuery(String sql, Boolean cacheable) { Query query = this.getCurrentSession().createQuery(sql); query.setCacheable(cacheable); return query; }
From source file:com.rapid.develop.core.jersey.features.hibernate.GenericDao.java
License:Apache License
public Query createQuery(String sql, Object... values) { Query query = this.getCurrentSession().createQuery(sql); for (int i = 0; i < values.length; i++) { query.setParameter(i, values[i]); }// w ww . j av a 2 s .com query.setCacheable(false); return query; }
From source file:com.rapid.develop.core.jersey.features.hibernate.GenericDao.java
License:Apache License
public Query createQuery(String sql, Boolean cacheable, Object... values) { Query query = this.getCurrentSession().createQuery(sql); for (int i = 0; i < values.length; i++) { query.setParameter(i, values[i]); }//from w w w . j av a 2 s. com query.setCacheable(cacheable); return query; }
From source file:com.redhat.rhn.common.hibernate.HibernateFactory.java
License:Open Source License
/** * Using a named query, find all the objects matching the criteria within. * Warning: This can be very expensive if the returned list is large. Use * only for small tables with static data * @param qryName Named query to use to find a list of objects. * @param qryParams Map of named bind parameters whose keys are Strings. The * map can also be null.//from ww w . j a v a2s. c o m * @param cacheable if we should cache the results of this query * @return List of objects returned by named query, or null if nothing * found. */ protected List listObjectsByNamedQuery(String qryName, Map qryParams, boolean cacheable) { Session session = null; List retval = null; session = HibernateFactory.getSession(); Query query = session.getNamedQuery(qryName); query.setCacheable(cacheable); bindParameters(query, qryParams); retval = query.list(); return retval; }
From source file:com.redhat.rhn.domain.kickstart.KickstartFactory.java
License:Open Source License
/** * Looks up a specific KickstartCommandName * @param commandName name of the KickstartCommandName * @return found instance, if any//from ww w .j a v a 2s.c o m */ public static KickstartCommandName lookupKickstartCommandName(String commandName) { Session session = null; KickstartCommandName retval = null; session = HibernateFactory.getSession(); Query query = session.getNamedQuery("KickstartCommandName.findByLabel"); //Retrieve from cache if there query.setCacheable(true); query.setParameter("name", commandName); retval = (KickstartCommandName) query.uniqueResult(); return retval; }
From source file:com.redhat.rhn.domain.kickstart.KickstartFactory.java
License:Open Source License
/** * Lookup KickstartableTree by tree id and org id * @param treeId desired tree/* w ww . j a v a 2 s . co m*/ * @param org owning org * @return KickstartableTree if found, otherwise null */ public static KickstartableTree lookupKickstartTreeByIdAndOrg(Long treeId, Org org) { Session session = null; KickstartableTree retval = null; String queryName = "KickstartableTree.findByIdAndOrg"; if (treeId != null && org != null) { session = HibernateFactory.getSession(); Query query = session.getNamedQuery(queryName); query.setLong("org_id", org.getId().longValue()); query.setLong("tree_id", treeId.longValue()); //Retrieve from cache if there retval = (KickstartableTree) query.setCacheable(true).uniqueResult(); } return retval; }
From source file:com.sapienter.jbilling.server.pluggableTask.admin.PluggableTaskDAS.java
License:Open Source License
public List<PluggableTaskDTO> findAllByEntity(Integer entityId) { Query query = getSession().createQuery(findAllByEntitySQL); query.setParameter("entity", entityId); query.setCacheable(true); query.setComment("PluggableTaskDAS.findAllByEntity"); return query.list(); }