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;
}
}
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)));
}
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();
}
}
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;
}
Aggregations