use of com.evolveum.midpoint.repo.sqale.mapping.CountMappingResolver 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;
}
}
Aggregations