List of usage examples for org.hibernate SQLQuery setCacheable
@Override
NativeQuery<T> setCacheable(boolean cacheable);
From source file:org.gbif.portal.dao.resources.impl.hibernate.DataResourceDAOImpl.java
License:Open Source License
/** * @param dataResourceId//from ww w . j a va2 s. com * @param geoRefOnly * @return */ @SuppressWarnings("unchecked") public List<Object[]> getCountryCountsForDataResource(final Long dataResourceId, final boolean geoRefOnly) { HibernateTemplate template = getHibernateTemplate(); return (List) template.execute(new HibernateCallback() { public Object doInHibernate(Session session) { StringBuffer sb = new StringBuffer( "select c.id as country_id, c.iso_country_code as iso_country_code, c.region as region,"); if (geoRefOnly) { sb.append(" rc.occurrence_coordinate_count as the_count"); } else { sb.append(" rc.count as the_count"); } sb.append( " from resource_country rc inner join country c on c.iso_country_code=rc.iso_country_code"); if (dataResourceId != null) { sb.append(" where rc.data_resource_id=:dataResourceId "); } if (geoRefOnly) { sb.append(" and rc.occurrence_coordinate_count>0"); } sb.append(" order by c.iso_country_code"); SQLQuery query = session.createSQLQuery(sb.toString()); if (dataResourceId != null) query.setParameter("dataResourceId", dataResourceId); query.setCacheable(true); query.addScalar("country_id", Hibernate.LONG); query.addScalar("iso_country_code", Hibernate.STRING); query.addScalar("region", Hibernate.STRING); query.addScalar("the_count", Hibernate.INTEGER); return query.list(); } }); }
From source file:org.gbif.portal.dao.taxonomy.impl.hibernate.TaxonConceptDAOImpl.java
License:Open Source License
@SuppressWarnings("unchecked") public List<String> getTaxonConceptCounts() { HibernateTemplate template = getHibernateTemplate(); List<Object[]> taxonCounts = (List<Object[]>) getHibernateTemplate().execute(new HibernateCallback() { public Object doInHibernate(Session session) { SQLQuery query = session.createSQLQuery("select taxon_name, count from stats_taxon_concept_counts"); query.setCacheable(true); query.addScalar("taxon_name", Hibernate.STRING); query.addScalar("count", Hibernate.INTEGER); return query.list(); }//w ww . ja v a 2 s. com }); ArrayList<String> taxaC = new ArrayList<String>(); for (Object[] result : taxonCounts) { taxaC.add(result[0].toString() + "|" + result[1].toString()); } return taxaC; }
From source file:org.jtalks.jcommune.model.dao.hibernate.LastReadPostHibernateDaoTest.java
License:Open Source License
/** * Method marks topics as read to user//from w w w . jav a2 s .c om * * @param topics List of topics to mark * @param user User for which threads are marked as read * @return list of count posts for each topic, for verification */ private Map<Long, DateTime> markAllTopicsASRead(List<Topic> topics, JCUser user) { SQLQuery insertQuery = (SQLQuery) session.getNamedQuery("markAllTopicsRead"); insertQuery.setCacheable(false); Map<Long, DateTime> listCountPostsToTopics = new HashMap<Long, DateTime>(); for (Topic tp : topics) { insertQuery.setParameter("uuid", UUID.randomUUID().toString()).setParameter("user", user.getId()) .setParameter("lastPostDate", ((DateTime) tp.getLastPost().getCreationDate()).toDate()) .setParameter("topic", tp.getId()).executeUpdate(); listCountPostsToTopics.put(tp.getId(), tp.getLastPost().getCreationDate()); } return listCountPostsToTopics; }
From source file:org.yamj.core.database.dao.ArtworkDao.java
License:Open Source License
public List<QueueDTO> getArtworkQueue(final CharSequence sql, final int maxResults) { SQLQuery query = currentSession().createSQLQuery(sql.toString()); query.setReadOnly(true);/* w w w.j a va 2 s. c o m*/ query.setCacheable(true); if (maxResults > 0) { query.setMaxResults(maxResults); } List<QueueDTO> queueElements = new ArrayList<>(); List<Object[]> objects = query.list(); for (Object[] object : objects) { QueueDTO queueElement = new QueueDTO(); queueElement.setId(convertRowElementToLong(object[0])); queueElement.setArtworkType(convertRowElementToString(object[1])); queueElement.setDate(convertRowElementToDate(object[3])); if (queueElement.getDate() == null) { queueElement.setDate(convertRowElementToDate(object[2])); } queueElements.add(queueElement); } Collections.sort(queueElements); return queueElements; }
From source file:org.yamj.core.database.dao.ArtworkDao.java
License:Open Source License
public List<QueueDTO> getArtworkLocatedQueue(final int maxResults) { final StringBuilder sql = new StringBuilder(); sql.append("SELECT DISTINCT loc.id, loc.create_timestamp, loc.update_timestamp "); sql.append("FROM artwork_located loc "); sql.append("WHERE loc.status in ('NEW','UPDATED')"); SQLQuery query = currentSession().createSQLQuery(sql.toString()); query.setReadOnly(true);/* w w w . ja v a2s . c o m*/ query.setCacheable(true); if (maxResults > 0) { query.setMaxResults(maxResults); } List<QueueDTO> queueElements = new ArrayList<>(); List<Object[]> objects = query.list(); for (Object[] object : objects) { QueueDTO queueElement = new QueueDTO(); queueElement.setId(convertRowElementToLong(object[0])); queueElement.setDate(convertRowElementToDate(object[2])); if (queueElement.getDate() == null) { queueElement.setDate(convertRowElementToDate(object[1])); } queueElements.add(queueElement); } Collections.sort(queueElements); return queueElements; }
From source file:org.yamj.core.database.dao.ConfigDao.java
License:Open Source License
public Map<String, String> readConfig() { SQLQuery query = currentSession().createSQLQuery("select config_key, config_value from configuration"); query.setReadOnly(true);//from www. j a v a2 s . c o m query.setCacheable(true); HashMap<String, String> config = new HashMap<>(); List<Object[]> objects = query.list(); for (Object[] object : objects) { String key = convertRowElementToString(object[0]); String value = convertRowElementToString(object[1]); config.put(key, value); } return config; }
From source file:org.yamj.core.database.dao.MediaDao.java
License:Open Source License
public List<QueueDTO> getMediaQueue(final CharSequence sql, final int maxResults) { SQLQuery query = currentSession().createSQLQuery(sql.toString()); query.setReadOnly(true);/*from w ww . j av a2 s . c o m*/ query.setCacheable(true); if (maxResults > 0) { query.setMaxResults(maxResults); } List<QueueDTO> queueElements = new ArrayList<>(); List<Object[]> objects = query.list(); for (Object[] object : objects) { QueueDTO queueElement = new QueueDTO(); queueElement.setId(convertRowElementToLong(object[0])); queueElement.setDate(convertRowElementToDate(object[2])); if (queueElement.getDate() == null) { queueElement.setDate(convertRowElementToDate(object[1])); } queueElements.add(queueElement); } Collections.sort(queueElements); return queueElements; }
From source file:org.yamj.core.database.dao.MetadataDao.java
License:Open Source License
public List<QueueDTO> getMetadataQueue(final CharSequence sql, final int maxResults) { SQLQuery query = currentSession().createSQLQuery(sql.toString()); query.setReadOnly(true);//from ww w . java 2 s . c om query.setCacheable(true); if (maxResults > 0) { query.setMaxResults(maxResults); } List<QueueDTO> queueElements = new ArrayList<>(); List<Object[]> objects = query.list(); for (Object[] object : objects) { QueueDTO queueElement = new QueueDTO(); queueElement.setId(convertRowElementToLong(object[0])); queueElement.setMetadataType(convertRowElementToString(object[1])); queueElement.setDate(convertRowElementToDate(object[3])); if (queueElement.getDate() == null) { queueElement.setDate(convertRowElementToDate(object[2])); } queueElements.add(queueElement); } Collections.sort(queueElements); return queueElements; }
From source file:org.yamj.core.database.dao.TrailerDao.java
License:Open Source License
public List<QueueDTO> getTrailerQueueForScanning(final int maxResults) { final StringBuilder sql = new StringBuilder(); sql.append("select vd.id,'"); sql.append(MetaDataType.MOVIE);//from w w w . j av a 2s.c om sql.append("' as metatype,vd.create_timestamp,vd.update_timestamp "); sql.append("from videodata vd "); sql.append("where vd.trailer_status in ('NEW','UPDATED') "); sql.append("and vd.status='DONE' "); sql.append("and vd.episode<0 "); sql.append("union "); sql.append("select ser.id,'"); sql.append(MetaDataType.SERIES); sql.append("' as mediatype,ser.create_timestamp,ser.update_timestamp "); sql.append("from series ser "); sql.append("where ser.trailer_status in ('NEW','UPDATED') "); sql.append("and ser.status='DONE' "); SQLQuery query = currentSession().createSQLQuery(sql.toString()); query.setReadOnly(true); query.setCacheable(true); if (maxResults > 0) { query.setMaxResults(maxResults); } List<QueueDTO> queueElements = new ArrayList<>(); List<Object[]> objects = query.list(); for (Object[] object : objects) { QueueDTO queueElement = new QueueDTO(); queueElement.setId(convertRowElementToLong(object[0])); queueElement.setMetadataType(convertRowElementToString(object[1])); queueElement.setDate(convertRowElementToDate(object[3])); if (queueElement.getDate() == null) { queueElement.setDate(convertRowElementToDate(object[2])); } queueElements.add(queueElement); } Collections.sort(queueElements); return queueElements; }
From source file:org.yamj.core.database.dao.TrailerDao.java
License:Open Source License
public List<QueueDTO> getTrailerQueueForProcessing(final int maxResults) { final StringBuilder sql = new StringBuilder(); sql.append("SELECT DISTINCT t.id, t.create_timestamp, t.update_timestamp "); sql.append("FROM trailer t "); sql.append("WHERE t.status in ('NEW','UPDATED')"); SQLQuery query = currentSession().createSQLQuery(sql.toString()); query.setReadOnly(true);/*from w ww.j av a2s .co m*/ query.setCacheable(true); if (maxResults > 0) { query.setMaxResults(maxResults); } List<QueueDTO> queueElements = new ArrayList<>(); List<Object[]> objects = query.list(); for (Object[] object : objects) { QueueDTO queueElement = new QueueDTO(); queueElement.setId(convertRowElementToLong(object[0])); queueElement.setDate(convertRowElementToDate(object[2])); if (queueElement.getDate() == null) { queueElement.setDate(convertRowElementToDate(object[1])); } queueElements.add(queueElement); } Collections.sort(queueElements); return queueElements; }