use of org.hisp.dhis.query.Conjunction in project dhis2-core by dhis2.
the class DefaultQueryPlanner method handleJunction.
private Junction handleJunction(Query query, Junction queryJunction, boolean persistedOnly) {
Iterator<org.hisp.dhis.query.Criterion> iterator = queryJunction.getCriterions().iterator();
Junction criteriaJunction = Disjunction.class.isInstance(queryJunction) ? new Disjunction(query.getSchema()) : new Conjunction(query.getSchema());
while (iterator.hasNext()) {
org.hisp.dhis.query.Criterion criterion = iterator.next();
if (Junction.class.isInstance(criterion)) {
Junction junction = handleJunction(query, (Junction) criterion, persistedOnly);
if (!junction.getCriterions().isEmpty()) {
criteriaJunction.getAliases().addAll(junction.getAliases());
criteriaJunction.add(junction);
}
if (((Junction) criterion).getCriterions().isEmpty()) {
iterator.remove();
}
} else if (Restriction.class.isInstance(criterion)) {
Restriction restriction = (Restriction) criterion;
restriction.setQueryPath(getQueryPath(query.getSchema(), restriction.getPath()));
if (restriction.getQueryPath().isPersisted() && !restriction.getQueryPath().haveAlias(1)) {
criteriaJunction.getAliases().addAll(Arrays.asList(((Restriction) criterion).getQueryPath().getAlias()));
criteriaJunction.getCriterions().add(criterion);
iterator.remove();
} else if (persistedOnly) {
throw new RuntimeException("Path " + restriction.getQueryPath().getPath() + " is not fully persisted, unable to build persisted only query plan.");
}
}
}
return criteriaJunction;
}
Aggregations