Search in sources :

Example 1 with OrCondition

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

the class ReferenceRestriction method interpretInternal.

@Override
public Condition interpretInternal() throws QueryException {
    String hqlPath = hqlDataInstance.getHqlPath();
    LOGGER.trace("interpretInternal starting with hqlPath = {}", hqlPath);
    RootHibernateQuery hibernateQuery = context.getHibernateQuery();
    List<PrismReferenceValue> values = filter.getValues();
    if (CollectionUtils.isEmpty(values)) {
        return hibernateQuery.createIsNull(hqlDataInstance.getHqlPath());
    }
    Set<String> oids = new HashSet<>();
    Set<QName> relations = new HashSet<>();
    Set<QName> targetTypes = new HashSet<>();
    for (PrismReferenceValue value : values) {
        if (value.getOid() == null) {
            throw new QueryException("Null OID is not allowed in the reference query. Use empty reference list if needed.");
        }
        oids.add(value.getOid());
        if (value.getRelation() == null) {
            relations.add(SchemaConstants.ORG_DEFAULT);
        } else {
            // we intentionally don't normalize relations namespaces, to be able to do namespace-insensitive searches
            // so the caller is responsible to unify namespaces if he needs to optimize queries (use IN instead of OR)
            relations.add(value.getRelation());
        }
        targetTypes.add(qualifyTypeName(value.getTargetType()));
    }
    if (relations.size() > 1 || targetTypes.size() > 1) {
        // we must use 'OR' clause
        OrCondition rootOr = hibernateQuery.createOr();
        values.forEach(prv -> rootOr.add(createRefCondition(hibernateQuery, Collections.singleton(prv.getOid()), prv.getRelation(), prv.getTargetType())));
        return rootOr;
    } else {
        return createRefCondition(hibernateQuery, oids, MiscUtil.extractSingleton(relations), MiscUtil.extractSingleton(targetTypes));
    }
}
Also used : QueryException(com.evolveum.midpoint.repo.sql.query.QueryException) PrismReferenceValue(com.evolveum.midpoint.prism.PrismReferenceValue) RootHibernateQuery(com.evolveum.midpoint.repo.sql.query2.hqm.RootHibernateQuery) QName(javax.xml.namespace.QName) RUtil.qnameToString(com.evolveum.midpoint.repo.sql.util.RUtil.qnameToString) OrCondition(com.evolveum.midpoint.repo.sql.query2.hqm.condition.OrCondition)

Example 2 with OrCondition

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

the class PropertyRestriction method createPropertyVsPropertyCondition.

protected Condition createPropertyVsPropertyCondition(String leftPropertyValuePath) throws QueryException {
    HqlDataInstance rightItem = getItemPathResolver().resolveItemPath(filter.getRightHandSidePath(), filter.getRightHandSideDefinition(), getBaseHqlEntityForChildren(), true);
    String rightHqlPath = rightItem.getHqlPath();
    RootHibernateQuery hibernateQuery = context.getHibernateQuery();
    if (filter instanceof EqualFilter) {
        // left = right OR (left IS NULL AND right IS NULL)
        Condition condition = hibernateQuery.createCompareXY(leftPropertyValuePath, rightHqlPath, "=", false);
        OrCondition orCondition = hibernateQuery.createOr(condition, hibernateQuery.createAnd(hibernateQuery.createIsNull(leftPropertyValuePath), hibernateQuery.createIsNull(rightHqlPath)));
        return orCondition;
    } else if (filter instanceof ComparativeFilter) {
        ItemRestrictionOperation operation = findOperationForFilter(filter);
        Condition condition = hibernateQuery.createCompareXY(leftPropertyValuePath, rightHqlPath, operation.symbol(), false);
        return condition;
    } else {
        throw new QueryException("Right-side ItemPath is supported currently only for EqualFilter or ComparativeFilter, not for " + filter);
    }
}
Also used : Condition(com.evolveum.midpoint.repo.sql.query2.hqm.condition.Condition) OrCondition(com.evolveum.midpoint.repo.sql.query2.hqm.condition.OrCondition) HqlDataInstance(com.evolveum.midpoint.repo.sql.query2.resolution.HqlDataInstance) QueryException(com.evolveum.midpoint.repo.sql.query.QueryException) RootHibernateQuery(com.evolveum.midpoint.repo.sql.query2.hqm.RootHibernateQuery) ComparativeFilter(com.evolveum.midpoint.prism.query.ComparativeFilter) EqualFilter(com.evolveum.midpoint.prism.query.EqualFilter) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) OrCondition(com.evolveum.midpoint.repo.sql.query2.hqm.condition.OrCondition)

Example 3 with OrCondition

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

the class OrRestriction method interpret.

@Override
public Condition interpret() throws QueryException {
    validateFilter();
    OrCondition disjunction = getContext().getHibernateQuery().createOr();
    updateJunction(filter.getConditions(), disjunction);
    return disjunction;
}
Also used : OrCondition(com.evolveum.midpoint.repo.sql.query2.hqm.condition.OrCondition)

Aggregations

OrCondition (com.evolveum.midpoint.repo.sql.query2.hqm.condition.OrCondition)3 QueryException (com.evolveum.midpoint.repo.sql.query.QueryException)2 RootHibernateQuery (com.evolveum.midpoint.repo.sql.query2.hqm.RootHibernateQuery)2 PrismReferenceValue (com.evolveum.midpoint.prism.PrismReferenceValue)1 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)1 ComparativeFilter (com.evolveum.midpoint.prism.query.ComparativeFilter)1 EqualFilter (com.evolveum.midpoint.prism.query.EqualFilter)1 Condition (com.evolveum.midpoint.repo.sql.query2.hqm.condition.Condition)1 HqlDataInstance (com.evolveum.midpoint.repo.sql.query2.resolution.HqlDataInstance)1 RUtil.qnameToString (com.evolveum.midpoint.repo.sql.util.RUtil.qnameToString)1 QName (javax.xml.namespace.QName)1