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#getTaxonConcept(long)
 *//*from ww w  .  j a  v  a 2 s.  c o m*/
public TaxonConcept getParentConceptFor(final long taxonConceptId) {
    HibernateTemplate template = getHibernateTemplate();
    return (TaxonConcept) template.execute(new HibernateCallback() {

        public Object doInHibernate(Session session) {
            Query query = session.createQuery("select tc.parentConcept from TaxonConcept tc"
                    + " inner join fetch tc.parentConcept.taxonName"
                    + " left join fetch tc.parentConcept.dataResource"
                    + " left join fetch tc.parentConcept.dataProvider"
                    + " left join fetch tc.parentConcept.parentConcept"
                    + " left join fetch tc.parentConcept.kingdomConcept left join fetch tc.parentConcept.kingdomConcept.taxonNameLite"
                    + " left join fetch tc.parentConcept.phylumConcept left join fetch tc.parentConcept.phylumConcept.taxonNameLite"
                    + " left join fetch tc.parentConcept.orderConcept left join fetch tc.parentConcept.orderConcept.taxonNameLite"
                    + " left join fetch tc.parentConcept.classConcept left join fetch tc.parentConcept.classConcept.taxonNameLite"
                    + " left join fetch tc.parentConcept.familyConcept left join fetch tc.parentConcept.familyConcept.taxonNameLite"
                    + " left join fetch tc.parentConcept.genusConcept left join fetch tc.parentConcept.genusConcept.taxonNameLite"
                    + " left join fetch tc.parentConcept.speciesConcept left join fetch tc.parentConcept.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#getTaxonConceptCount(java.lang.Long, java.lang.Long)
 *//*from  w  w  w.j  a v  a2 s.c  o  m*/
public int getTaxonConceptCount(final Long dataProviderId, final Long dataResourceId) {
    Object result = getHibernateTemplate().execute(new HibernateCallback() {

        public Object doInHibernate(Session session) {
            StringBuffer sb = new StringBuffer("Select count(tc.id) from TaxonConcept tc");
            if (dataProviderId != null || dataResourceId != null)
                sb.append(" where");
            if (dataProviderId != null)
                sb.append(" and tc.dataProvider.id = :dataProviderId");
            if (dataResourceId != null)
                sb.append(" and tc.dataResource.id = :dataResourceId");
            // set the query object
            Query query = session.createQuery(sb.toString());
            if (dataProviderId != null)
                query.setParameter("dataProviderId", dataProviderId);
            if (dataResourceId != null)
                query.setParameter("dataResourceId", dataResourceId);

            query.setCacheable(true);
            return query.uniqueResult();
        }
    });
    if (result instanceof Integer)
        return ((Integer) result).intValue();
    if (result instanceof Long)
        return ((Long) result).intValue();
    return 0;
}

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

License:Open Source License

/**
 * Uses a Hibernate Criteria object to assemble and execute query.
 * /*www .j a  va 2  s  .c  o m*/
 * @see org.gbif.portal.dao.taxonomy.TaxonConceptDAO#getTaxonConceptCount(java.lang.String, boolean, java.lang.Long)
 */
public int getTaxonConceptCount(final String nameStub, final boolean fuzzy, final Long dataProviderId,
        final Long dataResourceId) {
    Object result = getHibernateTemplate().execute(new HibernateCallback() {

        public Object doInHibernate(Session session) {
            String searchString = null;
            if (fuzzy)
                searchString = nameStub + '%';
            else
                searchString = nameStub;

            StringBuffer sb = new StringBuffer("Select count(tc.id) from TaxonConcept tc");
            sb.append(" inner join tc.taxonName");
            sb.append(" where tc.taxonName.canonical like :searchString");
            if (dataProviderId != null)
                sb.append(" and tc.dataProvider.id = :dataProviderId");
            if (dataResourceId != null)
                sb.append(" and tc.dataResource.id = :dataResourceId");
            // set the query object
            Query query = session.createQuery(sb.toString());
            query.setParameter("searchString", searchString);
            if (dataProviderId != null)
                query.setParameter("dataProviderId", dataProviderId);
            if (dataResourceId != null)
                query.setParameter("dataResourceId", dataResourceId);

            query.setCacheable(true);
            return query.uniqueResult();
        }
    });
    if (result instanceof Integer)
        return ((Integer) result).intValue();
    if (result instanceof Long)
        return ((Long) result).intValue();
    return 0;
}

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

License:Open Source License

/**
 * @see org.gbif.portal.dao.taxonomy.TaxonConceptDAO#getTaxonConceptCountForRank(org.gbif.portal.model.taxonomy.TaxonRank,
 *      java.lang.Boolean, java.lang.Long)
 *///  w w w . j  a  v  a 2  s .c  o  m
public int getTaxonConceptCountForRank(final TaxonRank taxonRank, final Boolean higherThanSuppliedRank,
        final Long dataProviderId, final Long dataResourceId) {
    Object result = getHibernateTemplate().execute(new HibernateCallback() {

        public Object doInHibernate(Session session) {
            StringBuffer sb = new StringBuffer("Select count(tc.id) from TaxonConcept tc");
            sb.append(" where tc.isAccepted=true and tc.taxonRank ");
            if (taxonRank != TaxonRank.UNKNOWN) {
                if (higherThanSuppliedRank == null) {
                    sb.append("=");
                } else if (higherThanSuppliedRank.booleanValue()) {
                    sb.append(">");
                } else {
                    sb.append("<");
                }
                sb.append(" :taxonRank");
            }
            if (dataProviderId != null)
                sb.append(" and tc.dataProvider.id = :dataProviderId");
            if (dataResourceId != null)
                sb.append(" and tc.dataResource.id = :dataResourceId");
            // set the query object
            Query query = session.createQuery(sb.toString());
            query.setParameter("taxonRank", taxonRank);
            if (dataProviderId != null)
                query.setParameter("dataProviderId", dataProviderId);
            if (dataResourceId != null)
                query.setParameter("dataResourceId", dataResourceId);
            query.setCacheable(true);
            return query.uniqueResult();
        }
    });
    if (result instanceof Integer)
        return ((Integer) result).intValue();
    if (result instanceof Long)
        return ((Long) result).intValue();
    return 0;
}

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

License:Open Source License

/**
 * @see org.gbif.portal.dao.taxonomy.TaxonConceptDAO#getTaxonConcept(long)
 */// ww  w .  j  av  a  2s. c  o  m
public TaxonConcept getTaxonConceptFor(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.dataResource" + " left join fetch tc.dataProvider"
                    + " left join fetch tc.parentConcept" + " 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#getTaxonConceptForRemoteId(java.lang.Long, java.lang.Long,
 *      java.lang.String)//w  ww.  j a  v a2  s. c  om
 */
public TaxonConcept getTaxonConceptForRemoteId(final Long dataProviderId, final Long dataResourceId,
        final String remoteId) {
    HibernateTemplate template = getHibernateTemplate();
    return (TaxonConcept) template.execute(new HibernateCallback() {

        public Object doInHibernate(Session session) {
            StringBuffer sb = new StringBuffer(
                    "select rc.taxonConcept from RemoteConcept rc" + " inner join rc.taxonConcept tc "
                            + " left join fetch tc.dataResource" + " left join fetch tc.dataProvider"
                            + " left join fetch tc.parentConcept" + " where rc.remoteId = :remoteId");
            if (dataProviderId != null)
                sb.append(" and tc.dataProviderId = :dataProviderId");
            if (dataResourceId != null)
                sb.append(" and tc.dataResourceId = :dataResourceId");

            Query query = session.createQuery(sb.toString());
            query.setParameter("remoteId", remoteId);
            if (dataProviderId != null)
                query.setParameter("dataProviderId", dataProviderId);
            if (dataResourceId != null)
                query.setParameter("dataResourceId", dataResourceId);
            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#getTaxonConceptForRemoteId(long)
 *//*from   w w w .  ja v a2 s  . co  m*/
@SuppressWarnings("unchecked")
public List<TaxonConcept> getTaxonConceptForRemoteId(final String remoteId) {
    HibernateTemplate template = getHibernateTemplate();
    return (List<TaxonConcept>) template.execute(new HibernateCallback() {

        public Object doInHibernate(Session session) {
            Query query = session.createQuery("from TaxonConcept tc" + " inner join fetch tc.taxonName"
                    + " inner join fetch tc.remoteConcepts as remoteConcept"
                    + " left join fetch tc.dataResource" + " left join fetch tc.dataProvider"
                    + " left join fetch tc.parentConcept"
                    + " 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"
                    + " where remoteConcept.remoteId = ?");
            query.setParameter(0, remoteId);
            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#getTaxonConceptIdsForNubTaxonConcept(long)
 *//*from w w  w  .jav  a  2  s  .c  om*/
@SuppressWarnings("unchecked")
public List<Long> getTaxonConceptIdsForNubTaxonConcept(final long nubConceptId) {
    if (logger.isDebugEnabled())
        logger.debug("Retrieving taxon concept ids for nub concept:" + nubConceptId);
    HibernateTemplate template = getHibernateTemplate();
    return (List<Long>) template.execute(new HibernateCallback() {

        public Object doInHibernate(Session session) {
            Query query = session.createQuery("select tc.id from TaxonConcept tc"
                    + " where tc.partnerConceptId = :partnerConceptId" + " and tc.isNubConcept = false");
            query.setParameter("partnerConceptId", nubConceptId);
            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#getTaxonConceptLiteFor(java.lang.Long)
 *///w w  w.  j  a  v a  2  s. c  om
public TaxonConceptLite getTaxonConceptLiteFor(final long taxonConceptId) {
    HibernateTemplate template = getHibernateTemplate();
    return (TaxonConceptLite) template.execute(new HibernateCallback() {

        public Object doInHibernate(Session session) {
            Query query = session.createQuery(
                    "from TaxonConceptLite tc" + " inner join fetch tc.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#getTaxonConceptsForNubTaxonConcept(long)
 *///from  w  w w. java  2  s .c om
@SuppressWarnings("unchecked")
public List<TaxonConcept> getTaxonConceptsForNubTaxonConcept(final long nubConceptId) {
    if (logger.isDebugEnabled())
        logger.debug("Retrieving taxon concepts for nub concept:" + nubConceptId);
    HibernateTemplate template = getHibernateTemplate();
    return (List<TaxonConcept>) template.execute(new HibernateCallback() {

        public Object doInHibernate(Session session) {
            Query query = session.createQuery("from TaxonConcept tc" + " inner join fetch tc.taxonName"
                    + " where tc.partnerConceptId = :partnerConceptId" + " and tc.isNubConcept = false"
                    + " order by tc.taxonRank asc, tc.taxonName.canonical");
            query.setParameter("partnerConceptId", nubConceptId);
            query.setCacheable(true);
            return query.list();
        }
    });
}