List of usage examples for org.hibernate Query setCacheable
Query<R> setCacheable(boolean cacheable);
From source file:com.gisgraphy.domain.repository.GenericGisDao.java
License:Open Source License
@SuppressWarnings("unchecked") public List<T> listByName(final String name) { Assert.notNull(name);//from ww w. j a va 2s. c o m return (List<T>) this.getHibernateTemplate().execute(new HibernateCallback() { public Object doInHibernate(Session session) throws PersistenceException { String queryString = "from " + persistentClass.getSimpleName() + " as c where c.name= ?"; Query qry = session.createQuery(queryString); qry.setCacheable(true); qry.setParameter(0, name); List<T> results = (List<T>) qry.list(); if (results == null) { results = new ArrayList<T>(); } return results; } }); }
From source file:com.gisgraphy.domain.repository.GenericGisDao.java
License:Open Source License
@SuppressWarnings("unchecked") public T getByFeatureId(final Long featureId) { Assert.notNull(featureId);/* w w w . ja v a 2 s.co m*/ return (T) this.getHibernateTemplate().execute(new HibernateCallback() { public Object doInHibernate(Session session) throws PersistenceException { String queryString = "from " + persistentClass.getSimpleName() + " as g where g.featureId= ?"; Query qry = session.createQuery(queryString); qry.setCacheable(true); qry.setParameter(0, featureId); T result = (T) qry.uniqueResult(); return result; } }); }
From source file:com.gisgraphy.domain.repository.GenericGisDao.java
License:Open Source License
@SuppressWarnings("unchecked") public List<T> getDirties() { return (List<T>) this.getHibernateTemplate().execute(new HibernateCallback() { public Object doInHibernate(final Session session) throws PersistenceException { final String queryString = "from " + persistentClass.getSimpleName() + " as g where g.featureCode ='" + ImporterConfig.DEFAULT_FEATURE_CODE + "' or g.location=? or g.featureClass='" + ImporterConfig.DEFAULT_FEATURE_CLASS + "'"; final Query qry = session.createQuery(queryString); qry.setParameter(0, GeolocHelper.createPoint(0F, 0F), GEOMETRY_TYPE); qry.setCacheable(true); List<T> result = (List<T>) qry.list(); if (result == null) { result = new ArrayList<T>(); }//from ww w .j av a2 s .c o m return result; } }); }
From source file:com.gisgraphy.domain.repository.GenericGisDao.java
License:Open Source License
@SuppressWarnings("unchecked") public List<T> listByFeatureIds(final List<Long> ids) { if (ids == null || ids.size() == 0) { return new ArrayList<T>(); }//w ww .ja va 2 s . co m return (List<T>) this.getHibernateTemplate().execute(new HibernateCallback() { public Object doInHibernate(final Session session) throws PersistenceException { final String queryString = "from " + persistentClass.getSimpleName() + " as g where g.featureId in (:ids)"; final Query qry = session.createQuery(queryString); qry.setParameterList("ids", ids); qry.setCacheable(true); List<T> result = (List<T>) qry.list(); if (result == null) { result = new ArrayList<T>(); } return result; } }); }
From source file:com.gisgraphy.domain.repository.GenericGisDao.java
License:Open Source License
@SuppressWarnings("unchecked") public T getEager(final Long id) { Assert.notNull(id, "Can not retrieve an Ogject with a null id"); T returnValue = null;//from ww w . j ava 2 s .c om try { return (T) this.getHibernateTemplate().execute(new HibernateCallback() { public Object doInHibernate(Session session) throws PersistenceException { String queryString = "from " + persistentClass.getSimpleName() + " o where o.id=" + id; Query qry = session.createQuery(queryString); qry.setCacheable(true); GisFeature feature = (GisFeature) qry.uniqueResult(); feature.getAdm().getAdm1Code(); feature.getAlternateNames().size(); return feature; } }); } catch (Exception e) { logger.info("could not retrieve object of type " + persistentClass.getSimpleName() + " with id " + id, e); } return returnValue; }
From source file:com.gisgraphy.domain.repository.GenericGisDao.java
License:Open Source License
public String getShapeAsWKTByFeatureId(final Long featureId) { if (featureId == null) { return null; }//from w w w .j ava 2 s. co m return (String) this.getHibernateTemplate().execute(new HibernateCallback() { public Object doInHibernate(Session session) throws PersistenceException { String queryString = "select ST_AsText(" + GisFeature.SHAPE_COLUMN_NAME + ") from " + persistentClass.getSimpleName() + " as g where g.featureId= ?"; Query qry = session.createQuery(queryString); qry.setParameter(0, featureId); qry.setCacheable(true); return (String) qry.uniqueResult(); } }); }
From source file:com.gisgraphy.domain.repository.GisFeatureDao.java
License:Open Source License
public int deleteAllExceptAdmsAndCountries() { return ((Integer) this.getHibernateTemplate().execute(new HibernateCallback() { public Object doInHibernate(Session session) throws PersistenceException { String queryString = "delete from " + persistentClass.getSimpleName() + " as g where (g.featureCode NOT IN ('ADM1','ADM2','ADM3','ADM4') OR g.featureCode is null) AND g.featureId NOT IN (select featureId from Country) "; Query qry = session.createQuery(queryString); // Need to flush to avoid optimisticLock exception session.flush();/*w ww .jav a2 s .co m*/ session.clear(); qry.setCacheable(false); return Integer.valueOf(qry.executeUpdate()); } })).intValue(); }
From source file:com.gisgraphy.domain.repository.GisFeatureDao.java
License:Open Source License
public long getMaxFeatureId() { return (Long) this.getHibernateTemplate().execute(new HibernateCallback() { public Object doInHibernate(Session session) throws PersistenceException { String queryString = "select max(featureId) from " + GisFeature.class.getSimpleName(); Query qry = session.createQuery(queryString); qry.setCacheable(true); Long count = (Long) qry.uniqueResult(); return count == null ? 0 : count; }/*from w w w. jav a2s. c o m*/ }); }
From source file:com.gisgraphy.domain.repository.LanguageDao.java
License:Open Source License
public Language getByIso639Alpha2Code(final String iso639Alpha2LanguageCode) { return (Language) this.getHibernateTemplate().execute(new HibernateCallback() { public Object doInHibernate(Session session) throws PersistenceException { String queryString = "from " + Language.class.getSimpleName() + " as l where Iso639Alpha2LanguageCode= ?"; Query qry = session.createQuery(queryString); qry.setCacheable(true); qry.setParameter(0, iso639Alpha2LanguageCode.toUpperCase()); Language result = (Language) qry.uniqueResult(); return result; }/*from w ww .java 2s . c o m*/ }); }
From source file:com.gisgraphy.domain.repository.LanguageDao.java
License:Open Source License
public Language getByIso639Alpha3Code(final String iso639Alpha3Code) { return (Language) this.getHibernateTemplate().execute(new HibernateCallback() { public Object doInHibernate(Session session) throws PersistenceException { String queryString = "from " + Language.class.getSimpleName() + " as l where Iso639Alpha3LanguageCode= ?"; Query qry = session.createQuery(queryString); qry.setCacheable(true); qry.setParameter(0, iso639Alpha3Code.toUpperCase()); Language result = (Language) qry.uniqueResult(); return result; }/*from w ww . ja v a 2 s.com*/ }); }