List of usage examples for org.hibernate Query setCacheable
Query<R> setCacheable(boolean cacheable);
From source file:org.gbif.portal.dao.occurrence.impl.hibernate.IdentifierRecordDAOImpl.java
License:Open Source License
/** * @see org.gbif.portal.dao.occurrence.IdentifierRecordDAO#getIdentifierRecordsForOccurrenceRecords(java.util.List) *//*from w ww . ja v a 2s .c o m*/ @SuppressWarnings("unchecked") public List<IdentifierRecord> getIdentifierRecordsForOccurrenceRecords(final List<Long> occurrenceRecordIds) { HibernateTemplate template = getHibernateTemplate(); return (List<IdentifierRecord>) template.execute(new HibernateCallback() { public Object doInHibernate(Session session) { Query query = session.createQuery( "from IdentifierRecord ir" + " where ir.occurrenceRecordId in (:occurrenceRecordIds)"); query.setParameterList("occurrenceRecordIds", occurrenceRecordIds); query.setCacheable(true); return query.list(); } }); }
From source file:org.gbif.portal.dao.occurrence.impl.hibernate.ImageRecordDAOImpl.java
License:Open Source License
/** * @see org.gbif.portal.dao.occurrence.ImageRecordDAO#getImageRecordsForOccurrenceRecord(long) *///from w w w .j a v a 2 s. com @SuppressWarnings("unchecked") public List<ImageRecord> getImageRecordsForOccurrenceRecord(final long occurrenceRecordId) { HibernateTemplate template = getHibernateTemplate(); return (List<ImageRecord>) template.execute(new HibernateCallback() { public Object doInHibernate(Session session) { Query query = session.createQuery("from ImageRecord ir where ir.occurrenceRecordId = ?"); query.setParameter(0, occurrenceRecordId); query.setCacheable(true); return query.list(); } }); }
From source file:org.gbif.portal.dao.occurrence.impl.hibernate.ImageRecordDAOImpl.java
License:Open Source License
/** * @see org.gbif.portal.dao.occurrence.ImageRecordDAO#getImageRecordsForOccurrenceRecords(java.util.List) */// www.j a v a2 s .c o m @SuppressWarnings("unchecked") public List<ORImage> getImageRecordsForOccurrenceRecords(final List<Long> occurrenceRecordIds) { HibernateTemplate template = getHibernateTemplate(); return (List<ORImage>) template.execute(new HibernateCallback() { public Object doInHibernate(Session session) { Query query = session .createQuery("from ORImage oir where oir.occurrenceRecordId in (:occurrenceRecordIds)"); query.setParameterList("occurrenceRecordIds", occurrenceRecordIds); query.setCacheable(true); return query.list(); } }); }
From source file:org.gbif.portal.dao.occurrence.impl.hibernate.ImageRecordDAOImpl.java
License:Open Source License
/** * @see org.gbif.portal.dao.occurrence.ImageRecordDAO#getImageRecordsForTaxonConcept(long) */// w w w .jav a 2 s . c o m @SuppressWarnings("unchecked") public List<ImageRecord> getImageRecordsForTaxonConcept(final long taxonConceptId) { HibernateTemplate template = getHibernateTemplate(); return (List<ImageRecord>) template.execute(new HibernateCallback() { public Object doInHibernate(Session session) { Query query = session.createQuery("from ImageRecord ir" + " left join fetch ir.dataResource dr " + " left outer join dr.resourceRanks rr " + " where ir.taxonConceptId = :taxonConceptId" + // " and ir.imageTypeValue >= :imageTypeThreshold" + " or ir.taxonConceptLite.partnerConceptId = :taxonConceptId" + " and (rr.resourceType = :resourceType or rr.resourceType is null)" + " order by rr.rank desc"); query.setParameter("taxonConceptId", taxonConceptId); query.setParameter("resourceType", ResourceType.IMAGE_DATA_RESOURCE); // query.setParameter("imageTypeThreshold", imageTypeThreshold); query.setCacheable(true); return query.list(); } }); }
From source file:org.gbif.portal.dao.occurrence.impl.hibernate.LinkRecordDAOImpl.java
License:Open Source License
@SuppressWarnings("unchecked") public List<LinkRecord> getLinkRecordsForOccurrenceRecord(final long occurrenceRecordId) { HibernateTemplate template = getHibernateTemplate(); return (List<LinkRecord>) template.execute(new HibernateCallback() { public Object doInHibernate(Session session) { Query query = session.createQuery("from LinkRecord lr" + " where lr.occurrenceRecordId = ?"); query.setParameter(0, occurrenceRecordId); query.setCacheable(true); return query.list(); }/*from w w w.java 2 s .co m*/ }); }
From source file:org.gbif.portal.dao.occurrence.impl.hibernate.LinkRecordDAOImpl.java
License:Open Source License
@SuppressWarnings("unchecked") public List<LinkRecord> getLinkRecordsForTaxonConcept(final long taxonConceptId) { HibernateTemplate template = getHibernateTemplate(); return (List<LinkRecord>) template.execute(new HibernateCallback() { public Object doInHibernate(Session session) { Query query = session.createQuery("from LinkRecord lr" + " where lr.taxonConceptId = ?"); query.setParameter(0, taxonConceptId); query.setCacheable(true); return query.list(); }//from w w w. j a v a2 s .c o m }); }
From source file:org.gbif.portal.dao.occurrence.impl.hibernate.OccurrenceRecordDAOImpl.java
License:Open Source License
/** * @see org.gbif.portal.dao.occurrence.OccurrenceRecordDAO#getOccurrenceRecordFor(long) *//* w ww .j a va2 s . co m*/ public OccurrenceRecord getOccurrenceRecordFor(final long occurrenceRecordId) { HibernateTemplate template = getHibernateTemplate(); return (OccurrenceRecord) template.execute(new HibernateCallback() { public Object doInHibernate(Session session) { Query query = session.createQuery("from OccurrenceRecord oc" + " inner join fetch oc.dataProvider" + " inner join fetch oc.dataResource" + " inner join fetch oc.taxonConcept" + " inner join fetch oc.taxonName" + " where oc.id = ?"); query.setParameter(0, occurrenceRecordId); query.setCacheable(true); return query.uniqueResult(); } }); }
From source file:org.gbif.portal.dao.occurrence.impl.hibernate.OccurrenceRecordDAOImpl.java
License:Open Source License
/** * @see org.gbif.portal.dao.occurrence.OccurrenceRecordDAO#getOccurrenceRecordFor(java.lang.String, java.lang.String, java.lang.String) *///from ww w . j a va2 s . c o m @SuppressWarnings("unchecked") public List<OccurrenceRecord> getOccurrenceRecordFor(final String institutionCode, final String collectionCode, final String catalogueNumber) { HibernateTemplate template = getHibernateTemplate(); return (List<OccurrenceRecord>) template.execute(new HibernateCallback() { public Object doInHibernate(Session session) { Query query = session.createQuery("from OccurrenceRecord oc" + " inner join fetch oc.dataProvider" + " inner join fetch oc.dataResource" + " inner join fetch oc.taxonConcept" + " inner join fetch oc.taxonName" + " where oc.catalogueNumber.code = :catalogueNumber" + " and oc.collectionCode.code = :collectionCode" + " and oc.institutionCode.code = :institutionCode"); query.setParameter("catalogueNumber", catalogueNumber); query.setParameter("collectionCode", collectionCode); query.setParameter("institutionCode", institutionCode); query.setCacheable(true); return query.list(); } }); }
From source file:org.gbif.portal.dao.occurrence.impl.hibernate.OccurrenceRecordDAOImpl.java
License:Open Source License
/** * @see org.gbif.portal.dao.occurrence.OccurrenceRecordDAO#getTotalOccurrenceRecordCountForDeletedProviders() */// w w w. ja va2 s .c o m public int getTotalOccurrenceRecordCountForDeletedProviders() { HibernateTemplate template = getHibernateTemplate(); Object count = template.execute(new HibernateCallback() { public Object doInHibernate(Session session) { Query query = session.createQuery( "select count(*) from OccurrenceRecord oc where oc.dataProvider.deleted is not 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#getTotalOccurrenceRecordCount() *///from w w w . ja v a2s.co m public int getTotalOccurrenceRecordCount() { HibernateTemplate template = getHibernateTemplate(); Object count = template.execute(new HibernateCallback() { public Object doInHibernate(Session session) { Query query = null; if (useCount) query = session .createQuery("select count(oc.id) from OccurrenceRecord oc where oc.deleted is null"); else query = session .createQuery("select max(oc.id) 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; }