use of com.evolveum.midpoint.repo.sql.query2.hqm.condition.Condition in project midpoint by Evolveum.
the class ReferenceRestriction method interpretInternal.
@Override
public Condition interpretInternal() throws QueryException {
String hqlPath = hqlDataInstance.getHqlPath();
LOGGER.trace("interpretInternal starting with hqlPath = {}", hqlPath);
RootHibernateQuery hibernateQuery = context.getHibernateQuery();
List<PrismReferenceValue> values = filter.getValues();
if (CollectionUtils.isEmpty(values)) {
return hibernateQuery.createIsNull(hqlDataInstance.getHqlPath());
}
Set<String> oids = new HashSet<>();
Set<QName> relations = new HashSet<>();
Set<QName> targetTypes = new HashSet<>();
for (PrismReferenceValue value : values) {
if (value.getOid() == null) {
throw new QueryException("Null OID is not allowed in the reference query. Use empty reference list if needed.");
}
oids.add(value.getOid());
if (value.getRelation() == null) {
relations.add(SchemaConstants.ORG_DEFAULT);
} else {
// we intentionally don't normalize relations namespaces, to be able to do namespace-insensitive searches
// so the caller is responsible to unify namespaces if he needs to optimize queries (use IN instead of OR)
relations.add(value.getRelation());
}
targetTypes.add(qualifyTypeName(value.getTargetType()));
}
if (relations.size() > 1 || targetTypes.size() > 1) {
// we must use 'OR' clause
OrCondition rootOr = hibernateQuery.createOr();
values.forEach(prv -> rootOr.add(createRefCondition(hibernateQuery, Collections.singleton(prv.getOid()), prv.getRelation(), prv.getTargetType())));
return rootOr;
} else {
return createRefCondition(hibernateQuery, oids, MiscUtil.extractSingleton(relations), MiscUtil.extractSingleton(targetTypes));
}
}
use of com.evolveum.midpoint.repo.sql.query2.hqm.condition.Condition in project midpoint by Evolveum.
the class Matcher method basicMatch.
protected Condition basicMatch(RootHibernateQuery hibernateQuery, ItemRestrictionOperation operation, String propertyPath, Object value, boolean ignoreCase) throws QueryException {
Validate.notNull(hibernateQuery, "hibernateQuery");
if (ignoreCase && !(value instanceof String)) {
LOGGER.warn("Ignoring ignoreCase setting for non-string value of {}", value);
ignoreCase = false;
}
Condition condition;
switch(operation) {
case EQ:
if (value == null) {
condition = hibernateQuery.createIsNull(propertyPath);
} else {
condition = hibernateQuery.createEq(propertyPath, value, ignoreCase);
}
break;
case GT:
case GE:
case LT:
case LE:
condition = hibernateQuery.createSimpleComparisonCondition(propertyPath, value, operation.symbol(), ignoreCase);
break;
case NOT_NULL:
condition = hibernateQuery.createIsNotNull(propertyPath);
break;
case NULL:
condition = hibernateQuery.createIsNull(propertyPath);
break;
case STARTS_WITH:
condition = hibernateQuery.createLike(propertyPath, (String) value, MatchMode.START, ignoreCase);
break;
case ENDS_WITH:
condition = hibernateQuery.createLike(propertyPath, (String) value, MatchMode.END, ignoreCase);
break;
case SUBSTRING:
condition = hibernateQuery.createLike(propertyPath, (String) value, MatchMode.ANYWHERE, ignoreCase);
break;
default:
throw new QueryException("Unknown operation '" + operation + "'.");
}
return condition;
}
use of com.evolveum.midpoint.repo.sql.query2.hqm.condition.Condition 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.query2.hqm.condition.Condition in project midpoint by Evolveum.
the class ItemPathResolver method addJoin.
String addJoin(JpaLinkDefinition joinedItemDefinition, String currentHqlPath) throws QueryException {
RootHibernateQuery hibernateQuery = context.getHibernateQuery();
String joinedItemJpaName = joinedItemDefinition.getJpaName();
String joinedItemFullPath = currentHqlPath + "." + joinedItemJpaName;
String joinedItemAlias;
if (!joinedItemDefinition.isMultivalued()) {
/*
* Let's check if we were already here i.e. if we had already created this join.
* This is to avoid useless creation of redundant joins for singleton items.
*
* But how can we be sure that item is singleton if we look only at the last segment (which is single-valued)?
* Imagine we are creating join for single-valued entity of u.abc.(...).xyz.ent where
* ent is single-valued and not embedded (so we are to create something like "left join u.abc.(...).xyz.ent e").
* Then "u" is certainly a single value: either the root object, or some value pointed to by Exists restriction.
* Also, abc, ..., xyz are surely single-valued: otherwise they would be connected by a join. So,
* u.abc.(...).xyz.ent is a singleton.
*
* Look at it in other way: if e.g. xyz was multivalued, then we would have something like:
* left join u.abc.(...).uvw.xyz x
* left join x.ent e
* And, therefore we would not be looking for u.abc.(...).xyz.ent.
*/
JoinSpecification existingJoin = hibernateQuery.getPrimaryEntity().findJoinFor(joinedItemFullPath);
if (existingJoin != null) {
// but let's check the condition as well
String existingAlias = existingJoin.getAlias();
// we have to create condition for existing alias, to be matched to existing condition
Condition conditionForExistingAlias = createJoinCondition(existingAlias, joinedItemDefinition, hibernateQuery);
if (ObjectUtils.equals(conditionForExistingAlias, existingJoin.getCondition())) {
LOGGER.trace("Reusing alias '{}' for joined path '{}'", existingAlias, joinedItemFullPath);
return existingAlias;
}
}
}
joinedItemAlias = hibernateQuery.createAlias(joinedItemDefinition);
Condition condition = createJoinCondition(joinedItemAlias, joinedItemDefinition, hibernateQuery);
hibernateQuery.getPrimaryEntity().addJoin(new JoinSpecification(joinedItemAlias, joinedItemFullPath, condition));
return joinedItemAlias;
}
use of com.evolveum.midpoint.repo.sql.query2.hqm.condition.Condition in project midpoint by Evolveum.
the class AndRestriction method interpret.
@Override
public Condition interpret() throws QueryException {
validateFilter();
AndCondition conjunction = getContext().getHibernateQuery().createAnd();
updateJunction(filter.getConditions(), conjunction);
return conjunction;
}
Aggregations