Search in sources :

Example 1 with QueryInterpreter2

use of com.evolveum.midpoint.repo.sql.query2.QueryInterpreter2 in project midpoint by Evolveum.

the class ExistsRestriction method interpret.

@Override
public Condition interpret() throws QueryException {
    HqlDataInstance dataInstance = getItemPathResolver().resolveItemPath(filter.getFullPath(), filter.getDefinition(), getBaseHqlEntity(), false);
    boolean isAll = filter.getFilter() == null || filter.getFilter() instanceof AllFilter;
    JpaDataNodeDefinition jpaDefinition = dataInstance.getJpaDefinition();
    if (!isAll) {
        if (!(jpaDefinition instanceof JpaEntityDefinition)) {
            // partially checked already (for non-null-ness)
            throw new QueryException("ExistsRestriction with non-empty subfilter points to non-entity node: " + jpaDefinition);
        }
        setHqlDataInstance(dataInstance);
        QueryInterpreter2 interpreter = context.getInterpreter();
        return interpreter.interpretFilter(context, filter.getFilter(), this);
    } else if (jpaDefinition instanceof JpaPropertyDefinition && (((JpaPropertyDefinition) jpaDefinition).isCount())) {
        RootHibernateQuery hibernateQuery = context.getHibernateQuery();
        return hibernateQuery.createSimpleComparisonCondition(dataInstance.getHqlPath(), 0, ">");
    } else {
        // TODO support exists also for other properties (single valued or multi valued)
        throw new UnsupportedOperationException("Exists filter with 'all' subfilter is currently not supported");
    }
}
Also used : JpaDataNodeDefinition(com.evolveum.midpoint.repo.sql.query2.definition.JpaDataNodeDefinition) HqlDataInstance(com.evolveum.midpoint.repo.sql.query2.resolution.HqlDataInstance) QueryException(com.evolveum.midpoint.repo.sql.query.QueryException) AllFilter(com.evolveum.midpoint.prism.query.AllFilter) RootHibernateQuery(com.evolveum.midpoint.repo.sql.query2.hqm.RootHibernateQuery) JpaEntityDefinition(com.evolveum.midpoint.repo.sql.query2.definition.JpaEntityDefinition) JpaPropertyDefinition(com.evolveum.midpoint.repo.sql.query2.definition.JpaPropertyDefinition) QueryInterpreter2(com.evolveum.midpoint.repo.sql.query2.QueryInterpreter2)

Example 2 with QueryInterpreter2

use of com.evolveum.midpoint.repo.sql.query2.QueryInterpreter2 in project midpoint by Evolveum.

the class ItemValueRestriction method createPropertyVsConstantCondition.

protected Condition createPropertyVsConstantCondition(String hqlPropertyPath, Object value, ValueFilter filter) throws QueryException {
    ItemRestrictionOperation operation = findOperationForFilter(filter);
    InterpretationContext context = getContext();
    QueryInterpreter2 interpreter = context.getInterpreter();
    Matcher matcher = interpreter.findMatcher(value);
    String matchingRule = filter.getMatchingRule() != null ? filter.getMatchingRule().getLocalPart() : null;
    // TODO treat null for multivalued properties (at least throw an exception!)
    return matcher.match(context.getHibernateQuery(), operation, hqlPropertyPath, value, matchingRule);
}
Also used : InterpretationContext(com.evolveum.midpoint.repo.sql.query2.InterpretationContext) Matcher(com.evolveum.midpoint.repo.sql.query2.matcher.Matcher) QueryInterpreter2(com.evolveum.midpoint.repo.sql.query2.QueryInterpreter2)

Example 3 with QueryInterpreter2

use of com.evolveum.midpoint.repo.sql.query2.QueryInterpreter2 in project midpoint by Evolveum.

the class NaryLogicalRestriction method updateJunction.

