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:org.gbif.portal.dao.resources.impl.hibernate.ResourceNetworkDAOImpl.java

License:Open Source License

/**
 * @see org.gbif.portal.dao.resources.ResourceNetworkDAO#getResourceNetworkFor(long)
 *//*w w w.  j a v  a 2 s.  c  om*/
public ResourceNetwork getResourceNetworkFor(final long resourceNetworkId) {
    HibernateTemplate template = getHibernateTemplate();
    return (ResourceNetwork) template.execute(new HibernateCallback() {
        public Object doInHibernate(Session session) {
            Query query = session.createQuery("from ResourceNetwork rn where rn.id = ?");
            query.setParameter(0, resourceNetworkId);
            query.setCacheable(true);
            return query.uniqueResult();
        }
    });
}

From source file:org.gbif.portal.dao.resources.impl.hibernate.ResourceNetworkDAOImpl.java

License:Open Source License

/**
 * @see org.gbif.portal.dao.resources.ResourceNetworkDAO#getResourceNetworksForDataResource(long)
 *//*from   ww w .j  a  v a  2 s.c om*/
@SuppressWarnings("unchecked")
public List<ResourceNetwork> getResourceNetworksForDataResource(final long dataResourceId) {
    HibernateTemplate template = getHibernateTemplate();
    return (List<ResourceNetwork>) template.execute(new HibernateCallback() {
        public Object doInHibernate(Session session) {
            Query query = session.createQuery("select nm.resourceNetwork from NetworkMembership nm"
                    + " join nm.dataResource dr" + " where dr.id = ?");
            query.setParameter(0, dataResourceId);
            query.setCacheable(true);
            return query.list();
        }
    });
}

From source file:org.gbif.portal.dao.resources.impl.hibernate.ResourceNetworkDAOImpl.java

License:Open Source License

/**
 * @see org.gbif.portal.dao.resources.ResourceNetworkDAO#getResourceNetworkList()
 *///  w  ww.  j  a va 2  s .c  o m
public List getResourceNetworkList() {
    HibernateTemplate template = getHibernateTemplate();
    return (List) template.execute(new HibernateCallback() {
        public Object doInHibernate(Session session) {
            Query query = session.createQuery("select id, name from ResourceNetwork");
            query.setCacheable(true);
            return query.list();
        }
    });
}

From source file:org.gbif.portal.dao.taxonomy.impl.hibernate.CommonNameDAOImpl.java

License:Open Source License

/**
 * @see org.gbif.portal.dao.taxonomy.CommonNameDAO#findCommonNames(java.lang.String, boolean, int, int)
 *//*ww  w.  ja v a  2 s . c  om*/
@SuppressWarnings("unchecked")
public List<String> findCommonNames(final String name, final boolean fuzzy, final int startIndex,
        final int maxResults) {
    HibernateTemplate template = getHibernateTemplate();
    return (List<String>) template.execute(new HibernateCallback() {
        public Object doInHibernate(Session session) {
            String nameStub = name;
            if (fuzzy)
                nameStub = nameStub + '%';
            Query query = session.createQuery(
                    "select distinct cn.name from CommonName cn inner join cn.taxonConcepts where cn.name like :nameStub");
            query.setParameter("nameStub", nameStub);
            query.setCacheable(true);
            query.setMaxResults(maxResults);
            query.setFirstResult(startIndex);
            return query.list();
        }
    });
}

From source file:org.gbif.portal.dao.taxonomy.impl.hibernate.CommonNameDAOImpl.java

License:Open Source License

/**
 * @see org.gbif.portal.dao.taxonomy.CommonNameDAO#findCommonNames(java.lang.String, boolean, int, int)
 *///from w  w  w  . j  a  v a  2s .com
@SuppressWarnings("unchecked")
public List<CommonName> findCommonNamesFetchingCorrespondingTaxonName(final String name, final boolean fuzzy,
        final int startIndex, final int maxResults) {
    HibernateTemplate template = getHibernateTemplate();
    return (List<CommonName>) template.execute(new HibernateCallback() {
        public Object doInHibernate(Session session) {
            String nameStub = name;
            if (fuzzy)
                nameStub = nameStub + '%';
            Query query = session.createQuery("from CommonName cn" + " inner join fetch cn.taxonConcepts"
                    + " inner join fetch cn.taxonConcepts.taxonName" + " where cn.name like :nameStub");
            query.setParameter("nameStub", nameStub);
            query.setCacheable(true);
            query.setMaxResults(maxResults);
            query.setFirstResult(startIndex);
            return query.list();
        }
    });
}

