List of usage examples for org.hibernate SharedSessionContract createQuery
<R> Query<R> createQuery(String queryString, Class<R> resultClass);
From source file:com.romeikat.datamessie.core.base.dao.impl.StatisticsDao.java
License:Open Source License
public StatisticsSparseTable getStatistics(final SharedSessionContract ssc, final Collection<Long> sourceIds, final LocalDate published) { if (CollectionUtils.isEmpty(sourceIds) || published == null) { return new StatisticsSparseTable(); }//www . java 2s .c om // Query final StringBuilder hql = new StringBuilder(); hql.append("SELECT s.sourceId, s.state, documents "); hql.append("FROM Statistics s "); hql.append("WHERE s.sourceId IN :_sourceIds "); hql.append("AND s.published = :_published "); hql.append("GROUP BY s.sourceId, s.state "); final Query<Object[]> query = ssc.createQuery(hql.toString(), Object[].class); query.setParameterList("_sourceIds", sourceIds); query.setParameter("_published", published); // Execute final List<Object[]> records = query.list(); // Postprocess final StatisticsSparseTable statistics = new StatisticsSparseTable(); for (final Object[] record : records) { final long sourceId = (Long) record[0]; final DocumentProcessingState state = (DocumentProcessingState) record[1]; final long number = (Long) record[2]; final DocumentsPerState documentsForState = new DocumentsPerState(); documentsForState.put(state, number); statistics.putValue(sourceId, published, documentsForState); } // Done return statistics; }