use of org.hibernate.criterion.DetachedCriteria in project dhis2-core by dhis2.
the class HibernateGenericStore method getCriteria.
/**
* Creates a Criteria for the implementation Class type.
* <p>
* Please note that sharing is not considered.
*
* @return a Criteria instance.
*/
@Override
public final Criteria getCriteria() {
DetachedCriteria criteria = DetachedCriteria.forClass(getClazz());
preProcessDetachedCriteria(criteria);
return getExecutableCriteria(criteria);
}
use of org.hibernate.criterion.DetachedCriteria in project dhis2-core by dhis2.
the class CriteriaQueryEngine method query.
@Override
@SuppressWarnings("unchecked")
public List<T> query(Query query) {
Schema schema = query.getSchema();
InternalHibernateGenericStore<?> store = getStore((Class<? extends IdentifiableObject>) schema.getKlass());
if (store == null) {
return new ArrayList<>();
}
if (query.getUser() == null) {
query.setUser(currentUserService.getCurrentUser());
}
if (!query.isPlannedQuery()) {
QueryPlan queryPlan = queryPlanner.planQuery(query, true);
query = queryPlan.getPersistedQuery();
}
DetachedCriteria detachedCriteria = buildCriteria(store.getSharingDetachedCriteria(query.getUser()), query);
Criteria criteria = store.getCriteria();
if (criteria == null) {
return new ArrayList<>();
}
criteria.setFirstResult(query.getFirstResult());
criteria.setMaxResults(query.getMaxResults());
for (Order order : query.getOrders()) {
criteria.addOrder(getHibernateOrder(order));
}
return criteria.add(Subqueries.propertyIn("id", detachedCriteria)).list();
}
use of org.hibernate.criterion.DetachedCriteria in project dhis2-core by dhis2.
the class CriteriaQueryEngine method count.
@Override
@SuppressWarnings("unchecked")
public int count(Query query) {
Schema schema = query.getSchema();
InternalHibernateGenericStore<?> store = getStore((Class<? extends IdentifiableObject>) schema.getKlass());
if (store == null) {
return 0;
}
if (query.getUser() == null) {
query.setUser(currentUserService.getCurrentUser());
}
if (!query.isPlannedQuery()) {
QueryPlan queryPlan = queryPlanner.planQuery(query, true);
query = queryPlan.getPersistedQuery();
}
DetachedCriteria detachedCriteria = buildCriteria(store.getSharingDetachedCriteria(query.getUser()), query);
Criteria criteria = store.getCriteria();
if (criteria == null) {
return 0;
}
return ((Number) criteria.add(Subqueries.propertyIn("id", detachedCriteria)).setProjection(Projections.countDistinct("id")).uniqueResult()).intValue();
}
Aggregations