use of com.evolveum.midpoint.repo.sqlbase.QueryException in project midpoint by Evolveum.
the class ExistsFilterProcessor method process.
private <TQ extends FlexibleRelationalPathBase<TR>, TR> Predicate process(ItemPath path, ExistsFilter filter) throws RepositoryException {
if (path.isEmpty()) {
ObjectFilter innerFilter = filter.getFilter();
// empty filter means EXISTS, NOT can be added before the filter
return innerFilter != null ? context.process(innerFilter) : null;
}
ItemRelationResolver<Q, R, TQ, TR> resolver = mapping.relationResolver(path);
// "Clean" solution would require more classes/code and would be more confusing.
if (resolver instanceof CountMappingResolver<?, ?>) {
return ((CountMappingResolver<Q, R>) resolver).createExistsPredicate(context);
}
ItemRelationResolver.ResolutionResult<TQ, TR> resolution = resolver.resolve(context);
// noinspection unchecked
SqaleQueryContext<?, TQ, TR> subcontext = (SqaleQueryContext<?, TQ, TR>) resolution.context;
if (!(resolution.mapping instanceof QueryTableMapping)) {
throw new QueryException("Repository supports exists only for multi-value containers (for now)");
}
ExistsFilterProcessor<TQ, TR> nestedProcessor = new ExistsFilterProcessor<>(subcontext, resolution.mapping);
Predicate predicate = nestedProcessor.process(path.rest(), filter);
if (resolution.subquery) {
return subcontext.sqlQuery().where(predicate).exists();
} else {
return predicate;
}
}
use of com.evolveum.midpoint.repo.sqlbase.QueryException in project midpoint by Evolveum.
the class ExtensionItemFilterProcessor method process.
@Override
public Predicate process(ValueFilter<?, ?> filter) throws RepositoryException {
ItemDefinition<?> definition = filter.getDefinition();
Objects.requireNonNull(definition, "Item '" + filter.getPath() + "' without definition used in query.");
MExtItem extItem = new ExtensionProcessor((SqaleRepoContext) context.repositoryContext()).resolveExtensionItem(definition, holderType);
assert definition != null;
if (extItem == null) {
throw new QueryException("Extension item " + definition.getItemName() + " is not indexed, filter: " + filter);
}
if (definition instanceof PrismReferenceDefinition) {
return processReference(extItem, (RefFilter) filter);
}
PropertyValueFilter<?> propertyValueFilter = (PropertyValueFilter<?>) filter;
ValueFilterValues<?, ?> values = ValueFilterValues.from(propertyValueFilter);
FilterOperation operation = operation(filter);
List<?> filterValues = filter.getValues();
if (filterValues == null || filterValues.isEmpty()) {
if (operation.isAnyEqualOperation()) {
return extItemIsNull(extItem);
} else {
throw new QueryException("Null value for other than EQUAL filter: " + filter);
}
}
if (extItem.valueType.equals(STRING_TYPE)) {
return processString(extItem, values, operation, filter);
}
// TODO for anything lower we don't support multi-value filter yet, but the solution from string can be adapted.
if (filterValues.size() > 1) {
throw new QueryException("Multiple values in filter are not supported for extension items: " + filter);
}
if (ExtUtils.isEnumDefinition((PrismPropertyDefinition<?>) definition)) {
return processEnum(extItem, values, operation, filter);
} else if (extItem.valueType.equals(INT_TYPE) || extItem.valueType.equals(INTEGER_TYPE) || extItem.valueType.equals(LONG_TYPE) || extItem.valueType.equals(SHORT_TYPE) || extItem.valueType.equals(DOUBLE_TYPE) || extItem.valueType.equals(FLOAT_TYPE) || extItem.valueType.equals(DECIMAL_TYPE)) {
return processNumeric(extItem, values, operation, filter);
} else if (extItem.valueType.equals(BOOLEAN_TYPE)) {
return processBoolean(extItem, values, operation, filter);
} else if (extItem.valueType.equals(DATETIME_TYPE)) {
// noinspection unchecked
PropertyValueFilter<XMLGregorianCalendar> dateTimeFilter = (PropertyValueFilter<XMLGregorianCalendar>) filter;
return processString(extItem, ValueFilterValues.from(dateTimeFilter, ExtUtils::extensionDateTime), operation, filter);
} else if (extItem.valueType.equals(POLY_STRING_TYPE)) {
return processPolyString(extItem, values, operation, propertyValueFilter);
}
throw new QueryException("Unsupported filter for extension item: " + filter);
}
use of com.evolveum.midpoint.repo.sqlbase.QueryException in project midpoint by Evolveum.
the class AuditCustomColumnItemFilterProcessor method process.
@Override
public Predicate process(PropertyValueFilter<AuditEventRecordCustomColumnPropertyType> filter) throws QueryException {
// This is a tricky situation, if multi-value, each value can have different path (derived
// from AuditEventRecordCustomColumnPropertyType.getName()), so we can't use this directly.
ValueFilterValues<AuditEventRecordCustomColumnPropertyType, ?> values = ValueFilterValues.from(filter);
if (values.isEmpty()) {
throw new QueryException("Custom column null value is not supported," + " column can't be determined from filter: " + filter);
}
if (values.isMultiValue()) {
Predicate predicate = null;
for (AuditEventRecordCustomColumnPropertyType propertyType : values.allValuesRaw()) {
Predicate right = createPredicate(filter, propertyType);
predicate = predicate != null ? ExpressionUtils.or(predicate, right) : right;
}
return predicate;
}
AuditEventRecordCustomColumnPropertyType value = values.singleValueRaw();
assert value != null;
return createPredicate(filter, value);
}
use of com.evolveum.midpoint.repo.sqlbase.QueryException in project midpoint by Evolveum.
the class AuditCustomColumnItemFilterProcessor method createPredicate.
private Predicate createPredicate(PropertyValueFilter<AuditEventRecordCustomColumnPropertyType> filter, AuditEventRecordCustomColumnPropertyType customColumnPropertyType) throws QueryException {
FilterOperation operation = operation(filter);
Path<?> path = context.path().getPath(customColumnPropertyType.getName());
if (customColumnPropertyType.getValue() == null) {
if (operation.isAnyEqualOperation()) {
return ExpressionUtils.predicate(Ops.IS_NULL, path);
} else {
throw new QueryException("Null value for other than EQUAL filter: " + filter);
}
}
return singleValuePredicate(path, operation, customColumnPropertyType.getValue());
}
use of com.evolveum.midpoint.repo.sqlbase.QueryException in project midpoint by Evolveum.
the class RAnyConverter method getAnySetType.
/**
* This method provides extension type (in real it's table) string for definition and value
* defined as parameters.
*
* @return One of "strings", "longs", "dates", "clobs"
*/
public static String getAnySetType(ItemDefinition definition, PrismContext prismContext) throws SchemaException, QueryException {
if (!isIndexed(definition, definition.getItemName(), true, prismContext)) {
throw new QueryException("Can't query non-indexed value for '" + definition.getItemName() + "', definition " + definition);
}
QName typeName = definition.getTypeName();
ValueType valueType = getValueType(typeName);
switch(valueType) {
case BOOLEAN:
return "booleans";
case DATE:
return "dates";
case LONG:
return "longs";
case STRING:
default:
return "strings";
}
}
Aggregations