Search in sources :

Example 1 with Conjunction

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;
}
Also used : Restriction(org.hisp.dhis.query.Restriction) Disjunction(org.hisp.dhis.query.Disjunction) Criterion(org.hisp.dhis.query.Criterion) Conjunction(org.hisp.dhis.query.Conjunction) Criterion(org.hisp.dhis.query.Criterion) Junction(org.hisp.dhis.query.Junction)

Aggregations

Conjunction (org.hisp.dhis.query.Conjunction)1 Criterion (org.hisp.dhis.query.Criterion)1 Disjunction (org.hisp.dhis.query.Disjunction)1 Junction (org.hisp.dhis.query.Junction)1 Restriction (org.hisp.dhis.query.Restriction)1