use of com.evolveum.midpoint.repo.sql.query2.hqm.condition.OrCondition in project midpoint by Evolveum.
the class ReferenceRestriction method interpretInternal.
@Override
public Condition interpretInternal() throws QueryException {
String hqlPath = hqlDataInstance.getHqlPath();
LOGGER.trace("interpretInternal starting with hqlPath = {}", hqlPath);
RootHibernateQuery hibernateQuery = context.getHibernateQuery();
List<PrismReferenceValue> values = filter.getValues();
if (CollectionUtils.isEmpty(values)) {
return hibernateQuery.createIsNull(hqlDataInstance.getHqlPath());
}
Set<String> oids = new HashSet<>();
Set<QName> relations = new HashSet<>();
Set<QName> targetTypes = new HashSet<>();
for (PrismReferenceValue value : values) {
if (value.getOid() == null) {
throw new QueryException("Null OID is not allowed in the reference query. Use empty reference list if needed.");
}
oids.add(value.getOid());
if (value.getRelation() == null) {
relations.add(SchemaConstants.ORG_DEFAULT);
} else {
// we intentionally don't normalize relations namespaces, to be able to do namespace-insensitive searches
// so the caller is responsible to unify namespaces if he needs to optimize queries (use IN instead of OR)
relations.add(value.getRelation());
}
targetTypes.add(qualifyTypeName(value.getTargetType()));
}
if (relations.size() > 1 || targetTypes.size() > 1) {
// we must use 'OR' clause
OrCondition rootOr = hibernateQuery.createOr();
values.forEach(prv -> rootOr.add(createRefCondition(hibernateQuery, Collections.singleton(prv.getOid()), prv.getRelation(), prv.getTargetType())));
return rootOr;
} else {
return createRefCondition(hibernateQuery, oids, MiscUtil.extractSingleton(relations), MiscUtil.extractSingleton(targetTypes));
}
}
use of com.evolveum.midpoint.repo.sql.query2.hqm.condition.OrCondition in project midpoint by Evolveum.
the class PropertyRestriction method createPropertyVsPropertyCondition.
protected Condition createPropertyVsPropertyCondition(String leftPropertyValuePath) throws QueryException {
HqlDataInstance rightItem = getItemPathResolver().resolveItemPath(filter.getRightHandSidePath(), filter.getRightHandSideDefinition(), getBaseHqlEntityForChildren(), true);
String rightHqlPath = rightItem.getHqlPath();
RootHibernateQuery hibernateQuery = context.getHibernateQuery();
if (filter instanceof EqualFilter) {
// left = right OR (left IS NULL AND right IS NULL)
Condition condition = hibernateQuery.createCompareXY(leftPropertyValuePath, rightHqlPath, "=", false);
OrCondition orCondition = hibernateQuery.createOr(condition, hibernateQuery.createAnd(hibernateQuery.createIsNull(leftPropertyValuePath), hibernateQuery.createIsNull(rightHqlPath)));
return orCondition;
} else if (filter instanceof ComparativeFilter) {
ItemRestrictionOperation operation = findOperationForFilter(filter);
Condition condition = hibernateQuery.createCompareXY(leftPropertyValuePath, rightHqlPath, operation.symbol(), false);
return condition;
} else {
throw new QueryException("Right-side ItemPath is supported currently only for EqualFilter or ComparativeFilter, not for " + filter);
}
}
use of com.evolveum.midpoint.repo.sql.query2.hqm.condition.OrCondition in project midpoint by Evolveum.
the class OrRestriction method interpret.
@Override
public Condition interpret() throws QueryException {
validateFilter();
OrCondition disjunction = getContext().getHibernateQuery().createOr();
updateJunction(filter.getConditions(), disjunction);
return disjunction;
}
Aggregations