Search in sources :

Example 1 with AndCondition

use of com.evolveum.midpoint.repo.sql.query.hqm.condition.AndCondition in project midpoint by Evolveum.

the class ItemPathResolver method createJoinCondition.

private Condition createJoinCondition(String joinedItemAlias, JpaLinkDefinition<?> joinedItemDefinition, RootHibernateQuery hibernateQuery) throws QueryException {
    Condition condition = null;
    if (joinedItemDefinition instanceof JpaAnyItemLinkDefinition) {
        JpaAnyItemLinkDefinition anyLinkDef = (JpaAnyItemLinkDefinition) joinedItemDefinition;
        AndCondition conjunction = hibernateQuery.createAnd();
        if (anyLinkDef.getOwnerType() != null) {
            // null for assignment extensions
            conjunction.add(hibernateQuery.createEq(joinedItemAlias + ".ownerType", anyLinkDef.getOwnerType()));
        }
        ExtItemDictionary dictionary = context.getExtItemDictionary();
        RExtItem extItemDefinition = dictionary.findItemByDefinition(anyLinkDef.getItemDefinition());
        if (extItemDefinition != null) {
            conjunction.add(hibernateQuery.createEq(joinedItemAlias + "." + RAnyValue.F_ITEM_ID, extItemDefinition.getId()));
        } else {
            // there are no rows referencing this item, because it does not exist in RExtItem (yet)
            conjunction.add(hibernateQuery.createFalse());
        }
        condition = conjunction;
    } else if (joinedItemDefinition.getCollectionSpecification() instanceof VirtualCollectionSpecification) {
        VirtualCollectionSpecification vcd = (VirtualCollectionSpecification) joinedItemDefinition.getCollectionSpecification();
        List<Condition> conditions = new ArrayList<>(vcd.getAdditionalParams().length);
        for (VirtualQueryParam vqp : vcd.getAdditionalParams()) {
            // e.g. name = "assignmentOwner", type = RAssignmentOwner.class, value = "ABSTRACT_ROLE"
            Object value = createQueryParamValue(vqp);
            Condition c = hibernateQuery.createEq(joinedItemAlias + "." + vqp.name(), value);
            conditions.add(c);
        }
        if (conditions.size() > 1) {
            condition = hibernateQuery.createAnd(conditions);
        } else if (conditions.size() == 1) {
            condition = conditions.iterator().next();
        }
    }
    return condition;
}
Also used : AndCondition(com.evolveum.midpoint.repo.sql.query.hqm.condition.AndCondition) Condition(com.evolveum.midpoint.repo.sql.query.hqm.condition.Condition) ExtItemDictionary(com.evolveum.midpoint.repo.sql.data.common.dictionary.ExtItemDictionary) ArrayList(java.util.ArrayList) List(java.util.List) RObject(com.evolveum.midpoint.repo.sql.data.common.RObject) RExtItem(com.evolveum.midpoint.repo.sql.data.common.any.RExtItem) AndCondition(com.evolveum.midpoint.repo.sql.query.hqm.condition.AndCondition)

Example 2 with AndCondition

use of com.evolveum.midpoint.repo.sql.query.hqm.condition.AndCondition in project midpoint by Evolveum.

the class ReferenceRestriction method createRefCondition.

private Condition createRefCondition(RootHibernateQuery hibernateQuery, Collection<String> oids, QName relation, QName targetType) {
    String hqlPath = hqlDataInstance.getHqlPath();
    final String targetOidHqlProperty, relationHqlProperty, targetTypeHqlProperty;
    if (linkDefinition.getTargetDefinition() instanceof JpaAnyReferenceDefinition) {
        targetOidHqlProperty = ROExtReference.F_TARGET_OID;
        relationHqlProperty = ROExtReference.F_RELATION;
        targetTypeHqlProperty = ROExtReference.F_TARGET_TYPE;
    } else {
        targetOidHqlProperty = RObjectReference.F_TARGET_OID;
        relationHqlProperty = RObjectReference.F_RELATION;
        targetTypeHqlProperty = RObjectReference.F_TARGET_TYPE;
    }
    AndCondition conjunction = hibernateQuery.createAnd();
    if (CollectionUtils.isNotEmpty(oids)) {
        conjunction.add(hibernateQuery.createEqOrInOrNull(hqlDataInstance.getHqlPath() + "." + targetOidHqlProperty, oids));
    }
    List<String> relationsToTest = getRelationsToTest(relation, getContext());
    if (!relationsToTest.isEmpty()) {
        conjunction.add(hibernateQuery.createEqOrInOrNull(hqlPath + "." + relationHqlProperty, relationsToTest));
    }
    if (targetType != null) {
        conjunction.add(handleEqInOrNull(hibernateQuery, hqlPath + "." + targetTypeHqlProperty, ClassMapper.getHQLTypeForQName(targetType)));
    }
    return conjunction;
}
Also used : JpaAnyReferenceDefinition(com.evolveum.midpoint.repo.sql.query.definition.JpaAnyReferenceDefinition) AndCondition(com.evolveum.midpoint.repo.sql.query.hqm.condition.AndCondition)

