List of usage examples for org.hibernate Criteria setResultTransformer
public Criteria setResultTransformer(ResultTransformer resultTransformer);
From source file:com.hmsinc.epicenter.model.workflow.impl.WorkflowRepositoryImpl.java
License:Open Source License
@SuppressWarnings("unchecked") public List<Subscription> getSubscriptions(Classification classification, Geography geography) { Validate.notNull(classification, "Classification must be specified."); Validate.notNull(geography, "Geography must be specified."); final Criteria c = criteriaQuery(entityManager, Subscription.class); c.createCriteria("classifications").add(Restrictions.idEq(classification.getId())); c.createCriteria("geographies").add(SpatialRestrictions.contains("geometry", geography.getGeometry())); c.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); return c.list(); }
From source file:com.hypersocket.permissions.PermissionRepositoryImpl.java
License:Open Source License
@Override @Transactional(readOnly = true)//from ww w . j a v a2 s.c o m public List<Role> searchRoles(final Realm realm, String searchPattern, int start, int length, ColumnSort[] sorting) { return search(Role.class, "name", searchPattern, start, length, sorting, new CriteriaConfiguration() { @Override public void configure(Criteria criteria) { criteria.add(Restrictions.eq("personalRole", false)); criteria.add(Restrictions.eq("hidden", false)); criteria.setFetchMode("permissions", FetchMode.SELECT); criteria.setFetchMode("principals", FetchMode.SELECT); criteria.setFetchMode("resources", FetchMode.SELECT); criteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); criteria.add(Restrictions.eq("realm", realm)); } }); }
From source file:com.hypersocket.permissions.PermissionRepositoryImpl.java
License:Open Source License
@Override @Transactional(readOnly = true)/*ww w . j ava 2 s. c om*/ public Long countRoles(final Realm realm, String searchPattern) { return getCount(Role.class, "name", searchPattern, new CriteriaConfiguration() { @Override public void configure(Criteria criteria) { criteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); criteria.add(Restrictions.eq("personalRole", false)); criteria.add(Restrictions.eq("hidden", false)); criteria.add(Restrictions.or(Restrictions.eq("realm", realm), Restrictions.isNull("realm"))); } }); }
From source file:com.hypersocket.repository.AbstractRepositoryImpl.java
License:Open Source License
@SuppressWarnings("unchecked") @Transactional(readOnly = true)//from w w w. ja va 2 s . com protected <T> List<T> list(Class<T> cls, boolean caseInsensitive, CriteriaConfiguration... configs) { Criteria criteria = createCriteria(cls); for (CriteriaConfiguration c : configs) { c.configure(criteria); } criteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); @SuppressWarnings("rawtypes") List results = criteria.list(); return results; }
From source file:com.hypersocket.repository.AbstractRepositoryImpl.java
License:Open Source License
@SuppressWarnings("unchecked") @Transactional(readOnly = true)//from w w w . jav a2s . c o m protected <T> Collection<T> list(Class<T> cls, CriteriaConfiguration... configs) { Criteria criteria = createCriteria(cls); for (CriteriaConfiguration c : configs) { c.configure(criteria); } criteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); @SuppressWarnings("rawtypes") List results = criteria.list(); return results; }
From source file:com.hypersocket.repository.AbstractRepositoryImpl.java
License:Open Source License
@SuppressWarnings("unchecked") @Transactional(readOnly = true)/*from ww w. j av a 2 s. c o m*/ protected <T> List<T> allEntities(Class<T> cls, CriteriaConfiguration... configs) { Criteria criteria = createCriteria(cls); criteria.add(Restrictions.eq("deleted", false)); criteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); for (CriteriaConfiguration c : configs) { c.configure(criteria); } return (List<T>) criteria.list(); }
From source file:com.hypersocket.repository.AbstractRepositoryImpl.java
License:Open Source License
@Override @Transactional(readOnly = true)/*from ww w .j av a 2s . com*/ public Long getCount(Class<?> clz, String searchColumn, String searchPattern, CriteriaConfiguration... configs) { Criteria criteria = createCriteria(clz); for (CriteriaConfiguration c : configs) { c.configure(criteria); } if (!StringUtils.isEmpty(searchPattern)) { criteria.add(Restrictions.ilike(searchColumn, searchPattern)); } criteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); criteria.setProjection(Projections.rowCount()); return (long) criteria.uniqueResult(); }
From source file:com.hypersocket.repository.AbstractRepositoryImpl.java
License:Open Source License
@Override public List<?> getCounts(Class<?> clz, String groupBy, CriteriaConfiguration... configs) { Criteria criteria = createCriteria(clz); for (CriteriaConfiguration c : configs) { c.configure(criteria);//w ww . ja v a 2s. c om } criteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); criteria.setProjection(Projections.projectionList().add(Projections.groupProperty(groupBy)) .add(Projections.count(groupBy))); return criteria.list(); }
From source file:com.hypersocket.repository.AbstractRepositoryImpl.java
License:Open Source License
@SuppressWarnings("unchecked") @Transactional(readOnly = true)/*from ww w . ja va 2 s.com*/ public <T> List<T> search(Class<T> clz, final String searchColumn, final String searchPattern, final int start, final int length, final ColumnSort[] sorting, CriteriaConfiguration... configs) { Criteria criteria = createCriteria(clz); if (!StringUtils.isEmpty(searchPattern)) { criteria.add(Restrictions.ilike(searchColumn, searchPattern)); } for (CriteriaConfiguration c : configs) { c.configure(criteria); } for (ColumnSort sort : sorting) { criteria.addOrder(sort.getSort() == Sort.ASC ? Order.asc(sort.getColumn().getColumnName()) : Order.desc(sort.getColumn().getColumnName())); } criteria.setProjection(Projections.distinct(Projections.id())); criteria.setFirstResult(start); criteria.setMaxResults(length); List<T> ids = (List<T>) criteria.list(); if (ids.isEmpty()) { return new ArrayList<T>(); } criteria = createCriteria(clz); criteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); criteria.add(Restrictions.in("id", ids)); return ((List<T>) criteria.list()); }
From source file:com.hypersocket.resource.AbstractAssignableResourceRepositoryImpl.java
License:Open Source License
@SuppressWarnings("unchecked") @Override/* w ww.j a va2s . c o m*/ public Collection<T> getAssignedResources(Principal... principals) { Criteria criteria = createCriteria(getResourceClass()); criteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); criteria.add(Restrictions.eq("realm", principals[0].getRealm())); criteria = criteria.createCriteria("roles"); criteria.add(Restrictions.eq("allUsers", true)); Set<T> everyone = new HashSet<T>(criteria.list()); Set<Long> ids = new HashSet<Long>(); for (Principal p : principals) { ids.add(p.getId()); } criteria = createCriteria(getResourceClass()); criteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); criteria.add(Restrictions.eq("realm", principals[0].getRealm())); criteria = criteria.createCriteria("roles"); criteria.add(Restrictions.eq("allUsers", false)); criteria = criteria.createCriteria("principals"); criteria.add(Restrictions.in("id", ids)); everyone.addAll((List<T>) criteria.list()); return everyone; }