List of usage examples for org.hibernate SQLQuery setCacheable
@Override
NativeQuery<T> setCacheable(boolean cacheable);
From source file:edu.vt.vbi.patric.dao.DBDisease.java
License:Apache License
public int getGADBreadCrumbCount(Map<String, String> key) { String sql = getGADSQL(key, "breadcrumb"); Session session = factory.getCurrentSession(); session.beginTransaction();// w ww .j a v a 2 s . c om SQLQuery q = session.createSQLQuery(sql).addScalar("cnt", Hibernate.INTEGER); q = bindSQLValues(q, key); q.setCacheable(true); Object obj = q.uniqueResult(); session.getTransaction().commit(); return Integer.parseInt(obj.toString()); }
From source file:edu.vt.vbi.patric.dao.DBDisease.java
License:Apache License
public int getGADGraphBreadCrumbCount(Map<String, String> key) { String sql = getGADSQL(key, "graphbreadcrumb"); Session session = factory.getCurrentSession(); session.beginTransaction();/*from w w w .j a v a 2s . co m*/ SQLQuery q = session.createSQLQuery(sql).addScalar("cnt", Hibernate.INTEGER); q = bindGraphGADSQLValues(q, key); q.setCacheable(true); Object obj = q.uniqueResult(); session.getTransaction().commit(); return Integer.parseInt(obj.toString()); }
From source file:edu.vt.vbi.patric.dao.DBDisease.java
License:Apache License
public int getGADGraphCount(Map<String, String> key) { String sql = getGADSQL(key, "graphcount"); Session session = factory.getCurrentSession(); session.beginTransaction();//from w w w . j a v a 2 s.c o m SQLQuery q = session.createSQLQuery(sql).addScalar("cnt", Hibernate.INTEGER); q = bindGraphGADSQLValues(q, key); q.setCacheable(true); Object obj = q.uniqueResult(); session.getTransaction().commit(); return Integer.parseInt(obj.toString()); }
From source file:edu.vt.vbi.patric.dao.DBDisease.java
License:Apache License
public int getGADCount(Map<String, String> key) { String sql = getGADSQL(key, "count"); Session session = factory.getCurrentSession(); session.beginTransaction();/* ww w . ja v a 2 s .co m*/ SQLQuery q = session.createSQLQuery(sql).addScalar("cnt", Hibernate.INTEGER); q = bindSQLValues(q, key); q.setCacheable(true); Object obj = q.uniqueResult(); session.getTransaction().commit(); return Integer.parseInt(obj.toString()); }
From source file:edu.vt.vbi.patric.dao.DBPRC.java
License:Apache License
public int getPRCCount(String taxonId, String filter) { String sql = "select count(*) cnt from (select distinct experiment_id, description, speciesname, processing_type, summary, pubmed_id, count(distinct sample_id) from app.post_genomic"; if (filter.equals("MS")) sql += " where processing_type = 'Mass spectrometry'"; else if (filter.equals("MA")) sql += " where processing_type = 'Microarray'"; else//w w w . j a v a2 s . c o m sql += " where processing_type = 'Protein interaction'"; sql += " and taxon_id in (" + DBSummary.getTaxonIdsInTaxonSQL(":taxonId") + ")"; sql += " group by experiment_id, description, speciesname, processing_type, summary, pubmed_id)"; Session session = factory.getCurrentSession(); session.beginTransaction(); SQLQuery q = session.createSQLQuery(sql).addScalar("cnt", Hibernate.INTEGER); q.setCacheable(true); q.setTimeout(SQL_TIMEOUT); q.setString("taxonId", taxonId); Object obj = q.uniqueResult(); session.getTransaction().commit(); return Integer.parseInt(obj.toString()); }
From source file:org.gbif.portal.dao.geospatial.impl.hibernate.CountryDAOImpl.java
License:Open Source License
/** * @see org.gbif.portal.dao.resources.DataResourceDAO#getCountryCountsForCountry(java.lang.Long) *///from ww w . j av a 2 s . c om @SuppressWarnings("unchecked") public List<Object[]> getCountryCountsForCountry(final String isoCountryCode, final boolean geoRefOnly, final Locale locale) { HibernateTemplate template = getHibernateTemplate(); return (List) template.execute(new HibernateCallback() { public Object doInHibernate(Session session) { StringBuffer sb = new StringBuffer( "select dp.iso_country_code as the_iso_country_code, cn.name as cn_name,"); if (geoRefOnly) { sb.append(" sum(rc.occurrence_coordinate_count) as the_count 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 " + " inner join country_name cn on dp.iso_country_code=cn.iso_country_code" + " where "); } else { sb.append(" sum(rc.count) as the_count 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 " + " inner join country_name cn on dp.iso_country_code=cn.iso_country_code" + " where "); } if (isoCountryCode != null) { sb.append(" rc.iso_country_code=:isoCountryCode and cn.locale=:locale"); } if (geoRefOnly) { sb.append(" and rc.occurrence_coordinate_count>0"); } sb.append(" and dr.deleted is null"); sb.append(" group by cn_name"); SQLQuery query = session.createSQLQuery(sb.toString()); if (isoCountryCode != null) { query.setParameter("isoCountryCode", isoCountryCode); query.setParameter("locale", getLocaleForQuery(locale)); query.addScalar("the_iso_country_code", Hibernate.STRING); query.addScalar("cn_name", Hibernate.STRING); query.addScalar("the_count", Hibernate.INTEGER); } query.setCacheable(true); logger.debug("query is: " + sb.toString()); return query.list(); } }); }
From source file:org.gbif.portal.dao.geospatial.impl.hibernate.CountryDAOImpl.java
License:Open Source License
/** * @see org.gbif.portal.dao.taxonomy.TaxonConceptDAO#getCountryCountsForTaxonConcept(java.lang.Long) *///from ww w . j av a 2 s . c o m @SuppressWarnings("unchecked") public List<Object[]> getCountryCountsForTaxonConcept(final long taxonConceptId, final Locale locale) { HibernateTemplate template = getHibernateTemplate(); return (List) template.execute(new HibernateCallback() { public Object doInHibernate(Session session) { SQLQuery query = session.createSQLQuery("select tc.iso_country_code the_iso_country_code, " + " tc.iso_country_code the_iso_country_code2, cn.name as cn_name, tc.count as the_count from taxon_country tc" + " inner join country_name cn on tc.iso_country_code=cn.iso_country_code" + " where tc.taxon_concept_id=:taxonConceptId and cn.locale=:locale order by cn_name"); query.setParameter("taxonConceptId", taxonConceptId); query.setParameter("locale", getLocaleForQuery(locale)); query.addScalar("the_iso_country_code", Hibernate.STRING); query.addScalar("the_iso_country_code2", Hibernate.STRING); query.addScalar("the_count", Hibernate.INTEGER); query.setCacheable(true); return query.list(); } }); }
From source file:org.gbif.portal.dao.resources.impl.hibernate.DataProviderDAOImpl.java
License:Open Source License
@SuppressWarnings("unchecked") public List<String> getProviderTypeCounts() { HibernateTemplate template = getHibernateTemplate(); List<Object[]> providerTypeCounts = (List<Object[]>) getHibernateTemplate() .execute(new HibernateCallback() { public Object doInHibernate(Session session) { SQLQuery query = session.createSQLQuery( "SELECT provider_type, count FROM stats_provider_type_species_counts"); query.setCacheable(true); query.addScalar("provider_type", Hibernate.STRING); query.addScalar("count", Hibernate.INTEGER); return query.list(); }/*from w ww. j a va 2s. c o m*/ }); ArrayList<String> providerC = new ArrayList<String>(); for (Object[] result : providerTypeCounts) { providerC.add(result[0].toString() + "|" + result[1].toString()); } return providerC; }
From source file:org.gbif.portal.dao.resources.impl.hibernate.DataProviderDAOImpl.java
License:Open Source License
@SuppressWarnings("unchecked") public List<String> getOcurrencePerMonthAccumulativeCounts() { HibernateTemplate template = getHibernateTemplate(); List<Object[]> monthAccumulativeCounts = (List<Object[]>) getHibernateTemplate() .execute(new HibernateCallback() { public Object doInHibernate(Session session) { SQLQuery query = session.createSQLQuery( "SELECT year, month, accumulative FROM stats_month_counts where count > 0"); query.setCacheable(true); query.addScalar("year", Hibernate.INTEGER); query.addScalar("month", Hibernate.INTEGER); query.addScalar("accumulative", Hibernate.INTEGER); return query.list(); }/*from w w w . j av a2s . c om*/ }); ArrayList<String> monthC = new ArrayList<String>(); for (Object[] result : monthAccumulativeCounts) { monthC.add(result[0].toString() + "-" + result[1].toString() + "|" + result[2].toString()); } return monthC; }
From source file:org.gbif.portal.dao.resources.impl.hibernate.DataProviderDAOImpl.java
License:Open Source License
@SuppressWarnings("unchecked") public List<String> getOcurrencePerMonthTriCounts() { HibernateTemplate template = getHibernateTemplate(); List<Object[]> monthTriCounts = (List<Object[]>) getHibernateTemplate().execute(new HibernateCallback() { public Object doInHibernate(Session session) { SQLQuery query = session .createSQLQuery("SELECT tri, count FROM stats_tri_month_counts where count > 0"); query.setCacheable(true); query.addScalar("tri", Hibernate.STRING); query.addScalar("count", Hibernate.INTEGER); return query.list(); }//from ww w. j a va2 s . c o m }); ArrayList<String> monthTC = new ArrayList<String>(); for (Object[] result : monthTriCounts) { monthTC.add(result[0].toString() + "|" + result[1].toString()); } return monthTC; }