From source file:org.gbif.portal.dao.taxonomy.impl.hibernate.CommonNameDAOImpl.java

License:Open Source License

/**
 * @see org.gbif.portal.dao.taxonomy.CommonNameDAO#getCommonNamesFor(long, boolean, int, int)
 *//* w ww .ja v a  2s .c o  m*/
@SuppressWarnings("unchecked")
public List<CommonName> getCommonNamesFor(final long taxonConceptId, final boolean fuzzy, final int startIndex,
        final int maxResults) {
    HibernateTemplate template = getHibernateTemplate();
    return (List<CommonName>) template.execute(new HibernateCallback() {
        public Object doInHibernate(Session session) {
            Query query = session.createQuery("from CommonName cn where  cn.taxonConcepts.id=:taxonConceptId");
            query.setParameter("taxonConceptId", taxonConceptId);
            query.setCacheable(true);
            query.setMaxResults(maxResults);
            query.setFirstResult(startIndex);
            return query.list();
        }
    });
}

From source file:org.gbif.portal.dao.taxonomy.impl.hibernate.RelationshipAssertionDAOImpl.java

License:Open Source License

@SuppressWarnings("unchecked")
public List<RelationshipAssertion> getRelationshipAssertionsForFromTaxonConcept(final long fromTaxonConceptId) {
    HibernateTemplate template = getHibernateTemplate();
    return (List<RelationshipAssertion>) template.execute(new HibernateCallback() {
        public Object doInHibernate(Session session) {
            Query query = session.createQuery(
                    "from RelationshipAssertion ra" + " where ra.fromConcept.id = :fromTaxonConceptId");
            query.setParameter("fromTaxonConceptId", fromTaxonConceptId);
            query.setCacheable(true);
            return query.list();
        }/*from   w w  w  . jav a2s.c om*/
    });
}

From source file:org.gbif.portal.dao.taxonomy.impl.hibernate.RelationshipAssertionDAOImpl.java

License:Open Source License

@SuppressWarnings("unchecked")
public List<RelationshipAssertion> getRelationshipAssertionsForToTaxonConcept(final long toTaxonConceptId) {
    HibernateTemplate template = getHibernateTemplate();
    return (List<RelationshipAssertion>) template.execute(new HibernateCallback() {
        public Object doInHibernate(Session session) {
            Query query = session.createQuery(
                    "from RelationshipAssertion ra" + " where ra.toConcept.id = :toTaxonConceptId");
            query.setParameter("toTaxonConceptId", toTaxonConceptId);
            query.setCacheable(true);
            return query.list();
        }/*from ww  w.j  a  va  2  s .com*/
    });
}

From source file:org.gbif.portal.dao.taxonomy.impl.hibernate.RemoteConceptDAOImpl.java

License:Open Source License

/**
 * @see org.gbif.portal.dao.taxonomy.RemoteConceptDAO#findRemoteUrlFor(long)
 *///w w  w . j a  va2  s .  c  o m
@SuppressWarnings("unchecked")
public List<String> findRemoteUrlFor(final long taxonConceptId) {
    HibernateTemplate template = getHibernateTemplate();
    return (List<String>) template.execute(new HibernateCallback() {
        public Object doInHibernate(Session session) {
            Query query = session.createQuery("select remoteId from RemoteConcept rc"
                    + " where rc.taxonConceptId = :taxonConceptId and rc.idType= :idType");
            query.setParameter("taxonConceptId", taxonConceptId);
            query.setParameter("idType", IdType.URL);
            query.setCacheable(true);
            return query.list();
        }
    });
}

From source file:org.gbif.portal.dao.taxonomy.impl.hibernate.RemoteConceptDAOImpl.java

License:Open Source License

/**
 * @see org.gbif.portal.dao.taxonomy.RemoteConceptDAO#findRemoteUrlFor(long)
 *//*from w ww. j  a  v  a 2 s  .c  om*/
@SuppressWarnings("unchecked")
public List<RemoteConcept> findRemoteConceptsFor(final long taxonConceptId) {
    HibernateTemplate template = getHibernateTemplate();
    return (List<RemoteConcept>) template.execute(new HibernateCallback() {
        public Object doInHibernate(Session session) {
            Query query = session.createQuery(
                    "from RemoteConcept rc" + " where rc.taxonConceptId = :taxonConceptId order by rc.idType");
            query.setParameter("taxonConceptId", taxonConceptId);
            query.setCacheable(true);
            return query.list();
        }
    });
}