protected void updateJunction(List<? extends ObjectFilter> subfilters, JunctionCondition junction) throws QueryException {
    InterpretationContext context = getContext();
    QueryInterpreter2 interpreter = context.getInterpreter();
    for (ObjectFilter subfilter : subfilters) {
        Condition condition = interpreter.interpretFilter(context, subfilter, this);
        junction.add(condition);
    }
}
Also used : Condition(com.evolveum.midpoint.repo.sql.query2.hqm.condition.Condition) JunctionCondition(com.evolveum.midpoint.repo.sql.query2.hqm.condition.JunctionCondition) InterpretationContext(com.evolveum.midpoint.repo.sql.query2.InterpretationContext) ObjectFilter(com.evolveum.midpoint.prism.query.ObjectFilter) QueryInterpreter2(com.evolveum.midpoint.repo.sql.query2.QueryInterpreter2)

Example 4 with QueryInterpreter2

use of com.evolveum.midpoint.repo.sql.query2.QueryInterpreter2 in project midpoint by Evolveum.

the class TypeRestriction method interpret.

@Override
public Condition interpret() throws QueryException {
    InterpretationContext context = getContext();
    RootHibernateQuery hibernateQuery = context.getHibernateQuery();
    String property = getBaseHqlEntity().getHqlPath() + "." + RObject.F_OBJECT_TYPE_CLASS;
    Set<RObjectType> values = getValues(filter.getType());
    Condition basedOnType;
    if (values.size() > 1) {
        basedOnType = hibernateQuery.createIn(property, values);
    } else {
        basedOnType = hibernateQuery.createEq(property, values.iterator().next());
    }
    if (filter.getFilter() == null) {
        return basedOnType;
    }
    QueryInterpreter2 interpreter = context.getInterpreter();
    Condition basedOnFilter = interpreter.interpretFilter(context, filter.getFilter(), this);
    return hibernateQuery.createAnd(basedOnType, basedOnFilter);
}
Also used : Condition(com.evolveum.midpoint.repo.sql.query2.hqm.condition.Condition) RObjectType(com.evolveum.midpoint.repo.sql.data.common.other.RObjectType) InterpretationContext(com.evolveum.midpoint.repo.sql.query2.InterpretationContext) RootHibernateQuery(com.evolveum.midpoint.repo.sql.query2.hqm.RootHibernateQuery) QueryInterpreter2(com.evolveum.midpoint.repo.sql.query2.QueryInterpreter2)

Example 5 with QueryInterpreter2

use of com.evolveum.midpoint.repo.sql.query2.QueryInterpreter2 in project midpoint by Evolveum.

the class UnaryLogicalRestriction method interpretChildFilter.

protected Condition interpretChildFilter() throws QueryException {
    InterpretationContext context = getContext();
    QueryInterpreter2 interpreter = context.getInterpreter();
    return interpreter.interpretFilter(context, filter.getFilter(), this);
}
Also used : InterpretationContext(com.evolveum.midpoint.repo.sql.query2.InterpretationContext) QueryInterpreter2(com.evolveum.midpoint.repo.sql.query2.QueryInterpreter2)

Aggregations

QueryInterpreter2 (com.evolveum.midpoint.repo.sql.query2.QueryInterpreter2)5 InterpretationContext (com.evolveum.midpoint.repo.sql.query2.InterpretationContext)4 RootHibernateQuery (com.evolveum.midpoint.repo.sql.query2.hqm.RootHibernateQuery)3 Condition (com.evolveum.midpoint.repo.sql.query2.hqm.condition.Condition)2 AllFilter (com.evolveum.midpoint.prism.query.AllFilter)1 ObjectFilter (com.evolveum.midpoint.prism.query.ObjectFilter)1 RObjectType (com.evolveum.midpoint.repo.sql.data.common.other.RObjectType)1 QueryException (com.evolveum.midpoint.repo.sql.query.QueryException)1 JpaDataNodeDefinition (com.evolveum.midpoint.repo.sql.query2.definition.JpaDataNodeDefinition)1 JpaEntityDefinition (com.evolveum.midpoint.repo.sql.query2.definition.JpaEntityDefinition)1 JpaPropertyDefinition (com.evolveum.midpoint.repo.sql.query2.definition.JpaPropertyDefinition)1 JunctionCondition (com.evolveum.midpoint.repo.sql.query2.hqm.condition.JunctionCondition)1 Matcher (com.evolveum.midpoint.repo.sql.query2.matcher.Matcher)1 HqlDataInstance (com.evolveum.midpoint.repo.sql.query2.resolution.HqlDataInstance)1