use of com.evolveum.midpoint.repo.sql.query.hqm.condition.Condition in project midpoint by Evolveum.
the class QueryInterpreter method interpretPagingAndSorting.
private void interpretPagingAndSorting(InterpretationContext context, ObjectQuery query, boolean countingObjects) throws QueryException {
RootHibernateQuery hibernateQuery = context.getHibernateQuery();
String rootAlias = hibernateQuery.getPrimaryEntityAlias();
// noinspection StringEquality
if (query != null && query.getPaging() != null && query.getPaging().hasCookie() && query.getPaging().getCookie() != ObjectRetriever.NULL_OID_MARKER) {
ObjectPaging paging = query.getPaging();
Condition c = hibernateQuery.createSimpleComparisonCondition(rootAlias + ".oid", paging.getCookie(), ">");
hibernateQuery.addCondition(c);
}
if (!countingObjects && query != null && query.getPaging() != null) {
if (query.getPaging().hasCookie()) {
// very special case - ascending ordering by OID (nothing more)
updatePagingAndSortingByOid(hibernateQuery, query.getPaging());
} else {
updatePagingAndSorting(context, query.getPaging());
}
}
}
use of com.evolveum.midpoint.repo.sql.query.hqm.condition.Condition 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()));
}
ExtItemDictionary dictionary = context.getExtItemDictionary();
RExtItem extItemDefinition = dictionary.findItemByDefinition(anyLinkDef.getItemDefinition());
if (extItemDefinition != null) {
conjunction.add(hibernateQuery.createEq(joinedItemAlias + "." + RAnyValue.F_ITEM_ID, extItemDefinition.getId()));
} else {
// there are no rows referencing this item, because it does not exist in RExtItem (yet)
conjunction.add(hibernateQuery.createFalse());
}
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;
}
use of com.evolveum.midpoint.repo.sql.query.hqm.condition.Condition in project midpoint by Evolveum.
the class PropertyRestriction method createPropertyVsPropertyCondition.
Condition createPropertyVsPropertyCondition(String leftPropertyValuePath) throws QueryException {
HqlDataInstance rightItem = getItemPathResolver().resolveItemPath(filter.getRightHandSidePath(), filter.getRightHandSideDefinition(), getBaseHqlEntityForChildren(), true);
String rightHqlPath = rightItem.getHqlPath();
RootHibernateQuery hibernateQuery = context.getHibernateQuery();
if (filter instanceof EqualFilter) {
// left = right OR (left IS NULL AND right IS NULL)
Condition condition = hibernateQuery.createCompareXY(leftPropertyValuePath, rightHqlPath, "=", false);
return hibernateQuery.createOr(condition, hibernateQuery.createAnd(hibernateQuery.createIsNull(leftPropertyValuePath), hibernateQuery.createIsNull(rightHqlPath)));
} else if (filter instanceof ComparativeFilter) {
ItemRestrictionOperation operation = findOperationForFilter(filter);
return hibernateQuery.createCompareXY(leftPropertyValuePath, rightHqlPath, operation.symbol(), false);
} else {
throw new QueryException("Right-side ItemPath is supported currently only for EqualFilter or ComparativeFilter, not for " + filter);
}
}
use of com.evolveum.midpoint.repo.sql.query.hqm.condition.Condition 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);
}
}
}
use of com.evolveum.midpoint.repo.sql.query.hqm.condition.Condition in project midpoint by Evolveum.
the class QueryInterpreter method interpretQueryFilter.
private void interpretQueryFilter(InterpretationContext context, ObjectQuery query) throws QueryException {
if (query != null && query.getFilter() != null) {
Condition c = interpretFilter(context, query.getFilter(), null);
context.getHibernateQuery().addCondition(c);
}
}
Aggregations