use of com.evolveum.midpoint.repo.sql.query.resolution.HqlDataInstance in project midpoint by Evolveum.
the class ExistsRestriction method interpret.
@Override
public Condition interpret() throws QueryException {
HqlDataInstance dataInstance = getItemPathResolver().resolveItemPath(filter.getFullPath(), filter.getDefinition(), getBaseHqlEntity(), false);
boolean isAll = filter.getFilter() == null || filter.getFilter() instanceof AllFilter;
JpaDataNodeDefinition jpaDefinition = dataInstance.getJpaDefinition();
if (!isAll) {
if (!(jpaDefinition instanceof JpaEntityDefinition)) {
// partially checked already (for non-null-ness)
throw new QueryException("ExistsRestriction with non-empty subfilter points to non-entity node: " + jpaDefinition);
}
setHqlDataInstance(dataInstance);
QueryInterpreter interpreter = context.getInterpreter();
return interpreter.interpretFilter(context, filter.getFilter(), this);
} else if (jpaDefinition instanceof JpaPropertyDefinition && (((JpaPropertyDefinition) jpaDefinition).isCount())) {
RootHibernateQuery hibernateQuery = context.getHibernateQuery();
return hibernateQuery.createSimpleComparisonCondition(dataInstance.getHqlPath(), 0, ">");
} else {
// TODO support exists also for other properties (single valued or multi valued)
throw new UnsupportedOperationException("Exists filter with 'all' subfilter is currently not supported");
}
}
use of com.evolveum.midpoint.repo.sql.query.resolution.HqlDataInstance 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.sql.query.resolution.HqlDataInstance 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);
}
}
Aggregations