List of usage examples for org.hibernate Query setCacheable
Query<R> setCacheable(boolean cacheable);
From source file:org.gbif.portal.dao.resources.impl.hibernate.AgentDAOImpl.java
License:Open Source License
/** * @see org.gbif.portal.dao.resources.AgentDAO#getAgentsForDataProvider(long) *///from w ww .j a va 2s . c om @SuppressWarnings("unchecked") public List<DataProviderAgent> getAgentsForDataProvider(final long dataProviderId) { HibernateTemplate template = getHibernateTemplate(); return (List<DataProviderAgent>) template.execute(new HibernateCallback() { public Object doInHibernate(Session session) { Query query = session.createQuery("from DataProviderAgent pa" + " where pa.dataProvider.id = ?"); query.setParameter(0, dataProviderId); query.setCacheable(true); return query.list(); } }); }
From source file:org.gbif.portal.dao.resources.impl.hibernate.AgentDAOImpl.java
License:Open Source License
/** * @see org.gbif.portal.dao.resources.AgentDAO#getAgentsForDataResource(long) */// www .jav a2s. c om @SuppressWarnings("unchecked") public List<DataResourceAgent> getAgentsForDataResource(final long dataResourceId) { HibernateTemplate template = getHibernateTemplate(); return (List<DataResourceAgent>) template.execute(new HibernateCallback() { public Object doInHibernate(Session session) { Query query = session.createQuery("from DataResourceAgent ra" + " where ra.dataResource.id = ?"); query.setParameter(0, dataResourceId); query.setCacheable(true); return query.list(); } }); }
From source file:org.gbif.portal.dao.resources.impl.hibernate.AgentDAOImpl.java
License:Open Source License
/** * @see org.gbif.portal.dao.resources.AgentDAO#getAgentsForEmailAddress(java.lang.String) */// ww w . j a v a2s. c o m @SuppressWarnings("unchecked") public List getAgentsForEmailAddress(final String email) { HibernateTemplate template = getHibernateTemplate(); return (List<DataResourceAgent>) template.execute(new HibernateCallback() { public Object doInHibernate(Session session) { Query query = session.createQuery("from Agent a" + " where a.email like ?"); query.setParameter(0, email); query.setCacheable(true); return query.list(); } }); }
From source file:org.gbif.portal.dao.resources.impl.hibernate.DataProviderDAOImpl.java
License:Open Source License
/** * @see org.gbif.portal.dao.resources.DataProviderDAO#getDataProviderFor(long) *//*from w ww.j a va2s.com*/ @SuppressWarnings("unchecked") public List<DataProvider> getDataProviderAssociatedWithUser(final String emailUsername, final String emailDomain) { HibernateTemplate template = getHibernateTemplate(); return (List<DataProvider>) template.execute(new HibernateCallback() { public Object doInHibernate(Session session) { Query query = session.createQuery("select distinct dp from DataProvider dp " + "inner join dp.dataProviderAgents agents " + "inner join agents.agent ag " + "where ag.email like :emailUsername and ag.email like :emailDomain"); query.setParameter("emailUsername", emailUsername); query.setParameter("emailDomain", emailDomain); query.setCacheable(true); return query.list(); } }); }
From source file:org.gbif.portal.dao.resources.impl.hibernate.DataProviderDAOImpl.java
License:Open Source License
/** * @see org.gbif.portal.dao.resources.DataResourceDAO#getDataResourceCountsForCountry(java.lang.Long) *//*from w ww . ja va 2 s . c o m*/ @SuppressWarnings("unchecked") public List<Object[]> getDataProviderCountsForCountry(final String isoCountryCode) { HibernateTemplate template = getHibernateTemplate(); return (List) template.execute(new HibernateCallback() { public Object doInHibernate(Session session) { Query query = session.createSQLQuery( "select distinct dp.id, dp.name as dp_name, sum(rc.count) from data_provider dp" + " inner join data_resource dr on dr.data_provider_id=dp.id" + " inner join resource_country rc on rc.data_resource_id=dr.id" + " where rc.iso_country_code=? group by dp.id order by dp_name"); query.setParameter(0, isoCountryCode); query.setCacheable(true); return query.list(); } }); }
From source file:org.gbif.portal.dao.resources.impl.hibernate.DataProviderDAOImpl.java
License:Open Source License
/** * @see org.gbif.portal.dao.resources.DataProviderDAO#getDataProviderFor(long) *//*from w w w .j a va 2 s . c om*/ public DataProvider getDataProviderFor(final long dataProviderId) { HibernateTemplate template = getHibernateTemplate(); return (DataProvider) template.execute(new HibernateCallback() { public Object doInHibernate(Session session) { Query query = session.createQuery("from DataProvider dp where dp.id = ?"); query.setParameter(0, dataProviderId); query.setCacheable(true); return query.uniqueResult(); } }); }
From source file:org.gbif.portal.dao.resources.impl.hibernate.DataProviderDAOImpl.java
License:Open Source License
/** * @see org.gbif.portal.dao.resources.DataProviderDAO#getDataProvidersOfferingTaxonomies() *//*from w w w.j a va2 s .c o m*/ @SuppressWarnings("unchecked") public List<DataProvider> getDataProvidersOfferingTaxonomies() { HibernateTemplate template = getHibernateTemplate(); return (List<DataProvider>) template.execute(new HibernateCallback() { public Object doInHibernate(Session session) { Query query = session.createQuery( "select dr.dataProvider from DataResource dr" + " inner join dr.dataProvider as dp" + " where dr.sharedTaxonomy=true" + " group by dp.id order by dp.name"); query.setCacheable(true); return query.list(); } }); }
From source file:org.gbif.portal.dao.resources.impl.hibernate.DataProviderDAOImpl.java
License:Open Source License
/** * @see org.gbif.portal.dao.resources.DataProviderDAO#getLastDataProviderAdded() *///from ww w . ja v a 2 s. c o m public DataProvider getLastDataProviderAdded() { HibernateTemplate template = getHibernateTemplate(); return (DataProvider) template.execute(new HibernateCallback() { public Object doInHibernate(Session session) { Query query = session .createQuery("from DataProvider dp where dp.deleted is null order by dp.created desc"); query.setMaxResults(1); 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#findDataResourcesAndProviders(java.lang.String, boolean, * java.lang.Integer, java.lang.Integer) */// w ww .j a va 2s .c o m @SuppressWarnings("unchecked") public List findDataResourcesAndProvidersAndNetworks(final String nameStub, final boolean fuzzy, final boolean anyOccurrence, final boolean includeCountrySearch, final int startIndex, final int maxResults) { List modelObjects = new ArrayList(); try { HibernateTemplate template = getHibernateTemplate(); List results = (List) template.execute(new HibernateCallback() { public Object doInHibernate(Session session) { String searchString = nameStub; if (fuzzy) searchString = searchString + '%'; String anyPartNameString = "%" + searchString; StringBuffer sb = new StringBuffer( "Select 'provider', dp.id, dp.name, 0 as shared_taxonomy, dp.occurrence_count, dp.occurrence_coordinate_count, dp.concept_count, dp.species_count, dp.data_resource_count, dp.id as provider_id, dp.name as provider_name, dp.iso_country_code, dp.logo_url from data_provider dp"); sb.append(" where (dp.name like :nameStub "); if (anyOccurrence) { sb.append(" or dp.name like '" + anyPartNameString + "'"); } for (String prefix : resourceNamePrefixes) sb.append(" or dp.name like '" + prefix + " " + searchString + "'"); sb.append(") and dp.deleted is null"); sb.append(" UNION "); sb.append( " Select 'resource', dr.id, dr.display_name, dr.shared_taxonomy as shared_taxonomy, dr.occurrence_count, dr.occurrence_coordinate_count, dr.concept_count, dr.species_count, dr.species_count, dp.id as provider_id, dp.name as provider_name, 'XX', dr.logo_url from data_resource dr inner join data_provider dp on dr.data_provider_id=dp.id"); sb.append(" where ( dr.display_name like :nameStub "); if (anyOccurrence) { sb.append(" or dr.display_name like '" + anyPartNameString + "'"); } for (String prefix : resourceNamePrefixes) { sb.append(" or dr.display_name like '"); sb.append(prefix); sb.append(' '); sb.append(searchString); sb.append("'"); } sb.append(") and dr.deleted is null"); sb.append(" UNION "); sb.append( " Select 'network', rn.id, rn.name, 0 as shared_taxonomy, rn.occurrence_count, rn.occurrence_coordinate_count, rn.concept_count, rn.species_count, rn.data_resource_count, rn.id as provider_id, rn.name as provider_name, rn.code, rn.logo_url from resource_network rn left join country_name cn on rn.code = cn.iso_country_code"); sb.append(" where ( rn.name like :nameStub "); if (includeCountrySearch) { sb.append("or rn.code like :nameStub or cn.name like :nameStub"); } if (anyOccurrence) { sb.append(" or rn.name like '" + anyPartNameString + "'"); } for (String prefix : resourceNamePrefixes) { sb.append(" or rn.name like '"); sb.append(prefix); sb.append(' '); sb.append(searchString); sb.append("'"); } sb.append(") and rn.deleted is null"); Query query = session.createSQLQuery(sb.toString()); query.setParameter("nameStub", searchString); query.setMaxResults(maxResults); query.setFirstResult(startIndex); query.setCacheable(true); return query.list(); } }); for (Iterator iter = results.iterator(); iter.hasNext();) { Object[] result = (Object[]) iter.next(); Object modelObject = null; Long id = null; if (result[1] instanceof BigInteger) id = ((BigInteger) result[1]).longValue(); else if (result[1] instanceof Integer) id = ((Integer) result[1]).longValue(); else if (result[1] instanceof Long) id = (Long) result[1]; if (result[0].equals("resource")) { modelObject = new DataResource(id, (String) result[2], ((BigInteger) result[3]).intValue() == 1, (Integer) result[4], (Integer) result[5], (Integer) result[6], (Integer) result[7], (Integer) result[9], (String) result[10]); } else if (result[0].equals("provider")) { modelObject = new DataProvider(id, (String) result[2], (Integer) result[4], (Integer) result[5], (Integer) result[6], (Integer) result[7], (Integer) result[8], (String) result[11], (String) result[12]); } else { modelObject = new ResourceNetwork(id, (String) result[2], (String) result[11], (Integer) result[4], (Integer) result[5], (Integer) result[6], (Integer) result[7], (Integer) result[8]); } modelObjects.add(modelObject); } } catch (Exception e) { logger.error(e.getMessage(), e); } return modelObjects; }
From source file:org.gbif.portal.dao.resources.impl.hibernate.DataResourceDAOImpl.java
License:Open Source License
/** * @see org.gbif.portal.dao.resources.DataResourceDAO#findDataResourcesAndProviders(java.lang.String, boolean, * java.lang.Integer, java.lang.Integer) *//*from w w w .ja v a 2 s . c o m*/ @SuppressWarnings("unchecked") public List findDataResourcesAndProvidersAndNetworksFromPlots(final String nameStub, final boolean fuzzy, final boolean anyOccurrence, final boolean includeCountrySearch, final int startIndex, final int maxResults) { List modelObjects = new ArrayList(); try { HibernateTemplate template = getHibernateTemplate(); List results = (List) template.execute(new HibernateCallback() { public Object doInHibernate(Session session) { String searchString = nameStub; if (fuzzy) searchString = searchString + '%'; String anyPartNameString = "%" + searchString; StringBuffer sb = new StringBuffer( "Select 'provider', dp.id, dp.name, 0 as shared_taxonomy, dp.occurrence_count, dp.occurrence_coordinate_count, dp.concept_count, dp.species_count, dp.data_resource_count, dp.id as provider_id, dp.name as provider_name, dp.iso_country_code, dp.logo_url from data_provider dp"); sb.append(" where (dp.name like :nameStub "); if (anyOccurrence) { sb.append(" or dp.name like '" + anyPartNameString + "'"); } for (String prefix : resourceNamePrefixes) sb.append(" or dp.name like '" + prefix + " " + searchString + "'"); sb.append(") and dp.deleted is null"); sb.append(" UNION "); sb.append( " Select 'resource', dr.id, dr.display_name, dr.shared_taxonomy as shared_taxonomy, dr.occurrence_count, dr.occurrence_coordinate_count, dr.concept_count, dr.species_count, dr.species_count, dp.id as provider_id, dp.name as provider_name, 'XX', dr.logo_url from data_resource dr inner join data_provider dp on dr.data_provider_id=dp.id"); sb.append(" where ( dr.display_name like :nameStub "); if (anyOccurrence) { sb.append(" or dr.display_name like '" + anyPartNameString + "'"); } for (String prefix : resourceNamePrefixes) { sb.append(" or dr.display_name like '"); sb.append(prefix); sb.append(' '); sb.append(searchString); sb.append("'"); } sb.append(") and dr.deleted is null and dr.is_from_plots is true"); sb.append(" UNION "); sb.append( " Select 'network', rn.id, rn.name, 0 as shared_taxonomy, rn.occurrence_count, rn.occurrence_coordinate_count, rn.concept_count, rn.species_count, rn.data_resource_count, rn.id as provider_id, rn.name as provider_name, rn.code, rn.logo_url from resource_network rn left join country_name cn on rn.code = cn.iso_country_code"); sb.append(" where ( rn.name like :nameStub "); if (includeCountrySearch) { sb.append("or rn.code like :nameStub or cn.name like :nameStub"); } if (anyOccurrence) { sb.append(" or rn.name like '" + anyPartNameString + "'"); } for (String prefix : resourceNamePrefixes) { sb.append(" or rn.name like '"); sb.append(prefix); sb.append(' '); sb.append(searchString); sb.append("'"); } sb.append(") and rn.deleted is null"); Query query = session.createSQLQuery(sb.toString()); query.setParameter("nameStub", searchString); query.setMaxResults(maxResults); query.setFirstResult(startIndex); query.setCacheable(true); return query.list(); } }); for (Iterator iter = results.iterator(); iter.hasNext();) { Object[] result = (Object[]) iter.next(); Object modelObject = null; Long id = null; if (result[1] instanceof BigInteger) id = ((BigInteger) result[1]).longValue(); else if (result[1] instanceof Integer) id = ((Integer) result[1]).longValue(); else if (result[1] instanceof Long) id = (Long) result[1]; if (result[0].equals("resource")) { modelObject = new DataResource(id, (String) result[2], ((BigInteger) result[3]).intValue() == 1, (Integer) result[4], (Integer) result[5], (Integer) result[6], (Integer) result[7], (Integer) result[9], (String) result[10]); } else if (result[0].equals("provider")) { modelObject = new DataProvider(id, (String) result[2], (Integer) result[4], (Integer) result[5], (Integer) result[6], (Integer) result[7], (Integer) result[8], (String) result[11], (String) result[12]); } else { modelObject = new ResourceNetwork(id, (String) result[2], (String) result[11], (Integer) result[4], (Integer) result[5], (Integer) result[6], (Integer) result[7], (Integer) result[8]); } modelObjects.add(modelObject); } } catch (Exception e) { logger.error(e.getMessage(), e); } return modelObjects; }