Example usage for org.hibernate Query setCacheable

List of usage examples for org.hibernate Query setCacheable

Introduction

In this page you can find the example usage for org.hibernate Query setCacheable.

Prototype

Query<R> setCacheable(boolean cacheable);

Source Link

Document

Enable/disable second level query (result) caching for this query.

Usage

From source file:com.gisgraphy.domain.repository.OpenStreetMapDao.java

License:Open Source License

public OpenStreetMap getByGid(final Long gid) {
    Assert.notNull(gid);/*from  w  w w. ja  v a  2s. c o m*/
    return (OpenStreetMap) this.getHibernateTemplate().execute(new HibernateCallback() {

        public Object doInHibernate(Session session) throws PersistenceException {
            String queryString = "from " + OpenStreetMap.class.getSimpleName() + " as c where c.gid= ?";

            Query qry = session.createQuery(queryString);
            qry.setCacheable(true);

            qry.setParameter(0, gid);

            OpenStreetMap result = (OpenStreetMap) qry.uniqueResult();
            return result;
        }
    });
}

From source file:com.gisgraphy.domain.repository.OpenStreetMapDao.java

License:Open Source License

public long countEstimate() {
    return (Long) this.getHibernateTemplate().execute(new HibernateCallback() {

        public Object doInHibernate(Session session) throws PersistenceException {
            String queryString = "select max(gid)-min(gid)+1 from " + persistentClass.getSimpleName();

            Query qry = session.createQuery(queryString);
            qry.setCacheable(true);
            Long count = (Long) qry.uniqueResult();
            return count == null ? 0 : count;
        }/*from   w ww .j  a v  a2s . c o m*/
    });
}

From source file:com.gisgraphy.domain.repository.OpenStreetMapDao.java

License:Open Source License

public OpenStreetMap getByOpenStreetMapId(final Long openstreetmapId) {
    Assert.notNull(openstreetmapId);//from   w  w w. j av a  2  s  .  c  o m
    return (OpenStreetMap) this.getHibernateTemplate().execute(new HibernateCallback() {

        public Object doInHibernate(Session session) throws PersistenceException {
            String queryString = "from " + OpenStreetMap.class.getSimpleName()
                    + " as c where c.openstreetmapId= ?";

            Query qry = session.createQuery(queryString);
            qry.setMaxResults(1);
            //we need to limit to 1 because a street can be in two countries
            qry.setCacheable(true);

            qry.setParameter(0, openstreetmapId);

            OpenStreetMap result = (OpenStreetMap) qry.uniqueResult();
            return result;
        }
    });
}

From source file:com.gisgraphy.domain.repository.OpenStreetMapDao.java

License:Open Source License

public long getMaxOpenstreetMapId() {
    return (Long) this.getHibernateTemplate().execute(new HibernateCallback() {

        public Object doInHibernate(Session session) throws PersistenceException {
            String queryString = "select max(openstreetmapId) from " + OpenStreetMap.class.getSimpleName();

            Query qry = session.createQuery(queryString);
            qry.setCacheable(true);
            Long count = (Long) qry.uniqueResult();
            return count == null ? 0 : count;
        }/*from w ww . j  ava 2  s  .  c  o m*/
    });
}

From source file:com.gisgraphy.domain.repository.OpenStreetMapDao.java

License:Open Source License

public long getMaxGid() {
    return (Long) this.getHibernateTemplate().execute(new HibernateCallback() {

        public Object doInHibernate(Session session) throws PersistenceException {
            String queryString = "select max(gid) from " + OpenStreetMap.class.getSimpleName();

            Query qry = session.createQuery(queryString);
            qry.setCacheable(true);
            Long count = (Long) qry.uniqueResult();
            return count == null ? 0 : count;
        }/*from  w w  w  .  ja v a 2 s . com*/
    });
}

From source file:com.gisgraphy.domain.repository.OpenStreetMapDao.java

License:Open Source License

public String getShapeAsWKTByGId(final Long gid) {
    if (gid == null) {
        return null;
    }//from ww w . ja  v a 2  s .  c om
    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 o where o.gid=?";

            Query qry = session.createQuery(queryString);
            qry.setParameter(0, gid);
            qry.setCacheable(true);
            return (String) qry.uniqueResult();
        }
    });
}

From source file:com.gisgraphy.domain.repository.StatsUsageDao.java

License:Open Source License

public StatsUsage getByUsageType(final StatsUsageType statsUsageType) {
    return (StatsUsage) this.getHibernateTemplate().execute(new HibernateCallback() {

        public Object doInHibernate(final Session session) throws PersistenceException {
            final String queryString = "from StatsUsage as s where s.statsUsageType = :statstype";

            final Query qry = session.createQuery(queryString);
            qry.setParameter("statstype", statsUsageType);
            qry.setCacheable(true);

            return (StatsUsage) qry.uniqueResult();
        }/*from  w  w  w . j  av a2s.  co  m*/
    });
}

From source file:com.gisgraphy.domain.repository.ZipCodeDao.java

License:Open Source License

@SuppressWarnings("unchecked")
public List<ZipCode> getByCodeAndCountry(final String code, final String countryCode) {
    Assert.notNull(code);// ww  w.ja  va  2 s  . co  m
    Assert.notNull(countryCode);
    return (List<ZipCode>) this.getHibernateTemplate().execute(new HibernateCallback() {

        public Object doInHibernate(Session session) throws PersistenceException {
            String queryString = "from " + getPersistenceClass().getSimpleName()
                    + " as z where z.code= ? and z.gisFeature.countryCode= ?";

            Query qry = session.createQuery(queryString);
            qry.setCacheable(true);

            qry.setParameter(0, code.toUpperCase());
            qry.setParameter(1, countryCode.toUpperCase());

            List<ZipCode> result = (List<ZipCode>) qry.list();
            return result == null ? new ArrayList<ZipCode>() : result;
        }
    });
}

From source file:com.gisgraphy.domain.repository.ZipCodeDao.java

License:Open Source License

@SuppressWarnings("unchecked")
public List<ZipCode> listByCode(final String code) {
    Assert.notNull(code);/*from  ww w .  j av a  2s .  c om*/
    return (List<ZipCode>) this.getHibernateTemplate().execute(new HibernateCallback() {

        public Object doInHibernate(Session session) throws PersistenceException {
            String queryString = "from " + getPersistenceClass().getSimpleName() + " as z where z.code= ?";

            Query qry = session.createQuery(queryString);
            qry.setCacheable(true);

            qry.setParameter(0, code.toUpperCase());

            List<ZipCode> result = (List<ZipCode>) qry.list();
            return result == null ? new ArrayList<ZipCode>() : result;
        }
    });
}

From source file:com.hazelcast.hibernate.HibernateSlowTestSupport.java

License:Open Source License

protected List<DummyEntity> executeQuery(SessionFactory factory) {
    Session session = factory.openSession();
    try {//w w  w.  ja v a 2 s  .co  m
        Query query = session.createQuery("from " + DummyEntity.class.getName());
        query.setCacheable(false);
        return query.list();
    } finally {
        session.close();
    }
}