Example 3 with AndCondition

use of com.evolveum.midpoint.repo.sql.query.hqm.condition.AndCondition 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.
 * <p>
 * Such a filter has to be treated like
 * <p>
 * NOT (PROPERTY=VALUE & PROPERTY IS NOT NULL)
 * <p>
 * TODO implement for restrictions other than PropertyRestriction.
 */
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.query.hqm.condition.IsNotNullCondition) RootHibernateQuery(com.evolveum.midpoint.repo.sql.query.hqm.RootHibernateQuery) IsNullCondition(com.evolveum.midpoint.repo.sql.query.hqm.condition.IsNullCondition) AndCondition(com.evolveum.midpoint.repo.sql.query.hqm.condition.AndCondition)

Example 4 with AndCondition

use of com.evolveum.midpoint.repo.sql.query.hqm.condition.AndCondition in project midpoint by Evolveum.

the class AndRestriction method interpret.

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

Example 5 with AndCondition

use of com.evolveum.midpoint.repo.sql.query.hqm.condition.AndCondition in project midpoint by Evolveum.

the class PolyStringMatcher method match.

@Override
public Condition match(RootHibernateQuery hibernateQuery, ItemRestrictionOperation operation, String propertyName, PolyString value, String matcher) throws QueryException {
    boolean ignoreCase = STRICT_IGNORE_CASE.equals(matcher) || ORIG_IGNORE_CASE.equals(matcher) || NORM_IGNORE_CASE.equals(matcher);
    if (Strings.isNullOrEmpty(matcher) || DEFAULT.equals(matcher) || STRICT.equals(matcher) || STRICT_IGNORE_CASE.equals(matcher)) {
        AndCondition conjunction = hibernateQuery.createAnd();
        conjunction.add(createOrigMatch(hibernateQuery, operation, propertyName, value, ignoreCase));
        conjunction.add(createNormMatch(hibernateQuery, operation, propertyName, value, ignoreCase));
        return conjunction;
    } else if (ORIG.equals(matcher) || ORIG_IGNORE_CASE.equals(matcher)) {
        return createOrigMatch(hibernateQuery, operation, propertyName, value, ignoreCase);
    } else if (NORM.equals(matcher) || NORM_IGNORE_CASE.equals(matcher)) {
        return createNormMatch(hibernateQuery, operation, propertyName, value, ignoreCase);
    } else {
        throw new QueryException("Unknown matcher '" + matcher + "'.");
    }
}
Also used : QueryException(com.evolveum.midpoint.repo.sqlbase.QueryException) AndCondition(com.evolveum.midpoint.repo.sql.query.hqm.condition.AndCondition)

Aggregations

AndCondition (com.evolveum.midpoint.repo.sql.query.hqm.condition.AndCondition)5 RObject (com.evolveum.midpoint.repo.sql.data.common.RObject)1 RExtItem (com.evolveum.midpoint.repo.sql.data.common.any.RExtItem)1 ExtItemDictionary (com.evolveum.midpoint.repo.sql.data.common.dictionary.ExtItemDictionary)1 JpaAnyReferenceDefinition (com.evolveum.midpoint.repo.sql.query.definition.JpaAnyReferenceDefinition)1 RootHibernateQuery (com.evolveum.midpoint.repo.sql.query.hqm.RootHibernateQuery)1 Condition (com.evolveum.midpoint.repo.sql.query.hqm.condition.Condition)1 IsNotNullCondition (com.evolveum.midpoint.repo.sql.query.hqm.condition.IsNotNullCondition)1 IsNullCondition (com.evolveum.midpoint.repo.sql.query.hqm.condition.IsNullCondition)1 QueryException (com.evolveum.midpoint.repo.sqlbase.QueryException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1