Search in sources :

Example 6 with QueryException

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

the class ExistsFilterProcessor method process.

private <TQ extends FlexibleRelationalPathBase<TR>, TR> Predicate process(ItemPath path, ExistsFilter filter) throws RepositoryException {
    if (path.isEmpty()) {
        ObjectFilter innerFilter = filter.getFilter();
        // empty filter means EXISTS, NOT can be added before the filter
        return innerFilter != null ? context.process(innerFilter) : null;
    }
    ItemRelationResolver<Q, R, TQ, TR> resolver = mapping.relationResolver(path);
    // "Clean" solution would require more classes/code and would be more confusing.
    if (resolver instanceof CountMappingResolver<?, ?>) {
        return ((CountMappingResolver<Q, R>) resolver).createExistsPredicate(context);
    }
    ItemRelationResolver.ResolutionResult<TQ, TR> resolution = resolver.resolve(context);
    // noinspection unchecked
    SqaleQueryContext<?, TQ, TR> subcontext = (SqaleQueryContext<?, TQ, TR>) resolution.context;
    if (!(resolution.mapping instanceof QueryTableMapping)) {
        throw new QueryException("Repository supports exists only for multi-value containers (for now)");
    }
    ExistsFilterProcessor<TQ, TR> nestedProcessor = new ExistsFilterProcessor<>(subcontext, resolution.mapping);
    Predicate predicate = nestedProcessor.process(path.rest(), filter);
    if (resolution.subquery) {
        return subcontext.sqlQuery().where(predicate).exists();
    } else {
        return predicate;
    }
}
Also used : SqaleQueryContext(com.evolveum.midpoint.repo.sqale.SqaleQueryContext) ObjectFilter(com.evolveum.midpoint.prism.query.ObjectFilter) Predicate(com.querydsl.core.types.Predicate) QueryException(com.evolveum.midpoint.repo.sqlbase.QueryException) CountMappingResolver(com.evolveum.midpoint.repo.sqale.mapping.CountMappingResolver) QueryTableMapping(com.evolveum.midpoint.repo.sqlbase.mapping.QueryTableMapping) ItemRelationResolver(com.evolveum.midpoint.repo.sqlbase.mapping.ItemRelationResolver)

Example 7 with QueryException

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

the class ExtensionItemFilterProcessor method process.

@Override
public Predicate process(ValueFilter<?, ?> filter) throws RepositoryException {
    ItemDefinition<?> definition = filter.getDefinition();
    Objects.requireNonNull(definition, "Item '" + filter.getPath() + "' without definition used in query.");
    MExtItem extItem = new ExtensionProcessor((SqaleRepoContext) context.repositoryContext()).resolveExtensionItem(definition, holderType);
    assert definition != null;
    if (extItem == null) {
        throw new QueryException("Extension item " + definition.getItemName() + " is not indexed, filter: " + filter);
    }
    if (definition instanceof PrismReferenceDefinition) {
        return processReference(extItem, (RefFilter) filter);
    }
    PropertyValueFilter<?> propertyValueFilter = (PropertyValueFilter<?>) filter;
    ValueFilterValues<?, ?> values = ValueFilterValues.from(propertyValueFilter);
    FilterOperation operation = operation(filter);
    List<?> filterValues = filter.getValues();
    if (filterValues == null || filterValues.isEmpty()) {
        if (operation.isAnyEqualOperation()) {
            return extItemIsNull(extItem);
        } else {
            throw new QueryException("Null value for other than EQUAL filter: " + filter);
        }
    }
    if (extItem.valueType.equals(STRING_TYPE)) {
        return processString(extItem, values, operation, filter);
    }
    // TODO for anything lower we don't support multi-value filter yet, but the solution from string can be adapted.
    if (filterValues.size() > 1) {
        throw new QueryException("Multiple values in filter are not supported for extension items: " + filter);
    }
    if (ExtUtils.isEnumDefinition((PrismPropertyDefinition<?>) definition)) {
        return processEnum(extItem, values, operation, filter);
    } else if (extItem.valueType.equals(INT_TYPE) || extItem.valueType.equals(INTEGER_TYPE) || extItem.valueType.equals(LONG_TYPE) || extItem.valueType.equals(SHORT_TYPE) || extItem.valueType.equals(DOUBLE_TYPE) || extItem.valueType.equals(FLOAT_TYPE) || extItem.valueType.equals(DECIMAL_TYPE)) {
        return processNumeric(extItem, values, operation, filter);
    } else if (extItem.valueType.equals(BOOLEAN_TYPE)) {
        return processBoolean(extItem, values, operation, filter);
    } else if (extItem.valueType.equals(DATETIME_TYPE)) {
        // noinspection unchecked
        PropertyValueFilter<XMLGregorianCalendar> dateTimeFilter = (PropertyValueFilter<XMLGregorianCalendar>) filter;
        return processString(extItem, ValueFilterValues.from(dateTimeFilter, ExtUtils::extensionDateTime), operation, filter);
    } else if (extItem.valueType.equals(POLY_STRING_TYPE)) {
        return processPolyString(extItem, values, operation, propertyValueFilter);
    }
    throw new QueryException("Unsupported filter for extension item: " + filter);
}
Also used : ExtUtils(com.evolveum.midpoint.repo.sqale.ExtUtils) SqaleRepoContext(com.evolveum.midpoint.repo.sqale.SqaleRepoContext) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) QueryException(com.evolveum.midpoint.repo.sqlbase.QueryException) MExtItem(com.evolveum.midpoint.repo.sqale.qmodel.ext.MExtItem) FilterOperation(com.evolveum.midpoint.repo.sqlbase.filtering.item.FilterOperation) ExtensionProcessor(com.evolveum.midpoint.repo.sqale.ExtensionProcessor) PropertyValueFilter(com.evolveum.midpoint.prism.query.PropertyValueFilter)

