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.taxonomy.impl.hibernate.TaxonConceptDAOImpl.java

License:Open Source License

/**
 * @see org.gbif.portal.dao.taxonomy.TaxonConceptDAO#getDepartmentRootConceptsFor(java.lang.String)
 *///  w w w . j  a v a2 s.c  om
@SuppressWarnings("unchecked")
public List<TaxonConceptLite> getDepartmentRootConceptsFor(final String isoDepartmentCode) {
    HibernateTemplate template = getHibernateTemplate();
    return (List<TaxonConceptLite>) template.execute(new HibernateCallback() {

        public Object doInHibernate(Session session) {
            // FIXME This query hardcodes the root rank to be
            // kingdom - not very elegant but the alternative query
            // select..where parent_concept_id is null was soo slooow
            Query query = session.createQuery("select tdt.taxonConceptLite from TaxonDepartment tdt"
                    + " inner join fetch tdt.taxonConceptLite.taxonNameLite"
                    + " where tdt.key.isoDepartmentCode = :isoDepartmentCode"
                    + " and tdt.taxonConceptLite.taxonRank=:taxonRank"
                    + " and tdt.taxonConceptLite.isAccepted=true"
                    + " order by tdt.taxonConceptLite.taxonRank asc, tdt.taxonConceptLite.taxonNameLite.canonical");
            query.setParameter("isoDepartmentCode", isoDepartmentCode);
            query.setParameter("taxonRank", TaxonRank.KINGDOM);
            query.setCacheable(true);
            return query.list();
        }
    });
}

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

License:Open Source License

/**
 * @see org.gbif.portal.dao.taxonomy.TaxonConceptDAO#getCountyRootConceptsFor(java.lang.String)
 */// w ww .j  a v  a 2  s. c  om
@SuppressWarnings("unchecked")
public List<TaxonConceptLite> getCountyRootConceptsFor(final String isoCountyCode) {
    HibernateTemplate template = getHibernateTemplate();
    return (List<TaxonConceptLite>) template.execute(new HibernateCallback() {

        public Object doInHibernate(Session session) {
            // FIXME This query hardcodes the root rank to be
            // kingdom - not very elegant but the alternative query
            // select..where parent_concept_id is null was soo slooow
            Query query = session.createQuery("select tct.taxonConceptLite from TaxonCounty tct"
                    + " inner join fetch tct.taxonConceptLite.taxonNameLite"
                    + " where tct.key.isoCountyCode = :isoDepartmentCode"
                    + " and tct.taxonConceptLite.taxonRank=:taxonRank"
                    + " and tct.taxonConceptLite.isAccepted=true"
                    + " order by tct.taxonConceptLite.taxonRank asc, tct.taxonConceptLite.taxonNameLite.canonical");
            query.setParameter("isoCountyCode", isoCountyCode);
            query.setParameter("taxonRank", TaxonRank.KINGDOM);
            query.setCacheable(true);
            return query.list();
        }
    });
}

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

License:Open Source License

/**
 * @see org.gbif.portal.dao.taxonomy.TaxonConceptDAO#getParamoRootConceptsFor(java.lang.String)
 *///from w w w .j a v  a 2s.c  o  m
@SuppressWarnings("unchecked")
public List<TaxonConceptLite> getParamoRootConceptsFor(final String complexId) {
    HibernateTemplate template = getHibernateTemplate();
    return (List<TaxonConceptLite>) template.execute(new HibernateCallback() {

        public Object doInHibernate(Session session) {
            // FIXME This query hardcodes the root rank to be
            // kingdom - not very elegant but the alternative query
            // select..where parent_concept_id is null was soo slooow
            Query query = session.createQuery("select tct.taxonConceptLite from TaxonParamo tct"
                    + " inner join fetch tct.taxonConceptLite.taxonNameLite"
                    + " where tct.key.complexId = :complexId" + " and tct.taxonConceptLite.taxonRank=:taxonRank"
                    + " and tct.taxonConceptLite.isAccepted=true"
                    + " order by tct.taxonConceptLite.taxonRank asc, tct.taxonConceptLite.taxonNameLite.canonical");
            query.setParameter("complexId", complexId);
            query.setParameter("taxonRank", TaxonRank.KINGDOM);
            query.setCacheable(true);
            return query.list();
        }
    });
}

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

License:Open Source License

/**
 * @see org.gbif.portal.dao.taxonomy.TaxonConceptDAO#getMarineZoneRootConceptsFor(java.lang.String)
 */// w w  w .  j  a  va2 s . c om
