use of com.evolveum.midpoint.repo.sql.query.QueryException in project midpoint by Evolveum.
the class PolyStringMatcher method match.
@Override
public Condition match(RootHibernateQuery hibernateQuery, ItemRestrictionOperation operation, String propertyName, PolyString value, String matcher) throws QueryException {
boolean ignoreCase = STRICT_IGNORE_CASE.equals(matcher) || ORIG_IGNORE_CASE.equals(matcher) || NORM_IGNORE_CASE.equals(matcher);
if (StringUtils.isEmpty(matcher) || DEFAULT.equals(matcher) || STRICT.equals(matcher) || STRICT_IGNORE_CASE.equals(matcher)) {
AndCondition conjunction = hibernateQuery.createAnd();
conjunction.add(createOrigMatch(hibernateQuery, operation, propertyName, value, ignoreCase));
conjunction.add(createNormMatch(hibernateQuery, operation, propertyName, value, ignoreCase));
return conjunction;
} else if (ORIG.equals(matcher) || ORIG_IGNORE_CASE.equals(matcher)) {
return createOrigMatch(hibernateQuery, operation, propertyName, value, ignoreCase);
} else if (NORM.equals(matcher) || NORM_IGNORE_CASE.equals(matcher)) {
return createNormMatch(hibernateQuery, operation, propertyName, value, ignoreCase);
} else {
throw new QueryException("Unknown matcher '" + matcher + "'.");
}
}
use of com.evolveum.midpoint.repo.sql.query.QueryException in project midpoint by Evolveum.
the class ItemPathResolutionState method nextState.
/**
* Executes transition to next state. Modifies query context by adding joins as necessary.
*
* Precondition: !isFinal()
* Precondition: adequate transition exists
*
* @param itemDefinition Target item definition (used/required only for "any" properties)
* @param singletonOnly Collections are forbidden
* @return destination state - always not null
*/
public ItemPathResolutionState nextState(ItemDefinition itemDefinition, boolean singletonOnly, PrismContext prismContext) throws QueryException {
// This is brutal hack, to be thought again.
if (remainingItemPath.startsWith(ParentPathSegment.class) && hqlDataInstance.getParentItem() != null) {
return new ItemPathResolutionState(remainingItemPath.tail(), hqlDataInstance.getParentItem(), itemPathResolver);
}
DataSearchResult<?> result = hqlDataInstance.getJpaDefinition().nextLinkDefinition(remainingItemPath, itemDefinition, prismContext);
LOGGER.trace("nextLinkDefinition on '{}' returned '{}'", remainingItemPath, result != null ? result.getLinkDefinition() : "(null)");
if (result == null) {
// sorry we failed (however, this should be caught before -> so IllegalStateException)
throw new IllegalStateException("Couldn't find '" + remainingItemPath + "' in " + hqlDataInstance.getJpaDefinition());
}
JpaLinkDefinition linkDefinition = result.getLinkDefinition();
String newHqlPath = hqlDataInstance.getHqlPath();
if (linkDefinition.hasJpaRepresentation()) {
if (singletonOnly && linkDefinition.isMultivalued()) {
// TODO better message + context
throw new QueryException("Collections are not allowable for right-side paths");
}
if (!linkDefinition.isEmbedded() || linkDefinition.isMultivalued()) {
LOGGER.trace("Adding join for '{}' to context", linkDefinition);
newHqlPath = itemPathResolver.addJoin(linkDefinition, hqlDataInstance.getHqlPath());
} else {
newHqlPath += "." + linkDefinition.getJpaName();
}
}
HqlDataInstance<?> parentDataInstance;
if (!remainingItemPath.startsWith(ParentPathSegment.class)) {
// TODO what about other special cases? (@, ...)
parentDataInstance = hqlDataInstance;
} else {
parentDataInstance = null;
}
return new ItemPathResolutionState(result.getRemainder(), new HqlDataInstance<>(newHqlPath, result.getTargetDefinition(), parentDataInstance), itemPathResolver);
}
use of com.evolveum.midpoint.repo.sql.query.QueryException in project midpoint by Evolveum.
the class ItemPathResolver method createQueryParamValue.
/**
* This method provides transformation from {@link String} value defined in
* {@link com.evolveum.midpoint.repo.sql.query.definition.VirtualQueryParam#value()} to real object. Currently only
* to simple types and enum values.
*/
private Object createQueryParamValue(VirtualQueryParam param) throws QueryException {
Class type = param.type();
String value = param.value();
try {
if (type.isPrimitive()) {
return type.getMethod("valueOf", new Class[] { String.class }).invoke(null, new Object[] { value });
}
if (type.isEnum()) {
return Enum.valueOf(type, value);
}
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException | RuntimeException ex) {
throw new QueryException("Couldn't transform virtual query parameter '" + param.name() + "' from String to '" + type + "', reason: " + ex.getMessage(), ex);
}
throw new QueryException("Couldn't transform virtual query parameter '" + param.name() + "' from String to '" + type + "', it's not yet implemented.");
}
use of com.evolveum.midpoint.repo.sql.query.QueryException in project midpoint by Evolveum.
the class ItemPathResolver method findRestrictedEntityDefinition.
/**
* Given existing entity definition and a request for narrowing it, tries to find refined definition.
*/
public JpaEntityDefinition findRestrictedEntityDefinition(JpaEntityDefinition baseEntityDefinition, QName specificTypeName) throws QueryException {
QueryDefinitionRegistry2 registry = QueryDefinitionRegistry2.getInstance();
JpaEntityDefinition specificEntityDefinition = registry.findEntityDefinition(specificTypeName);
if (!baseEntityDefinition.isAssignableFrom(specificEntityDefinition)) {
throw new QueryException("Entity " + baseEntityDefinition + " cannot be restricted to " + specificEntityDefinition);
}
return specificEntityDefinition;
}
use of com.evolveum.midpoint.repo.sql.query.QueryException 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);
QueryInterpreter2 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");
}
}
Aggregations