Search in sources :

Example 21 with QueryException

use of com.evolveum.midpoint.repo.sqlbase.QueryException 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<>();
    boolean valuesWithWildcardOid = false;
    boolean valuesWithSpecifiedOid = false;
    for (PrismReferenceValue value : values) {
        if (value.getOid() != null) {
            oids.add(value.getOid());
            valuesWithSpecifiedOid = true;
        } else {
            if (filter.isOidNullAsAny()) {
                valuesWithWildcardOid = true;
            } else {
                throw new QueryException("Null OID is not allowed in the reference query. " + "If you'd like to search for missing reference, use empty list of values.");
            }
        }
        if (value.getRelation() == null) {
            relations.add(context.getPrismContext().getDefaultRelation());
        } 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 (valuesWithWildcardOid && valuesWithSpecifiedOid || relations.size() > 1 || targetTypes.size() > 1) {
        // We must use 'OR' clause
        OrCondition rootOr = hibernateQuery.createOr();
        values.forEach(prv -> rootOr.add(createRefCondition(hibernateQuery, MiscUtil.singletonOrEmptySet(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.sqlbase.QueryException) PrismReferenceValue(com.evolveum.midpoint.prism.PrismReferenceValue) RootHibernateQuery(com.evolveum.midpoint.repo.sql.query.hqm.RootHibernateQuery) QName(javax.xml.namespace.QName) OrCondition(com.evolveum.midpoint.repo.sql.query.hqm.condition.OrCondition)

Example 22 with QueryException

use of com.evolveum.midpoint.repo.sqlbase.QueryException in project midpoint by Evolveum.

the class ItemValueRestriction method findOperationForFilter.

ItemRestrictionOperation findOperationForFilter(ValueFilter filter) throws QueryException {
    ItemRestrictionOperation operation;
    if (filter instanceof EqualFilter) {
        operation = ItemRestrictionOperation.EQ;
    } else if (filter instanceof GreaterFilter) {
        GreaterFilter gf = (GreaterFilter) filter;
        operation = gf.isEquals() ? ItemRestrictionOperation.GE : ItemRestrictionOperation.GT;
    } else if (filter instanceof LessFilter) {
        LessFilter lf = (LessFilter) filter;
        operation = lf.isEquals() ? ItemRestrictionOperation.LE : ItemRestrictionOperation.LT;
    } else if (filter instanceof SubstringFilter) {
        SubstringFilter substring = (SubstringFilter) filter;
        if (substring.isAnchorEnd()) {
            operation = ItemRestrictionOperation.ENDS_WITH;
        } else if (substring.isAnchorStart()) {
            operation = ItemRestrictionOperation.STARTS_WITH;
        } else {
            operation = ItemRestrictionOperation.SUBSTRING;
        }
    } else {
        throw new QueryException("Can't translate filter '" + filter + "' to operation.");
    }
    return operation;
}
Also used : QueryException(com.evolveum.midpoint.repo.sqlbase.QueryException)

Example 23 with QueryException

use of com.evolveum.midpoint.repo.sqlbase.QueryException in project midpoint by Evolveum.

the class ItemValueRestriction method interpret.

@Override
public Condition interpret() throws QueryException {
    ItemPath path = getItemPath();
    if (ItemPath.isEmpty(path)) {
        throw new QueryException("Null or empty path for ItemValueRestriction in " + filter.debugDump());
    }
    HqlDataInstance dataInstance = getItemPathResolver().resolveItemPath(path, itemDefinition, getBaseHqlEntity(), false);
    setHqlDataInstance(dataInstance);
    return interpretInternal();
}
Also used : QueryException(com.evolveum.midpoint.repo.sqlbase.QueryException) HqlDataInstance(com.evolveum.midpoint.repo.sql.query.resolution.HqlDataInstance) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 24 with QueryException

use of com.evolveum.midpoint.repo.sqlbase.QueryException in project midpoint by Evolveum.

the class PropertyRestriction method createPropertyVsPropertyCondition.

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);
        return hibernateQuery.createOr(condition, hibernateQuery.createAnd(hibernateQuery.createIsNull(leftPropertyValuePath), hibernateQuery.createIsNull(rightHqlPath)));
    } else if (filter instanceof ComparativeFilter) {
        ItemRestrictionOperation operation = findOperationForFilter(filter);
        return hibernateQuery.createCompareXY(leftPropertyValuePath, rightHqlPath, operation.symbol(), false);
    } else {
        throw new QueryException("Right-side ItemPath is supported currently only for EqualFilter or ComparativeFilter, not for " + filter);
    }
}
Also used : ConstantCondition(com.evolveum.midpoint.repo.sql.query.hqm.condition.ConstantCondition) Condition(com.evolveum.midpoint.repo.sql.query.hqm.condition.Condition) HqlDataInstance(com.evolveum.midpoint.repo.sql.query.resolution.HqlDataInstance) QueryException(com.evolveum.midpoint.repo.sqlbase.QueryException) RootHibernateQuery(com.evolveum.midpoint.repo.sql.query.hqm.RootHibernateQuery) ComparativeFilter(com.evolveum.midpoint.prism.query.ComparativeFilter) EqualFilter(com.evolveum.midpoint.prism.query.EqualFilter) PolyString(com.evolveum.midpoint.prism.polystring.PolyString)

Example 25 with QueryException

use of com.evolveum.midpoint.repo.sqlbase.QueryException in project midpoint by Evolveum.

the class PropertyRestriction method interpretInternal.

@Override
public Condition interpretInternal() throws QueryException {
    JpaPropertyDefinition propertyDefinition = linkDefinition.getTargetDefinition();
    if (propertyDefinition.isLob()) {
        throw new QueryException("Can't query based on clob property value '" + linkDefinition + "'.");
    }
    String propertyValuePath = getHqlDataInstance().getHqlPath();
    if (filter.getRightHandSidePath() != null) {
        return createPropertyVsPropertyCondition(propertyValuePath);
    } else {
        Object value = getValueFromFilter(filter);
        if (value == null && propertyDefinition.isNeverNull()) {
            LOGGER.warn("Checking nullity of non-null property {} (filter = {})", propertyDefinition, filter);
            return new ConstantCondition(context.getHibernateQuery(), false);
        } else {
            Condition condition = createPropertyVsConstantCondition(propertyValuePath, value, filter);
            return addIsNotNullIfNecessary(condition, propertyValuePath);
        }
    }
}
Also used : ConstantCondition(com.evolveum.midpoint.repo.sql.query.hqm.condition.ConstantCondition) Condition(com.evolveum.midpoint.repo.sql.query.hqm.condition.Condition) QueryException(com.evolveum.midpoint.repo.sqlbase.QueryException) ConstantCondition(com.evolveum.midpoint.repo.sql.query.hqm.condition.ConstantCondition) JpaPropertyDefinition(com.evolveum.midpoint.repo.sql.query.definition.JpaPropertyDefinition) PolyString(com.evolveum.midpoint.prism.polystring.PolyString)

Aggregations

QueryException (com.evolveum.midpoint.repo.sqlbase.QueryException)46 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)9 QName (javax.xml.namespace.QName)9 RootHibernateQuery (com.evolveum.midpoint.repo.sql.query.hqm.RootHibernateQuery)8 Predicate (com.querydsl.core.types.Predicate)8 QueryEngine (com.evolveum.midpoint.repo.sql.query.QueryEngine)6 PropertyValueFilter (com.evolveum.midpoint.prism.query.PropertyValueFilter)5 RQuery (com.evolveum.midpoint.repo.sql.query.RQuery)5 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)4 Condition (com.evolveum.midpoint.repo.sql.query.hqm.condition.Condition)4 FilterOperation (com.evolveum.midpoint.repo.sqlbase.filtering.item.FilterOperation)4 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)4 RPolyString (com.evolveum.midpoint.repo.sql.data.common.embedded.RPolyString)3 HqlDataInstance (com.evolveum.midpoint.repo.sql.query.resolution.HqlDataInstance)3 RepositoryException (com.evolveum.midpoint.repo.sqlbase.RepositoryException)3 ItemRelationResolver (com.evolveum.midpoint.repo.sqlbase.mapping.ItemRelationResolver)3 NotNull (org.jetbrains.annotations.NotNull)3 EqualFilter (com.evolveum.midpoint.prism.query.EqualFilter)2 ValueFilter (com.evolveum.midpoint.prism.query.ValueFilter)2 ExtensionProcessor (com.evolveum.midpoint.repo.sqale.ExtensionProcessor)2