List of usage examples for org.hibernate.criterion Projections sqlGroupProjection
@SuppressWarnings("UnusedDeclaration") public static Projection sqlGroupProjection(String sql, String groupBy, String[] columnAliases, Type[] types)
From source file:org.sculptor.framework.accessimpl.jpahibernate.JpaHibFindByConditionStatAccessImpl.java
License:Apache License
private Projection makeTimeGroupByMySql(ColumnStatRequest<T> column, ColumnStatType statType, Criteria criteria) {/*w w w. j a va 2 s. co m*/ String func; if (statType.equals(GROUP_BY_DAY)) { func = "day"; } else if (statType.equals(GROUP_BY_DOW)) { func = "dayofwek"; } else if (statType.equals(GROUP_BY_DOY)) { func = "dayofyear"; } else if (statType.equals(GROUP_BY_HOUR)) { func = "hour"; } else if (statType.equals(GROUP_BY_MONTH)) { func = "month"; } else if (statType.equals(GROUP_BY_QUARTER)) { func = "quarter"; } else if (statType.equals(GROUP_BY_WEEK)) { func = "week"; } else if (statType.equals(GROUP_BY_YEAR)) { func = "year"; } else { func = "day"; } String colName = column.getColumn().getName(); String fldName = colName + "_" + func; String sqlFunc = "extract(" + func + " from {alias}." + colName + ")"; criteria.addOrder(Order.asc(fldName)); return Projections.alias(Projections.sqlGroupProjection(sqlFunc + " as " + fldName, fldName, new String[] { fldName }, TIME_RESULT_TYPES), fldName); }
From source file:ru.trett.cis.DAO.AssetDAOImpl.java
License:Open Source License
@Override @SuppressWarnings("unchecked") public List<ResultMapper> assetGroupByStatusAndCount() { Criteria criteria = sessionFactory.getCurrentSession().createCriteria(Asset.class); return criteria .setProjection(Projections.projectionList() .add(Projections.sqlGroupProjection("status as st", "st", new String[] { "st" }, new Type[] { StandardBasicTypes.STRING }), "name") .add(Projections.rowCount(), "data")) .setResultTransformer(Transformers.aliasToBean(ResultMapper.class)).list(); }
From source file:ru.trett.cis.DAO.InvoiceDAOImpl.java
License:Open Source License
@Override @SuppressWarnings("unchecked") public List<ResultMapper> recordsPerDay() { Criteria criteria = sessionFactory.getCurrentSession().createCriteria(Invoice.class); return criteria .setProjection(Projections.projectionList() .add(Projections.sqlGroupProjection("date(date) as creationDate", "creationDate", new String[] { "creationDate" }, new Type[] { StandardBasicTypes.STRING }), "name") .add(Projections.rowCount(), "data")) .setResultTransformer(Transformers.aliasToBean(ResultMapper.class)).setCacheable(true).list(); }