use of com.evolveum.midpoint.repo.sql.query.QueryException 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.query.QueryException in project midpoint by Evolveum.
the class PropertyRestriction method interpretInternal.
@Override
public Condition interpretInternal() throws QueryException {
if (linkDefinition.getTargetDefinition().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);
Condition condition = createPropertyVsConstantCondition(propertyValuePath, value, filter);
return addIsNotNullIfNecessary(condition, propertyValuePath);
}
}
use of com.evolveum.midpoint.repo.sql.query.QueryException in project midpoint by Evolveum.
the class PropertyRestriction method getValueFromFilter.
protected Object getValueFromFilter(ValueFilter filter) throws QueryException {
JpaPropertyDefinition def = linkDefinition.getTargetDefinition();
Object value;
if (filter instanceof PropertyValueFilter) {
value = getValue((PropertyValueFilter) filter);
} else {
throw new QueryException("Unknown filter '" + filter + "', can't get value from it.");
}
value = checkValueType(value, filter);
if (def.isEnumerated()) {
value = getRepoEnumValue((Enum) value, def.getJpaClass());
}
return value;
}
use of com.evolveum.midpoint.repo.sql.query.QueryException in project midpoint by Evolveum.
the class ItemPathResolver method findProperDataDefinition.
/**
* Finds the proper definition for (possibly abstract) entity.
* Returns the most abstract entity that can be used.
* Checks for conflicts, such as user.locality vs org.locality.
*
* @param path Path to be found (non-empty!)
* @param itemDefinition Definition of target property, required/used only for "any" properties
* @param clazz Kind of definition to be looked for
* @param prismContext
* @return Entity type definition + item definition, or null if nothing was found
*/
public <T extends JpaDataNodeDefinition> ProperDataSearchResult<T> findProperDataDefinition(JpaEntityDefinition baseEntityDefinition, ItemPath path, ItemDefinition itemDefinition, Class<T> clazz, PrismContext prismContext) throws QueryException {
QueryDefinitionRegistry2 registry = QueryDefinitionRegistry2.getInstance();
ProperDataSearchResult<T> candidateResult = null;
for (JpaEntityDefinition entityDefinition : findPossibleBaseEntities(baseEntityDefinition, registry)) {
DataSearchResult<T> result = entityDefinition.findDataNodeDefinition(path, itemDefinition, clazz, prismContext);
if (result != null) {
if (candidateResult == null) {
candidateResult = new ProperDataSearchResult<>(entityDefinition, result);
} else {
// there is no possibility of false alarm.
if (!candidateResult.getEntityDefinition().isAssignableFrom(entityDefinition)) {
throw new QueryException("Unable to determine root entity for " + path + ": found incompatible candidates: " + candidateResult.getEntityDefinition() + " and " + entityDefinition);
}
}
}
}
LOGGER.trace("findProperDataDefinition: base='{}', path='{}', def='{}', class={} -- returning '{}'", baseEntityDefinition, path, itemDefinition, clazz.getSimpleName(), candidateResult);
return candidateResult;
}
use of com.evolveum.midpoint.repo.sql.query.QueryException in project midpoint by Evolveum.
the class ItemValueRestriction method interpret.
@Override
public Condition interpret() throws QueryException {
ItemPath path = getItemPath();
if (ItemPath.isNullOrEmpty(path)) {
throw new QueryException("Null or empty path for ItemValueRestriction in " + filter.debugDump());
}
HqlDataInstance dataInstance = getItemPathResolver().resolveItemPath(path, itemDefinition, getBaseHqlEntity(), false);
setHqlDataInstance(dataInstance);
Condition condition = interpretInternal();
return condition;
}
Aggregations