List of usage examples for org.hibernate Query setCacheable
Query<R> setCacheable(boolean cacheable);
From source file:org.gbif.portal.dao.resources.impl.hibernate.DataResourceDAOImpl.java
License:Open Source License
/** * @see org.gbif.portal.dao.resources.DataResourceDAO#getDataResourceCountsForCountry(java.lang.Long) */// w w w . j ava 2 s .c om @SuppressWarnings("unchecked") public List<Object[]> getDataResourceCountsForCountry(final String isoCountryCode, final boolean geoRefOnly) { HibernateTemplate template = getHibernateTemplate(); return (List) template.execute(new HibernateCallback() { public Object doInHibernate(Session session) { StringBuffer sb = new StringBuffer("select dr.id, dr.display_name as dr_name, dp.name as dp_name,"); if (geoRefOnly) { sb.append(" rc.occurrence_coordinate_count "); } else { sb.append(" rc.count "); } sb.append("from resource_country rc" + " inner join data_resource dr on rc.data_resource_id=dr.id" + " inner join data_provider dp on dr.data_provider_id=dp.id" + " where "); if (isoCountryCode != null) { sb.append("rc.iso_country_code=:isoCountryCode and "); } sb.append("dr.deleted is null"); if (geoRefOnly) { sb.append(" and rc.occurrence_coordinate_count>0"); } sb.append(" order by dr_name"); Query query = session.createSQLQuery(sb.toString()); if (isoCountryCode != null) query.setParameter("isoCountryCode", isoCountryCode); query.setCacheable(true); return query.list(); } }); }
From source file:org.gbif.portal.dao.resources.impl.hibernate.DataResourceDAOImpl.java
License:Open Source License
/** * @see org.gbif.portal.dao.resources.DataResourceDAO#getDataResourceFor(long) *//*from w w w . ja va 2s .c o m*/ public DataResource getDataResourceFor(final long dataResourceId) { HibernateTemplate template = getHibernateTemplate(); return (DataResource) template.execute(new HibernateCallback() { public Object doInHibernate(Session session) { Query query = session .createQuery("from DataResource dr left join fetch dr.dataProvider where dr.id = ?"); query.setParameter(0, dataResourceId); query.setCacheable(true); return query.uniqueResult(); } }); }
From source file:org.gbif.portal.dao.resources.impl.hibernate.DataResourceDAOImpl.java
License:Open Source License
/** * @see org.gbif.portal.dao.resources.DataResourceDAO#getDataResourceList(java.lang.Long) *//*from w w w. j a v a 2s .co m*/ @SuppressWarnings("unchecked") public List getDataResourceList(final Long dataProviderId) { HibernateTemplate template = getHibernateTemplate(); return (List) template.execute(new HibernateCallback() { public Object doInHibernate(Session session) { Query query = session.createQuery( "select dr.id, dr.name from DataResource dr where dr.dataProvider.id = ? and dr.deleted is null order by dr.name"); query.setParameter(0, dataProviderId); query.setCacheable(true); return query.list(); } }); }
From source file:org.gbif.portal.dao.resources.impl.hibernate.DataResourceDAOImpl.java
License:Open Source License
/** * @see org.gbif.portal.dao.resources.DataResourceDAO#getDataResourceForProvider(java.lang.Long) *//*w w w . j a v a2 s. c o m*/ @SuppressWarnings("unchecked") public List<DataResource> getDataResourcesForProvider(final long dataProviderId) { HibernateTemplate template = getHibernateTemplate(); return (List<DataResource>) template.execute(new HibernateCallback() { public Object doInHibernate(Session session) { Query query = session.createQuery( "from DataResource dr inner join fetch dr.dataProvider dp where dp.id = ? and dr.deleted is null order by dr.name"); query.setParameter(0, dataProviderId); query.setCacheable(true); return query.list(); } }); }
From source file:org.gbif.portal.dao.resources.impl.hibernate.DataResourceDAOImpl.java
License:Open Source License
/** * @see org.gbif.portal.dao.resources.DataResourceDAO#getDataResourcesForResourceNetwork(long) *///from w ww .jav a 2s. c om @SuppressWarnings("unchecked") public List<DataResource> getDataResourcesForResourceNetwork(final long resourceNetworkId) { HibernateTemplate template = getHibernateTemplate(); return (List<DataResource>) template.execute(new HibernateCallback() { public Object doInHibernate(Session session) { Query query = session.createQuery("select nm.dataResource from NetworkMembership nm" + " join nm.resourceNetwork rn" + " left join fetch nm.dataResource.dataProvider" + " where rn.id = ? and nm.dataResource.deleted is null" + " order by nm.dataResource.name"); query.setParameter(0, resourceNetworkId); query.setCacheable(true); return query.list(); } }); }
From source file:org.gbif.portal.dao.resources.impl.hibernate.DataResourceDAOImpl.java
License:Open Source License
/** * @see org.gbif.portal.dao.resources.DataResourceDAO#getDataResourcesWithNonSharedTaxonomies() *//*from w ww .j a v a 2 s . c om*/ @SuppressWarnings("unchecked") public List<DataResource> getDataResourcesWithNonSharedTaxonomies() { HibernateTemplate template = getHibernateTemplate(); return (List<DataResource>) template.execute(new HibernateCallback() { public Object doInHibernate(Session session) { Query query = session.createQuery("from DataResource dr inner join fetch dr.dataProvider" + " where dr.sharedTaxonomy=false and dr.conceptCount>0" + " and dr.deleted is null" + " order by dr.name"); query.setCacheable(true); return query.list(); } }); }
From source file:org.gbif.portal.dao.resources.impl.hibernate.DataResourceDAOImpl.java
License:Open Source License
/** * TODO This may need refactoring to use a join table similar to resource_country or taxon_country * /* w w w. j av a 2s .co m*/ * @see org.gbif.portal.dao.resources.DataResourceDAO#getDataResourceWithOccurrencesFor(java.lang.Long, * java.lang.String, boolean) */ @SuppressWarnings("unchecked") public List<Object[]> getDataResourceWithOccurrencesFor(final Long taxonConceptId, final String rank, final boolean georeferenced) { HibernateTemplate template = getHibernateTemplate(); return (List) template.execute(new HibernateCallback() { public Object doInHibernate(Session session) { StringBuffer sb = new StringBuffer( "select oc.dataResource.id, oc.dataResource.name, oc.dataProvider.name, count(oc.id) " + "from OccurrenceRecord oc where oc."); if (TaxonRankType.isRecognisedMajorRank(rank)) { sb.append(rank); sb.append("ConceptId=:taxonConceptId"); } else { sb.append("nubTaxonConceptId=:taxonConceptId"); } if (georeferenced) { sb.append(" and oc.cellId is not null and oc.geospatialIssue=0"); } sb.append(" group by oc.dataResourceId"); Query query = session.createQuery(sb.toString()); query.setParameter("taxonConceptId", taxonConceptId); query.setCacheable(true); return query.list(); } }); }
From source file:org.gbif.portal.dao.resources.impl.hibernate.DataResourceDAOImpl.java
License:Open Source License
/** * @see org.gbif.portal.dao.resources.DataResourceDAO#getLastDataResourceAdded() *///w w w . j a va2 s. co m public DataResource getLastDataResourceAdded() { HibernateTemplate template = getHibernateTemplate(); return (DataResource) template.execute(new HibernateCallback() { public Object doInHibernate(Session session) { Query query = session.createQuery( "from DataResource dr left join fetch dr.dataProvider where dr.deleted is null order by dr.created desc"); query.setMaxResults(1); query.setCacheable(true); return query.uniqueResult(); } }); }
From source file:org.gbif.portal.dao.resources.impl.hibernate.PropertyStoreNamespaceDAOImpl.java
License:Open Source License
@SuppressWarnings("unchecked") public List<PropertyStoreNamespace> getPropertyStoreNamespacesForResourceAccessPoint( final long resourceAccessPointId) { HibernateTemplate template = getHibernateTemplate(); return (List<PropertyStoreNamespace>) template.execute(new HibernateCallback() { public Object doInHibernate(Session session) { Query query = session.createQuery( "select rap.propertyStoreNamespaces from ResourceAccessPoint rap" + " where rap.id = ?"); query.setParameter(0, resourceAccessPointId); query.setCacheable(true); return query.list(); }/* w w w . j av a 2s . com*/ }); }
From source file:org.gbif.portal.dao.resources.impl.hibernate.ResourceAccessPointDAOImpl.java
License:Open Source License
/** * @see org.gbif.portal.dao.resources.ResourceAccessPointDAO#getResourceAccessPointsForDataResource(long) *//* w w w . j a va2 s . com*/ @SuppressWarnings("unchecked") public List<ResourceAccessPoint> getResourceAccessPointsForDataResource(final long dataResourceId) { HibernateTemplate template = getHibernateTemplate(); return (List<ResourceAccessPoint>) template.execute(new HibernateCallback() { public Object doInHibernate(Session session) { Query query = session.createQuery("from ResourceAccessPoint rap" + " where rap.dataResource.id = ? " + " and rap.deleted is null"); query.setParameter(0, dataResourceId); query.setCacheable(true); return query.list(); } }); }