List of usage examples for org.hibernate Query setCacheable
Query<R> setCacheable(boolean cacheable);
From source file:org.gbif.portal.dao.occurrence.impl.hibernate.OccurrenceRecordDAOImpl.java
License:Open Source License
/** * @see org.gbif.portal.dao.occurrence.OccurrenceRecordDAO#getTotalSpeciesCount() *///from w w w .j a va 2s . c om public int getTotalSpeciesCount() { HibernateTemplate template = getHibernateTemplate(); Object count = template.execute(new HibernateCallback() { public Object doInHibernate(Session session) { Query query = null; query = session.createQuery( "select count(distinct oc.speciesConceptId) from OccurrenceRecord oc where oc.deleted is null"); query.setCacheable(true); return query.uniqueResult(); } }); if (count instanceof Integer) return ((Integer) count).intValue(); if (count instanceof Long) return ((Long) count).intValue(); return 0; }
From source file:org.gbif.portal.dao.occurrence.impl.hibernate.OccurrenceRecordDAOImpl.java
License:Open Source License
/** * @see org.gbif.portal.dao.occurrence.OccurrenceRecordDAO#getTotalGeoreferencedOccurrenceRecordCount() */// w w w .ja v a 2s .com public int getTotalGeoreferencedOccurrenceRecordCount() { HibernateTemplate template = getHibernateTemplate(); Object count = template.execute(new HibernateCallback() { public Object doInHibernate(Session session) { Query query = null; query = session.createQuery( "select sum(dp.occurrenceCoordinateCount) from DataProvider dp where dp.deleted is null"); query.setCacheable(true); return query.uniqueResult(); } }); if (count instanceof Integer) return ((Integer) count).intValue(); if (count instanceof Long) return ((Long) count).intValue(); return 0; }
From source file:org.gbif.portal.dao.occurrence.impl.hibernate.RawOccurrenceRecordDAOImpl.java
License:Open Source License
/** * @see org.gbif.portal.dao.occurrence.OccurrenceRecordDAO#getRawOccurrenceRecordFor(long) *///from w w w.j av a2s . c o m public RawOccurrenceRecord getRawOccurrenceRecordFor(final long rawOccurrenceRecordId) { HibernateTemplate template = getHibernateTemplate(); return (RawOccurrenceRecord) template.execute(new HibernateCallback() { public Object doInHibernate(Session session) { Query query = session.createQuery("from RawOccurrenceRecord ror " + "where ror.id = ?"); query.setParameter(0, rawOccurrenceRecordId); query.setCacheable(true); return query.uniqueResult(); } }); }
From source file:org.gbif.portal.dao.occurrence.impl.hibernate.RawOccurrenceRecordDAOImpl.java
License:Open Source License
/** * @see org.gbif.portal.dao.occurrence.OccurrenceRecordDAO#getRawOccurrenceRecordFor(long) *//* www . j av a2s. c o m*/ @SuppressWarnings("unchecked") public List<RawOccurrenceRecord> findRawOccurrenceRecord(final long dataResourceId, final String catalogueNumber, final int startIndex, final int maxResults) { HibernateTemplate template = getHibernateTemplate(); return (List<RawOccurrenceRecord>) template.execute(new HibernateCallback() { public Object doInHibernate(Session session) { StringBuffer sb = new StringBuffer( "from RawOccurrenceRecord ror where ror.dataResourceId = :dataResourceId "); if (StringUtils.isNotEmpty(catalogueNumber)) { sb.append("and ror.catalogueNumber = :catalogueNumber"); } Query query = session.createQuery(sb.toString()); query.setParameter("dataResourceId", dataResourceId); if (StringUtils.isNotEmpty(catalogueNumber)) { query.setParameter("catalogueNumber", catalogueNumber); } query.setCacheable(true); query.setFirstResult(startIndex); query.setMaxResults(maxResults); return query.list(); } }); }
From source file:org.gbif.portal.dao.occurrence.impl.hibernate.TypificationRecordDAOImpl.java
License:Open Source License
/** * @see org.gbif.portal.dao.occurrence.TypificationRecordDAO#getTypificationRecordsForOccurrenceRecord(long) *//* w w w . jav a 2s. com*/ @SuppressWarnings("unchecked") public List<TypificationRecord> getTypificationRecordsForOccurrenceRecord(final long occurrenceRecordId) { HibernateTemplate template = getHibernateTemplate(); return (List<TypificationRecord>) template.execute(new HibernateCallback() { public Object doInHibernate(Session session) { Query query = session .createQuery("from TypificationRecord tr" + " where tr.occurrenceRecordId = ?"); query.setParameter(0, occurrenceRecordId); query.setCacheable(true); return query.list(); } }); }
From source file:org.gbif.portal.dao.occurrence.impl.hibernate.TypificationRecordDAOImpl.java
License:Open Source License
/** * @see org.gbif.portal.dao.occurrence.TypificationRecordDAO#getTypeStatusForOccurrenceRecords(java.util.List) *//* w w w. j a v a 2s . c om*/ @SuppressWarnings("unchecked") public List<TypeStatus> getTypeStatusForOccurrenceRecords(final List<Long> occurrenceRecordIds) { HibernateTemplate template = getHibernateTemplate(); return (List<TypeStatus>) template.execute(new HibernateCallback() { public Object doInHibernate(Session session) { Query query = session.createQuery( "from TypeStatus ts" + " where ts.occurrenceRecordId in (:occurrenceRecordIds)"); query.setParameterList("occurrenceRecordIds", occurrenceRecordIds); query.setCacheable(true); return query.list(); } }); }
From source file:org.gbif.portal.dao.occurrence.impl.hibernate.TypificationRecordDAOImpl.java
License:Open Source License
/** * @see org.gbif.portal.dao.occurrence.TypificationRecordDAO#getTypificationRecordsForTaxonName(long) *///w w w. j av a 2 s .c o m @SuppressWarnings("unchecked") public List<TypificationRecord> getTypificationRecordsForTaxonName(final long taxonNameId) { HibernateTemplate template = getHibernateTemplate(); return (List<TypificationRecord>) template.execute(new HibernateCallback() { public Object doInHibernate(Session session) { Query query = session.createQuery("from TypificationRecord tr" + " where tr.taxonNameId = ?"); query.setParameter(0, taxonNameId); query.setCacheable(true); return query.list(); } }); }
From source file:org.gbif.portal.dao.occurrence.impl.hibernate.TypificationRecordDAOImpl.java
License:Open Source License
/** * @see org.gbif.portal.dao.occurrence.TypificationRecordDAO#getTypificationRecordsForTaxonName(long) *///from ww w.j a va 2s . c om @SuppressWarnings("unchecked") public List<TypificationRecord> getTypificationRecordsForNamesOfPartnersOfTaxonConcept( final long taxonConceptId) { HibernateTemplate template = getHibernateTemplate(); final List<Long> taxonNameIds = (List<Long>) template.execute(new HibernateCallback() { public Object doInHibernate(Session session) { Query query = session.createQuery( "select distinct tc.taxonName.id from TaxonConcept tc where tc.partnerConceptId=:taxonConceptId"); query.setParameter("taxonConceptId", taxonConceptId); return query.list(); } }); if (taxonNameIds.size() > 0) { return (List<TypificationRecord>) template.execute(new HibernateCallback() { public Object doInHibernate(Session session) { Query query = session.createQuery( "from TypificationRecord tr inner join fetch tr.occurrenceRecord inner join fetch tr.dataResource where tr.taxonNameId in(:ids)"); query.setParameterList("ids", taxonNameIds); query.setCacheable(true); return query.list(); } }); } else { return new LinkedList<TypificationRecord>(); } }
From source file:org.gbif.portal.dao.occurrence.impl.hibernate.TypificationRecordDAOImpl.java
License:Open Source License
/** * /*from w w w . j av a2 s .co m*/ */ @SuppressWarnings("unchecked") public List<TypificationRecord> getTypificationRecordsForTaxonConcept(final long taxonConceptId) { HibernateTemplate template = getHibernateTemplate(); return (List<TypificationRecord>) template.execute(new HibernateCallback() { public Object doInHibernate(Session session) { String query = "from TypificationRecord tr " + "inner join fetch tr.occurrenceRecord inner join fetch tr.dataResource " + "where tr.occurrenceRecord.nubTaxonConceptId=? or tr.occurrenceRecord.taxonConceptId=?"; Query q = session.createQuery(query); q.setParameter(0, taxonConceptId); q.setParameter(1, taxonConceptId); q.setCacheable(true); q.setMaxResults(100); return q.list(); } }); }
From source file:org.gbif.portal.dao.registry.impl.hibernate.RegistrationLoginDAOImpl.java
License:Open Source License
/** * @see org.gbif.portal.dao.resources.AgentDAO#getBusinessKeysFor(long) *//* www . j av a 2s. com*/ @SuppressWarnings("unchecked") public List<String> getBusinessKeysFor(final String loginId) { HibernateTemplate template = getHibernateTemplate(); return (List<String>) template.execute(new HibernateCallback() { public Object doInHibernate(Session session) { Query query = session .createQuery("select rl.businessKey from RegistrationLogin rl" + " where rl.loginId = ?"); query.setParameter(0, loginId); query.setCacheable(true); return query.list(); } }); }