Example 8 with QueryException

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

the class AuditCustomColumnItemFilterProcessor method process.

@Override
public Predicate process(PropertyValueFilter<AuditEventRecordCustomColumnPropertyType> filter) throws QueryException {
    // This is a tricky situation, if multi-value, each value can have different path (derived
    // from AuditEventRecordCustomColumnPropertyType.getName()), so we can't use this directly.
    ValueFilterValues<AuditEventRecordCustomColumnPropertyType, ?> values = ValueFilterValues.from(filter);
    if (values.isEmpty()) {
        throw new QueryException("Custom column null value is not supported," + " column can't be determined from filter: " + filter);
    }
    if (values.isMultiValue()) {
        Predicate predicate = null;
        for (AuditEventRecordCustomColumnPropertyType propertyType : values.allValuesRaw()) {
            Predicate right = createPredicate(filter, propertyType);
            predicate = predicate != null ? ExpressionUtils.or(predicate, right) : right;
        }
        return predicate;
    }
    AuditEventRecordCustomColumnPropertyType value = values.singleValueRaw();
    assert value != null;
    return createPredicate(filter, value);
}
Also used : AuditEventRecordCustomColumnPropertyType(com.evolveum.midpoint.xml.ns._public.common.audit_3.AuditEventRecordCustomColumnPropertyType) QueryException(com.evolveum.midpoint.repo.sqlbase.QueryException) Predicate(com.querydsl.core.types.Predicate)

Example 9 with QueryException

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

the class AuditCustomColumnItemFilterProcessor method createPredicate.

private Predicate createPredicate(PropertyValueFilter<AuditEventRecordCustomColumnPropertyType> filter, AuditEventRecordCustomColumnPropertyType customColumnPropertyType) throws QueryException {
    FilterOperation operation = operation(filter);
    Path<?> path = context.path().getPath(customColumnPropertyType.getName());
    if (customColumnPropertyType.getValue() == null) {
        if (operation.isAnyEqualOperation()) {
            return ExpressionUtils.predicate(Ops.IS_NULL, path);
        } else {
            throw new QueryException("Null value for other than EQUAL filter: " + filter);
        }
    }
    return singleValuePredicate(path, operation, customColumnPropertyType.getValue());
}
Also used : QueryException(com.evolveum.midpoint.repo.sqlbase.QueryException) FilterOperation(com.evolveum.midpoint.repo.sqlbase.filtering.item.FilterOperation)

Example 10 with QueryException

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

the class RAnyConverter method getAnySetType.

/**
 * This method provides extension type (in real it's table) string for definition and value
 * defined as parameters.
 *
 * @return One of "strings", "longs", "dates", "clobs"
 */
public static String getAnySetType(ItemDefinition definition, PrismContext prismContext) throws SchemaException, QueryException {
    if (!isIndexed(definition, definition.getItemName(), true, prismContext)) {
        throw new QueryException("Can't query non-indexed value for '" + definition.getItemName() + "', definition " + definition);
    }
    QName typeName = definition.getTypeName();
    ValueType valueType = getValueType(typeName);
    switch(valueType) {
        case BOOLEAN:
            return "booleans";
        case DATE:
            return "dates";
        case LONG:
            return "longs";
        case STRING:
        default:
            return "strings";
    }
}
Also used : QueryException(com.evolveum.midpoint.repo.sqlbase.QueryException) QName(javax.xml.namespace.QName)

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