@SuppressWarnings("unchecked")
public List<TaxonConceptLite> getMarineZoneRootConceptsFor(final String marineId) {
    HibernateTemplate template = getHibernateTemplate();
    return (List<TaxonConceptLite>) template.execute(new HibernateCallback() {

        public Object doInHibernate(Session session) {
            // FIXME This query hardcodes the root rank to be
            // kingdom - not very elegant but the alternative query
            // select..where parent_concept_id is null was soo slooow
            Query query = session.createQuery("select tmz.taxonConceptLite from TaxonMarineZone tmz"
                    + " inner join fetch tmz.taxonConceptLite.taxonNameLite"
                    + " where tmz.key.marineId = :marineId" + " and tmz.taxonConceptLite.taxonRank=:taxonRank"
                    + " and tmz.taxonConceptLite.isAccepted=true"
                    + " order by tmz.taxonConceptLite.taxonRank asc, tmz.taxonConceptLite.taxonNameLite.canonical");
            query.setParameter("marineId", marineId);
            query.setParameter("taxonRank", TaxonRank.KINGDOM);
            query.setCacheable(true);
            return query.list();
        }
    });
}

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

License:Open Source License

/**
 * @see org.gbif.portal.dao.taxonomy.TaxonConceptDAO#getProtectedAreaRootConceptsFor(java.lang.String)
 *//*from   w  w  w .j a v  a  2  s . c o  m*/
@SuppressWarnings("unchecked")
public List<TaxonConceptLite> getProtectedAreaRootConceptsFor(final String protectedArea) {
    HibernateTemplate template = getHibernateTemplate();
    return (List<TaxonConceptLite>) template.execute(new HibernateCallback() {

        public Object doInHibernate(Session session) {
            // FIXME This query hardcodes the root rank to be
            // kingdom - not very elegant but the alternative query
            // select..where parent_concept_id is null was soo slooow
            Query query = session.createQuery("select tpa.taxonConceptLite from TaxonProtectedArea tpa"
                    + " inner join fetch tpa.taxonConceptLite.taxonNameLite"
                    + " where tpa.key.protectedId = :protectedId"
                    + " and tpa.taxonConceptLite.taxonRank=:taxonRank"
                    + " and tpa.taxonConceptLite.isAccepted=true"
                    + " order by tpa.taxonConceptLite.taxonRank asc, tpa.taxonConceptLite.taxonNameLite.canonical");
            query.setParameter("protectedId", protectedArea);
            query.setParameter("taxonRank", TaxonRank.KINGDOM);
            query.setCacheable(true);
            return query.list();
        }
    });
}

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

License:Open Source License

/**
 * @see org.gbif.portal.dao.taxonomy.TaxonConceptDAO#getEcosystemRootConceptsFor(java.lang.String)
 *//*from   ww  w  . j a  v  a2  s .  c o  m*/
@SuppressWarnings("unchecked")
public List<TaxonConceptLite> getEcosystemRootConceptsFor(final String ecosystem) {
    HibernateTemplate template = getHibernateTemplate();
    return (List<TaxonConceptLite>) template.execute(new HibernateCallback() {

        public Object doInHibernate(Session session) {
            // FIXME This query hardcodes the root rank to be
            // kingdom - not very elegant but the alternative query
            // select..where parent_concept_id is null was soo slooow
            Query query = session.createQuery("select te.taxonConceptLite from TaxonEcosystem te"
                    + " inner join fetch te.taxonConceptLite.taxonNameLite"
                    + " where te.key.ecosystemId = :ecosystemId"
                    + " and te.taxonConceptLite.taxonRank=:taxonRank"
                    + " and te.taxonConceptLite.isAccepted=true"
                    + " order by te.taxonConceptLite.taxonRank asc, te.taxonConceptLite.taxonNameLite.canonical");
            query.setParameter("ecosystemId", ecosystem);
            query.setParameter("taxonRank", TaxonRank.KINGDOM);
            query.setCacheable(true);
            return query.list();
        }
    });
}

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

License:Open Source License

/**
 * @see org.gbif.portal.dao.taxonomy.TaxonConceptDAO#getZonificacionRootConceptsFor(java.lang.String)
 *//*from   w w  w  .  ja  va 2 s  . c  o m*/
@SuppressWarnings("unchecked")
public List<TaxonConceptLite> getZonificacionRootConceptsFor(final String zonificacion) {
    HibernateTemplate template = getHibernateTemplate();
    return (List<TaxonConceptLite>) template.execute(new HibernateCallback() {

        public Object doInHibernate(Session session) {
            // FIXME This query hardcodes the root rank to be
            // kingdom - not very elegant but the alternative query
            // select..where parent_concept_id is null was soo slooow
            Query query = session.createQuery("select tz.taxonConceptLite from TaxonZonificacion tz"
                    + " inner join fetch tz.taxonConceptLite.taxonNameLite"
                    + " where tz.key.zonificacionId = :zonificacionId"
                    + " and tz.taxonConceptLite.taxonRank=:taxonRank"
                    + " and tz.taxonConceptLite.isAccepted=true"
                    + " order by tz.taxonConceptLite.taxonRank asc, tz.taxonConceptLite.taxonNameLite.canonical");
            query.setParameter("zonificacionId", zonificacion);
            query.setParameter("taxonRank", TaxonRank.KINGDOM);
            query.setCacheable(true);
            return query.list();
        }
    });
}

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

