Search in sources :

Example 1 with ItemRelationResolver

use of com.evolveum.midpoint.repo.sqlbase.mapping.ItemRelationResolver 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)

Aggregations

ObjectFilter (com.evolveum.midpoint.prism.query.ObjectFilter)1 SqaleQueryContext (com.evolveum.midpoint.repo.sqale.SqaleQueryContext)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 Predicate (com.querydsl.core.types.Predicate)1