Search in sources :

Example 6 with Condition

use of com.evolveum.midpoint.repo.sql.query2.hqm.condition.Condition in project midpoint by Evolveum.

the class AnyPropertyRestriction method interpretInternal.

@Override
public Condition interpretInternal() throws QueryException {
    String propertyValuePath = getHqlDataInstance().getHqlPath();
    if (filter.getRightHandSidePath() != null) {
        return createPropertyVsPropertyCondition(propertyValuePath);
    } else {
        Object value = RAnyConverter.getAggregatedRepoObject(getValue(filter));
        Condition c = createPropertyVsConstantCondition(propertyValuePath, value, filter);
        return addIsNotNullIfNecessary(c, propertyValuePath);
    }
}
Also used : Condition(com.evolveum.midpoint.repo.sql.query2.hqm.condition.Condition)

Example 7 with Condition

use of com.evolveum.midpoint.repo.sql.query2.hqm.condition.Condition 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 8 with Condition

use of com.evolveum.midpoint.repo.sql.query2.hqm.condition.Condition in project midpoint by Evolveum.

the class ItemValueRestriction method addIsNotNullIfNecessary.

/**
     * Filter of type NOT(PROPERTY=VALUE) causes problems when there are entities with PROPERTY set to NULL.
     *
     * Such a filter has to be treated like
     *
     *      NOT (PROPERTY=VALUE & PROPERTY IS NOT NULL)
     *
     * TODO implement for restrictions other than PropertyRestriction.
     */
protected Condition addIsNotNullIfNecessary(Condition condition, String propertyPath) {
    if (condition instanceof IsNullCondition || condition instanceof IsNotNullCondition) {
        return condition;
    }
    if (!isNegated()) {
        return condition;
    }
    RootHibernateQuery hibernateQuery = getContext().getHibernateQuery();
    AndCondition conjunction = hibernateQuery.createAnd();
    conjunction.add(condition);
    conjunction.add(hibernateQuery.createIsNotNull(propertyPath));
    return conjunction;
}
Also used : IsNotNullCondition(com.evolveum.midpoint.repo.sql.query2.hqm.condition.IsNotNullCondition) RootHibernateQuery(com.evolveum.midpoint.repo.sql.query2.hqm.RootHibernateQuery) IsNullCondition(com.evolveum.midpoint.repo.sql.query2.hqm.condition.IsNullCondition) AndCondition(com.evolveum.midpoint.repo.sql.query2.hqm.condition.AndCondition)

Example 9 with Condition

use of com.evolveum.midpoint.repo.sql.query2.hqm.condition.Condition 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 10 with Condition

use of com.evolveum.midpoint.repo.sql.query2.hqm.condition.Condition 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)

Aggregations

Condition (com.evolveum.midpoint.repo.sql.query2.hqm.condition.Condition)12 QueryException (com.evolveum.midpoint.repo.sql.query.QueryException)8 RootHibernateQuery (com.evolveum.midpoint.repo.sql.query2.hqm.RootHibernateQuery)8 AndCondition (com.evolveum.midpoint.repo.sql.query2.hqm.condition.AndCondition)7 QueryInterpreter2 (com.evolveum.midpoint.repo.sql.query2.QueryInterpreter2)5 InterpretationContext (com.evolveum.midpoint.repo.sql.query2.InterpretationContext)4 OrCondition (com.evolveum.midpoint.repo.sql.query2.hqm.condition.OrCondition)4 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)3 HqlDataInstance (com.evolveum.midpoint.repo.sql.query2.resolution.HqlDataInstance)3 IsNotNullCondition (com.evolveum.midpoint.repo.sql.query2.hqm.condition.IsNotNullCondition)2 IsNullCondition (com.evolveum.midpoint.repo.sql.query2.hqm.condition.IsNullCondition)2 RUtil.qnameToString (com.evolveum.midpoint.repo.sql.util.RUtil.qnameToString)2 QName (javax.xml.namespace.QName)2 PrismReferenceValue (com.evolveum.midpoint.prism.PrismReferenceValue)1 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)1 AllFilter (com.evolveum.midpoint.prism.query.AllFilter)1 ComparativeFilter (com.evolveum.midpoint.prism.query.ComparativeFilter)1 EqualFilter (com.evolveum.midpoint.prism.query.EqualFilter)1 ObjectFilter (com.evolveum.midpoint.prism.query.ObjectFilter)1 ObjectPagingAfterOid (com.evolveum.midpoint.repo.sql.ObjectPagingAfterOid)1