use of com.evolveum.midpoint.repo.sql.query2.hqm.condition.AndCondition 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.AndCondition 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;
}
use of com.evolveum.midpoint.repo.sql.query2.hqm.condition.AndCondition in project midpoint by Evolveum.
the class ItemValueRestriction method addIsNotNullIfNecessary.
/**
* Filter of type NOT(PROPERTY=VALUE) causes problems when there are entities with PROPERTY set to NULL.
*
* Such a filter has to be treated like
*
* NOT (PROPERTY=VALUE & PROPERTY IS NOT NULL)
*
* TODO implement for restrictions other than PropertyRestriction.
*/
protected Condition addIsNotNullIfNecessary(Condition condition, String propertyPath) {
if (condition instanceof IsNullCondition || condition instanceof IsNotNullCondition) {
return condition;
}
if (!isNegated()) {
return condition;
}
RootHibernateQuery hibernateQuery = getContext().getHibernateQuery();
AndCondition conjunction = hibernateQuery.createAnd();
conjunction.add(condition);
conjunction.add(hibernateQuery.createIsNotNull(propertyPath));
return conjunction;
}
use of com.evolveum.midpoint.repo.sql.query2.hqm.condition.AndCondition in project midpoint by Evolveum.
the class ReferenceRestriction method createRefCondition.
private Condition createRefCondition(RootHibernateQuery hibernateQuery, Collection<String> oids, QName relation, QName targetType) {
String hqlPath = hqlDataInstance.getHqlPath();
final String TARGET_OID_HQL_PROPERTY, RELATION_HQL_PROPERTY, TARGET_TYPE_HQL_PROPERTY;
if (linkDefinition.getTargetDefinition() instanceof JpaAnyReferenceDefinition) {
TARGET_OID_HQL_PROPERTY = ROExtReference.F_TARGET_OID;
RELATION_HQL_PROPERTY = ROExtReference.F_RELATION;
TARGET_TYPE_HQL_PROPERTY = ROExtReference.F_TARGET_TYPE;
} else {
TARGET_OID_HQL_PROPERTY = RObjectReference.F_TARGET_OID;
RELATION_HQL_PROPERTY = RObjectReference.F_RELATION;
TARGET_TYPE_HQL_PROPERTY = RObjectReference.F_TARGET_TYPE;
}
AndCondition conjunction = hibernateQuery.createAnd();
conjunction.add(hibernateQuery.createEqOrInOrNull(hqlDataInstance.getHqlPath() + "." + TARGET_OID_HQL_PROPERTY, oids));
if (ObjectTypeUtil.isDefaultRelation(relation)) {
// Return references without relation or with "member" relation
conjunction.add(hibernateQuery.createIn(hqlPath + "." + RELATION_HQL_PROPERTY, Arrays.asList(RUtil.QNAME_DELIMITER, qnameToString(SchemaConstants.ORG_DEFAULT))));
} else if (QNameUtil.match(relation, PrismConstants.Q_ANY)) {
// Return all relations => no restriction
} else {
// return references with specific relation
List<String> relationsToTest = new ArrayList<>();
relationsToTest.add(qnameToString(relation));
if (QNameUtil.noNamespace(relation)) {
relationsToTest.add(qnameToString(QNameUtil.setNamespaceIfMissing(relation, SchemaConstants.NS_ORG, null)));
} else if (SchemaConstants.NS_ORG.equals(relation.getNamespaceURI())) {
relationsToTest.add(qnameToString(new QName(relation.getLocalPart())));
} else {
// non-empty non-standard NS => nothing to add
}
conjunction.add(hibernateQuery.createEqOrInOrNull(hqlPath + "." + RELATION_HQL_PROPERTY, relationsToTest));
}
if (targetType != null) {
conjunction.add(handleEqInOrNull(hibernateQuery, hqlPath + "." + TARGET_TYPE_HQL_PROPERTY, ClassMapper.getHQLTypeForQName(targetType)));
}
return conjunction;
}
use of com.evolveum.midpoint.repo.sql.query2.hqm.condition.AndCondition in project midpoint by Evolveum.
the class ItemPathResolver method createJoinCondition.
private Condition createJoinCondition(String joinedItemAlias, JpaLinkDefinition joinedItemDefinition, RootHibernateQuery hibernateQuery) throws QueryException {
Condition condition = null;
if (joinedItemDefinition instanceof JpaAnyItemLinkDefinition) {
JpaAnyItemLinkDefinition anyLinkDef = (JpaAnyItemLinkDefinition) joinedItemDefinition;
AndCondition conjunction = hibernateQuery.createAnd();
if (anyLinkDef.getOwnerType() != null) {
// null for assignment extensions
conjunction.add(hibernateQuery.createEq(joinedItemAlias + ".ownerType", anyLinkDef.getOwnerType()));
}
conjunction.add(hibernateQuery.createEq(joinedItemAlias + "." + RAnyValue.F_NAME, RUtil.qnameToString(anyLinkDef.getItemName())));
condition = conjunction;
} else if (joinedItemDefinition.getCollectionSpecification() instanceof VirtualCollectionSpecification) {
VirtualCollectionSpecification vcd = (VirtualCollectionSpecification) joinedItemDefinition.getCollectionSpecification();
List<Condition> conditions = new ArrayList<>(vcd.getAdditionalParams().length);
for (VirtualQueryParam vqp : vcd.getAdditionalParams()) {
// e.g. name = "assignmentOwner", type = RAssignmentOwner.class, value = "ABSTRACT_ROLE"
Object value = createQueryParamValue(vqp);
Condition c = hibernateQuery.createEq(joinedItemAlias + "." + vqp.name(), value);
conditions.add(c);
}
if (conditions.size() > 1) {
condition = hibernateQuery.createAnd(conditions);
} else if (conditions.size() == 1) {
condition = conditions.iterator().next();
}
}
return condition;
}
Aggregations