use of com.evolveum.midpoint.repo.sqlbase.QueryException 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<>();
boolean valuesWithWildcardOid = false;
boolean valuesWithSpecifiedOid = false;
for (PrismReferenceValue value : values) {
if (value.getOid() != null) {
oids.add(value.getOid());
valuesWithSpecifiedOid = true;
} else {
if (filter.isOidNullAsAny()) {
valuesWithWildcardOid = true;
} else {
throw new QueryException("Null OID is not allowed in the reference query. " + "If you'd like to search for missing reference, use empty list of values.");
}
}
if (value.getRelation() == null) {
relations.add(context.getPrismContext().getDefaultRelation());
} 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 (valuesWithWildcardOid && valuesWithSpecifiedOid || relations.size() > 1 || targetTypes.size() > 1) {
// We must use 'OR' clause
OrCondition rootOr = hibernateQuery.createOr();
values.forEach(prv -> rootOr.add(createRefCondition(hibernateQuery, MiscUtil.singletonOrEmptySet(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.sqlbase.QueryException in project midpoint by Evolveum.
the class ItemValueRestriction method findOperationForFilter.
ItemRestrictionOperation findOperationForFilter(ValueFilter filter) throws QueryException {
ItemRestrictionOperation operation;
if (filter instanceof EqualFilter) {
operation = ItemRestrictionOperation.EQ;
} else if (filter instanceof GreaterFilter) {
GreaterFilter gf = (GreaterFilter) filter;
operation = gf.isEquals() ? ItemRestrictionOperation.GE : ItemRestrictionOperation.GT;
} else if (filter instanceof LessFilter) {
LessFilter lf = (LessFilter) filter;
operation = lf.isEquals() ? ItemRestrictionOperation.LE : ItemRestrictionOperation.LT;
} else if (filter instanceof SubstringFilter) {
SubstringFilter substring = (SubstringFilter) filter;
if (substring.isAnchorEnd()) {
operation = ItemRestrictionOperation.ENDS_WITH;
} else if (substring.isAnchorStart()) {
operation = ItemRestrictionOperation.STARTS_WITH;
} else {
operation = ItemRestrictionOperation.SUBSTRING;
}
} else {
throw new QueryException("Can't translate filter '" + filter + "' to operation.");
}
return operation;
}
use of com.evolveum.midpoint.repo.sqlbase.QueryException in project midpoint by Evolveum.
the class ItemValueRestriction method interpret.
@Override
public Condition interpret() throws QueryException {
ItemPath path = getItemPath();
if (ItemPath.isEmpty(path)) {
throw new QueryException("Null or empty path for ItemValueRestriction in " + filter.debugDump());
}
HqlDataInstance dataInstance = getItemPathResolver().resolveItemPath(path, itemDefinition, getBaseHqlEntity(), false);
setHqlDataInstance(dataInstance);
return interpretInternal();
}
use of com.evolveum.midpoint.repo.sqlbase.QueryException in project midpoint by Evolveum.
the class PropertyRestriction method createPropertyVsPropertyCondition.
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);
return hibernateQuery.createOr(condition, hibernateQuery.createAnd(hibernateQuery.createIsNull(leftPropertyValuePath), hibernateQuery.createIsNull(rightHqlPath)));
} else if (filter instanceof ComparativeFilter) {
ItemRestrictionOperation operation = findOperationForFilter(filter);
return hibernateQuery.createCompareXY(leftPropertyValuePath, rightHqlPath, operation.symbol(), false);
} else {
throw new QueryException("Right-side ItemPath is supported currently only for EqualFilter or ComparativeFilter, not for " + filter);
}
}
use of com.evolveum.midpoint.repo.sqlbase.QueryException in project midpoint by Evolveum.
the class PropertyRestriction method interpretInternal.
@Override
public Condition interpretInternal() throws QueryException {
JpaPropertyDefinition propertyDefinition = linkDefinition.getTargetDefinition();
if (propertyDefinition.isLob()) {
throw new QueryException("Can't query based on clob property value '" + linkDefinition + "'.");
}
String propertyValuePath = getHqlDataInstance().getHqlPath();
if (filter.getRightHandSidePath() != null) {
return createPropertyVsPropertyCondition(propertyValuePath);
} else {
Object value = getValueFromFilter(filter);
if (value == null && propertyDefinition.isNeverNull()) {
LOGGER.warn("Checking nullity of non-null property {} (filter = {})", propertyDefinition, filter);
return new ConstantCondition(context.getHibernateQuery(), false);
} else {
Condition condition = createPropertyVsConstantCondition(propertyValuePath, value, filter);
return addIsNotNullIfNecessary(condition, propertyValuePath);
}
}
}
Aggregations