use of org.hisp.dhis.query.planner.QueryPlan in project dhis2-core by dhis2.
the class DefaultQueryService method queryObjects.
//---------------------------------------------------------------------------------------------
// Helper methods
//---------------------------------------------------------------------------------------------
private List<? extends IdentifiableObject> queryObjects(Query query) {
List<? extends IdentifiableObject> objects = query.getObjects();
if (objects != null) {
return inMemoryQueryEngine.query(query.setObjects(objects));
}
QueryPlan queryPlan = queryPlanner.planQuery(query);
Query pQuery = queryPlan.getPersistedQuery();
Query npQuery = queryPlan.getNonPersistedQuery();
objects = criteriaQueryEngine.query(pQuery);
if (npQuery.isEmpty()) {
return objects;
}
if (log.isDebugEnabled()) {
log.debug("Doing in-memory for " + npQuery.getCriterions().size() + " criterions and " + npQuery.getOrders().size() + " orders.");
}
npQuery.setObjects(objects);
return inMemoryQueryEngine.query(npQuery);
}
use of org.hisp.dhis.query.planner.QueryPlan 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.hisp.dhis.query.planner.QueryPlan 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