List of usage examples for org.hibernate.criterion Projections countDistinct
public static CountProjection countDistinct(String propertyName)
From source file:com.jaspersoft.jasperserver.api.metadata.common.service.impl.hibernate.HibernateRepositoryServiceImpl.java
License:Open Source License
@Transactional(propagation = Propagation.REQUIRED) public Map<Class, Integer> loadResourcesMapCount(ExecutionContext context, String text, List<Class> resourceTypeList, List<SearchFilter> filters, Map<String, SearchFilter> typeSpecificFilters, SearchSorter sorter, TransformerFactory transformerFactory) { if (transformerFactory == null) { throw new IllegalArgumentException("Transformer factory is null."); }/*from w w w . jav a 2 s . c o m*/ Map<Class, Integer> result = new HashMap<Class, Integer>(); Map<Class, Class> typeToPersistentClassMap = getTypeToPersistentClassMap(resourceTypeList); for (Map.Entry<Class, Class> entry : typeToPersistentClassMap.entrySet()) { SearchCriteria criteria = getResourcesListCriteria(context, text, entry.getKey(), entry.getValue(), filters, typeSpecificFilters); criteria.setProjection(Projections.countDistinct("id")); // if (sorter != null) { // sorter.applyOrder(entry.getKey().getName(), context, criteria); // } List resourceList = getHibernateTemplate().findByCriteria(criteria); ResultTransformer transformer = transformerFactory.createTransformer(filters, sorter); if (transformer != null) { result.put(entry.getKey(), transformer.transformToCount(resourceList)); } else { throw new IllegalArgumentException("Result transformer is null."); } } return result; }
From source file:com.jaspersoft.jasperserver.api.metadata.common.service.impl.hibernate.HibernateRepositoryServiceImpl.java
License:Open Source License
@Transactional(propagation = Propagation.REQUIRED) public int getResourcesCount(ExecutionContext context, SearchCriteriaFactory searchCriteriaFactory, List<SearchFilter> filters, SearchSorter sorter, TransformerFactory transformerFactory) { if (transformerFactory == null) { throw new IllegalArgumentException("Transformer factory is null."); }/*from w w w .j a v a 2s . com*/ SearchCriteria criteria; if (queryModificationEvaluator.useFullResource(context)) { criteria = searchCriteriaFactory.newFactory(Resource.class.getName()).create(context, filters); criteria.setProjection(Projections.countDistinct("id")); } else { criteria = searchCriteriaFactory.create(context, filters); criteria.setProjection(Projections.rowCount()); } List resourceList = getHibernateTemplate().findByCriteria(criteria); ResultTransformer transformer = transformerFactory.createTransformer(filters, sorter); if (transformer != null) { return transformer.transformToCount(resourceList); } else { throw new IllegalArgumentException("Result transformer is null."); } }
From source file:com.kodemore.hibernate.criteria.KmCriteria.java
License:Open Source License
public void selectCountDistinct(String name) { Projection e; e = Projections.countDistinct(getFullName(name)); addProjection(e); }
From source file:com.liferay.portal.dao.orm.hibernate.ProjectionFactoryImpl.java
License:Open Source License
public Projection countDistinct(String propertyName) { return new ProjectionImpl(Projections.countDistinct(propertyName)); }
From source file:com.liferay.portal.workflow.jbpm.dao.CustomSession.java
License:Open Source License
public int countProcessDefinitions(String name, boolean latest) { try {/* w ww. ja va 2 s. c om*/ Criteria criteria = _session.createCriteria(ProcessDefinition.class); if (latest) { criteria.setProjection(Projections.countDistinct("name")); } else { criteria.setProjection(Projections.rowCount()); } if (name != null) { criteria.add(Restrictions.eq("name", name)); } Number count = (Number) criteria.uniqueResult(); return count.intValue(); } catch (Exception e) { throw new JbpmException(e); } }
From source file:com.liferay.portal.workflow.jbpm.dao.CustomSession.java
License:Open Source License
public int countProcessInstances(long processDefinitionId, Boolean completed) { try {/*from ww w. j av a2s . com*/ Criteria criteria = _session.createCriteria(ProcessInstance.class); criteria.setProjection(Projections.countDistinct("id")); criteria.add(Restrictions.eq("processDefinition.id", processDefinitionId)); if (completed != null) { if (completed.booleanValue()) { criteria.add(Restrictions.isNotNull("end")); } else { criteria.add(Restrictions.isNull("end")); } } Number count = (Number) criteria.uniqueResult(); return count.intValue(); } catch (Exception e) { throw new JbpmException(e); } }
From source file:com.liferay.portal.workflow.jbpm.dao.CustomSession.java
License:Open Source License
public int countTaskInstances(long processInstanceId, long tokenId, String[] actorIds, boolean pooledActors, Boolean completed) {/* w ww . ja v a 2 s .c o m*/ if ((actorIds != null) && (actorIds.length == 0)) { return 0; } try { Criteria criteria = _session.createCriteria(TaskInstance.class); criteria.setProjection(Projections.countDistinct("id")); if (processInstanceId > 0) { criteria.add(Restrictions.eq("processInstance.id", processInstanceId)); } else if (tokenId > 0) { criteria.add(Restrictions.eq("token.id", tokenId)); } else if (actorIds != null) { if (pooledActors) { Criteria subcriteria = criteria.createCriteria("pooledActors"); subcriteria.add(Restrictions.in("actorId", actorIds)); } else { criteria.add(Restrictions.in("actorId", actorIds)); } } if (completed != null) { if (completed.booleanValue()) { criteria.add(Restrictions.isNotNull("end")); } else { criteria.add(Restrictions.isNull("end")); } } Number count = (Number) criteria.uniqueResult(); return count.intValue(); } catch (Exception e) { throw new JbpmException(e); } }
From source file:com.maydesk.base.util.PDDataGridModel.java
License:Mozilla Public License
public void reloadData(int position) { dataList.clear();/* ww w .j a v a 2 s . c o m*/ Criteria criteria = tableFactory.getCriteria(PDHibernateFactory.getSession()); criteria.setProjection(Projections.countDistinct("id")); Long longRows = (Long) criteria.uniqueResult(); totalRows = longRows.intValue(); Projection projection = tableFactory.getProjectionList(); if (projection == null) { criteria = tableFactory.getCriteria(PDHibernateFactory.getSession()); } else { criteria.setProjection(projection); } criteria.setMaxResults(rowsPerPage); criteria.setFirstResult(position); tableFactory.addOrder(criteria); List list = criteria.list(); for (Object o : list) { Object[] data = null; if (o instanceof Object[]) { data = (Object[]) o; } else { data = new Object[] { o }; // convert to array } dataList.add(tableFactory.createHeaderValue(data)); } }
From source file:com.painiu.core.dao.hibernate.PhotoDAOHibernate.java
License:Open Source License
static Criteria buildCountPhotoCriteria(final Session session, User user, String[] tags, boolean taggedAll, String text, Relation relation) { //Criteria criteria = buildPhotoCriteria(session, user, group, tags, taggedAll, text, relation, true); Criteria criteria = buildPhotoCriteria(session, user, tags, taggedAll, text, relation, true); if ((tags != null && tags.length > 1) || text != null) { return criteria.setProjection(Projections.countDistinct("id")); }/*from w ww. j av a2 s . c om*/ return criteria.setProjection(Projections.count("id")); }
From source file:com.qcadoo.model.api.search.SearchProjections.java
License:Open Source License
/** * Creates projection which add given field to the "GROUP BY" clause and its "count with distinct" to the "SELECT" clause. * // w w w . j a v a2 s. c om * @param field * field * @return projection */ public static SearchProjection countDistinct(final String field) { return new SearchProjectionImpl(Projections.countDistinct(field)); }