use of com.evolveum.midpoint.repo.sql.query.definition.JpaPropertyDefinition in project midpoint by Evolveum.
the class PropertyRestriction method getValueFromFilter.
private 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.");
}
Object adaptedValue = adaptValueType(value, filter);
if (def.isEnumerated()) {
return getRepoEnumValue((Enum) adaptedValue, def.getJpaClass());
} else {
return adaptedValue;
}
}
use of com.evolveum.midpoint.repo.sql.query.definition.JpaPropertyDefinition 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.definition.JpaPropertyDefinition 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