License:Open Source License

/**
 * @see org.gbif.portal.dao.taxonomy.TaxonConceptDAO#getDetailedTaxonConceptFor(long)
 *///from  w  w w .  j a va  2s  .  c  o m
public TaxonConcept getDetailedTaxonConceptFor(final long taxonConceptId) {
    HibernateTemplate template = getHibernateTemplate();
    return (TaxonConcept) template.execute(new HibernateCallback() {

        public Object doInHibernate(Session session) {
            Query query = session.createQuery("from TaxonConcept tc" + " inner join fetch tc.taxonName"
                    + " left join fetch tc.parentConcept left join fetch tc.parentConcept.taxonName"
                    + " left join fetch tc.kingdomConcept left join fetch tc.kingdomConcept.taxonNameLite"
                    + " left join fetch tc.phylumConcept left join fetch tc.phylumConcept.taxonNameLite"
                    + " left join fetch tc.orderConcept left join fetch tc.orderConcept.taxonNameLite"
                    + " left join fetch tc.classConcept left join fetch tc.classConcept.taxonNameLite"
                    + " left join fetch tc.familyConcept left join fetch tc.familyConcept.taxonNameLite"
                    + " left join fetch tc.genusConcept left join fetch tc.genusConcept.taxonNameLite"
                    + " left join fetch tc.speciesConcept left join fetch tc.speciesConcept.taxonNameLite"
                    + " inner join fetch tc.dataResource" + " inner join fetch tc.dataProvider"
                    + " where tc.id=?");
            query.setParameter(0, taxonConceptId);
            query.setCacheable(true);
            return query.uniqueResult();
        }
    });
}

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

License:Open Source License

/**
 * @see org.gbif.portal.dao.taxonomy.TaxonConceptDAO#getNubConceptFor(long)
 *//*from  ww w  .j a  v  a  2s.  co  m*/
public TaxonConcept getNubConceptFor(final long taxonConceptId) {
    HibernateTemplate template = getHibernateTemplate();
    return (TaxonConcept) template.execute(new HibernateCallback() {

        public Object doInHibernate(Session session) {
            Query query = session.createQuery("select tc.partnerConcept from TaxonConcept tc"
                    + " inner join fetch tc.partnerConcept.taxonName"
                    + " left join fetch tc.partnerConcept.kingdomConcept left join fetch tc.partnerConcept.kingdomConcept.taxonNameLite"
                    + " left join fetch tc.partnerConcept.phylumConcept left join fetch tc.partnerConcept.phylumConcept.taxonNameLite"
                    + " left join fetch tc.partnerConcept.orderConcept left join fetch tc.partnerConcept.orderConcept.taxonNameLite"
                    + " left join fetch tc.partnerConcept.classConcept left join fetch tc.partnerConcept.classConcept.taxonNameLite"
                    + " left join fetch tc.partnerConcept.familyConcept left join fetch tc.partnerConcept.familyConcept.taxonNameLite"
                    + " left join fetch tc.partnerConcept.genusConcept left join fetch tc.partnerConcept.genusConcept.taxonNameLite"
                    + " left join fetch tc.partnerConcept.speciesConcept left join fetch tc.partnerConcept.speciesConcept.taxonNameLite"
                    + " where tc.id = ?");
            query.setParameter(0, taxonConceptId);
            query.setCacheable(true);
            return query.uniqueResult();
        }
    });
}

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

License:Open Source License

/**
 * @see org.gbif.portal.dao.taxonomy.TaxonConceptDAO#getParentChildConcepts(java.lang.String)
 *//*from  w  w  w. jav  a2 s .  co m*/
public TaxonConcept getParentChildConcepts(final long taxonConceptId, final boolean retrieveChildren,
        final boolean allowUnconfirmed) {
    HibernateTemplate template = getHibernateTemplate();
    return (TaxonConcept) template.execute(new HibernateCallback() {

        public Object doInHibernate(Session session) {
            StringBuffer sb = new StringBuffer("from TaxonConcept tc");
            sb.append(" inner join fetch tc.taxonName");
            sb.append(" left outer join fetch tc.parentConcept");
            sb.append(" left outer join fetch tc.parentConcept.taxonName");
            if (retrieveChildren) {
                sb.append(" left outer join fetch tc.childConcepts as child");
                sb.append(" left outer join fetch child.taxonNameLite");
            }
            sb.append(" where tc.id=?");
            if (retrieveChildren && !allowUnconfirmed) {
                sb.append(" and child.taxonomicPriority<=");
                sb.append(taxonomicPriorityThreshold);
            }
            if (retrieveChildren)
                sb.append(" order by child.taxonNameLite.canonical");
            Query query = session.createQuery(sb.toString());
            query.setParameter(0, taxonConceptId);
            query.setCacheable(true);
            query.setMaxResults(maxChildConcepts);
            return query.uniqueResult();
        }
    });
}