Search in sources :

Example 1 with SqaleQueryContext

use of com.evolveum.midpoint.repo.sqale.SqaleQueryContext 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 2 with SqaleQueryContext

use of com.evolveum.midpoint.repo.sqale.SqaleQueryContext in project midpoint by Evolveum.

the class ExtensionItemFilterProcessor method processSingleReferenceValue.

private Predicate processSingleReferenceValue(MExtItem extItem, RefFilter filter, PrismReferenceValue ref) {
    // So if we ask for OID IS NULL or for target type IS NULL we actually ask "item IS NULL".
    if (ref.getOid() == null && !filter.isOidNullAsAny() || ref.getTargetType() == null && !filter.isTargetTypeNullAsAny()) {
        return extItemIsNull(extItem);
    }
    Map<String, Object> json = new HashMap<>();
    if (ref.getOid() != null) {
        json.put("o", ref.getOid());
    }
    if (ref.getTargetType() != null) {
        MObjectType objectType = MObjectType.fromTypeQName(ref.getTargetType());
        json.put("t", objectType);
    }
    if (ref.getRelation() == null || !ref.getRelation().equals(PrismConstants.Q_ANY)) {
        Integer relationId = ((SqaleQueryContext<?, ?, ?>) context).searchCachedRelationId(ref.getRelation());
        json.put("r", relationId);
    }
    return predicateWithNotTreated(path, booleanTemplate("{0} @> {1}", path, jsonbValue(extItem, json)));
}
Also used : MObjectType(com.evolveum.midpoint.repo.sqale.qmodel.object.MObjectType) SqaleQueryContext(com.evolveum.midpoint.repo.sqale.SqaleQueryContext) HashMap(java.util.HashMap) PolyString(com.evolveum.midpoint.prism.polystring.PolyString)

Example 3 with SqaleQueryContext

use of com.evolveum.midpoint.repo.sqale.SqaleQueryContext in project midpoint by Evolveum.

the class TypeFilterProcessor method process.

@Override
public Predicate process(TypeFilter filter) throws RepositoryException {
    Q path = context.path();
    // noinspection unchecked
    Class<TQ> filterQueryType = (Class<TQ>) MObjectType.fromTypeQName(filter.getType()).getQueryType();
    ObjectFilter innerFilter = filter.getFilter();
    if (path.getClass().equals(filterQueryType)) {
        // Unexpected, but let's take the shortcut.
        return innerFilter != null ? context.process(innerFilter) : QuerydslUtils.EXPRESSION_TRUE;
    // We can't just return null, we need some condition meaning "everything" for cases
    // when the filter is in OR. It can't be just no-op in such cases.
    } else {
        SqaleQueryContext<?, TQ, TR> filterContext = (SqaleQueryContext<?, TQ, TR>) context.subquery(filterQueryType);
        filterContext.sqlQuery().where(filterContext.path().oid.eq(path.oid));
        // Here we call processFilter that actually adds the WHERE conditions to the subquery.
        filterContext.processFilter(innerFilter);
        // and this fulfills the processor contract
        return filterContext.sqlQuery().exists();
    }
}
Also used : SqaleQueryContext(com.evolveum.midpoint.repo.sqale.SqaleQueryContext) ObjectFilter(com.evolveum.midpoint.prism.query.ObjectFilter)

Example 4 with SqaleQueryContext

use of com.evolveum.midpoint.repo.sqale.SqaleQueryContext in project midpoint by Evolveum.

the class RefItemFilterProcessor method processSingleValue.

private Predicate processSingleValue(RefFilter filter, PrismReferenceValue ref) {
    Predicate predicate = null;
    if (ref.getOid() != null) {
        predicate = predicateWithNotTreated(oidPath, oidPath.eq(UUID.fromString(ref.getOid())));
    } else if (!filter.isOidNullAsAny()) {
        predicate = oidPath.isNull();
    }
    // Audit sometimes does not use target type path
    if (typePath != null) {
        if (ref.getTargetType() != null) {
            MObjectType objectType = MObjectType.fromTypeQName(ref.getTargetType());
            predicate = ExpressionUtils.and(predicate, predicateWithNotTreated(typePath, typePath.eq(objectType)));
        } else if (!filter.isTargetTypeNullAsAny()) {
            predicate = ExpressionUtils.and(predicate, typePath.isNull());
        }
    }
    // Audit tables do not use relation paths
    if (relationIdPath != null) {
        if (ref.getRelation() == null || !ref.getRelation().equals(PrismConstants.Q_ANY)) {
            Integer relationId = ((SqaleQueryContext<?, ?, ?>) context).searchCachedRelationId(ref.getRelation());
            predicate = ExpressionUtils.and(predicate, predicateWithNotTreated(relationIdPath, relationIdPath.eq(relationId)));
        }
    // else relation == Q_ANY, no additional predicate needed
    }
    if (targetNamePath != null && ref.getTargetName() != null) {
        predicate = ExpressionUtils.and(predicate, predicateWithNotTreated(targetNamePath, targetNamePath.eq(ref.getTargetName().getOrig())));
    }
    return predicate;
}
Also used : MObjectType(com.evolveum.midpoint.repo.sqale.qmodel.object.MObjectType) SqaleQueryContext(com.evolveum.midpoint.repo.sqale.SqaleQueryContext) Predicate(com.querydsl.core.types.Predicate)

Aggregations

SqaleQueryContext (com.evolveum.midpoint.repo.sqale.SqaleQueryContext)4 ObjectFilter (com.evolveum.midpoint.prism.query.ObjectFilter)2 MObjectType (com.evolveum.midpoint.repo.sqale.qmodel.object.MObjectType)2 Predicate (com.querydsl.core.types.Predicate)2 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)1 CountMappingResolver (com.evolveum.midpoint.repo.sqale.mapping.CountMappingResolver)1 QueryException (com.evolveum.midpoint.repo.sqlbase.QueryException)1 ItemRelationResolver (com.evolveum.midpoint.repo.sqlbase.mapping.ItemRelationResolver)1 QueryTableMapping (com.evolveum.midpoint.repo.sqlbase.mapping.QueryTableMapping)1 HashMap (java.util.HashMap)1