use of com.evolveum.midpoint.repo.sql.query2.hqm.condition.Condition in project midpoint by Evolveum.
the class QueryInterpreter2 method interpretPagingAndSorting.
private void interpretPagingAndSorting(InterpretationContext context, ObjectQuery query, boolean countingObjects) throws QueryException {
RootHibernateQuery hibernateQuery = context.getHibernateQuery();
String rootAlias = hibernateQuery.getPrimaryEntityAlias();
if (query != null && query.getPaging() instanceof ObjectPagingAfterOid) {
ObjectPagingAfterOid paging = (ObjectPagingAfterOid) query.getPaging();
if (paging.getOidGreaterThan() != null) {
Condition c = hibernateQuery.createSimpleComparisonCondition(rootAlias + ".oid", paging.getOidGreaterThan(), ">");
hibernateQuery.addCondition(c);
}
}
if (!countingObjects && query != null && query.getPaging() != null) {
if (query.getPaging() instanceof ObjectPagingAfterOid) {
// very special case - ascending ordering by OID (nothing more)
updatePagingAndSortingByOid(hibernateQuery, (ObjectPagingAfterOid) query.getPaging());
} else {
updatePagingAndSorting(context, query.getPaging());
}
}
}
use of com.evolveum.midpoint.repo.sql.query2.hqm.condition.Condition in project midpoint by Evolveum.
the class QueryInterpreter2 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);
}
}
use of com.evolveum.midpoint.repo.sql.query2.hqm.condition.Condition in project midpoint by Evolveum.
the class OrgRestriction method interpret.
@Override
public Condition interpret() throws QueryException {
RootHibernateQuery hibernateQuery = getContext().getHibernateQuery();
if (filter.isRoot()) {
// oid in (select descendantOid from ROrgClosure group by descendantOid having count(descendantOid) = 1)
return hibernateQuery.createIn(getBaseHqlEntity().getHqlPath() + ".oid", "select descendantOid from ROrgClosure group by descendantOid having count(descendantOid) = 1");
}
if (filter.getOrgRef() == null) {
throw new QueryException("No organization reference defined in the search query.");
}
if (filter.getOrgRef().getOid() == null) {
throw new QueryException("No oid specified in organization reference " + filter.getOrgRef().debugDump());
}
String orgOidParamName = hibernateQuery.addParameter("orgOid", filter.getOrgRef().getOid());
// oid in ...
String oidQueryText;
switch(filter.getScope()) {
case ONE_LEVEL:
oidQueryText = // TODO distinct(ref.ownerOid) ? (was in original QueryInterpreter)
"select ref.ownerOid " + "from RObjectReference ref " + "where " + "ref.referenceType = " + nameOf(RReferenceOwner.OBJECT_PARENT_ORG) + " and " + "ref.targetOid = :" + orgOidParamName;
break;
case ANCESTORS:
oidQueryText = "select c.ancestorOid " + "from ROrgClosure c " + "where " + "c.ancestorOid != :" + orgOidParamName + " and " + "c.descendantOid = :" + orgOidParamName;
break;
case SUBTREE:
default:
oidQueryText = "select ref.ownerOid " + "from RObjectReference ref " + "where " + "ref.referenceType = " + nameOf(RReferenceOwner.OBJECT_PARENT_ORG) + " and " + "ref.targetOid in (" + "select descendantOid from ROrgClosure where ancestorOid = :" + orgOidParamName + ")";
}
return hibernateQuery.createIn(getBaseHqlEntity().getHqlPath() + ".oid", oidQueryText);
}
use of com.evolveum.midpoint.repo.sql.query2.hqm.condition.Condition in project midpoint by Evolveum.
the class PropertyRestriction method createPropertyVsPropertyCondition.
protected 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);
OrCondition orCondition = hibernateQuery.createOr(condition, hibernateQuery.createAnd(hibernateQuery.createIsNull(leftPropertyValuePath), hibernateQuery.createIsNull(rightHqlPath)));
return orCondition;
} else if (filter instanceof ComparativeFilter) {
ItemRestrictionOperation operation = findOperationForFilter(filter);
Condition condition = hibernateQuery.createCompareXY(leftPropertyValuePath, rightHqlPath, operation.symbol(), false);
return condition;
} 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.query2.hqm.condition.Condition in project midpoint by Evolveum.
the class PropertyRestriction method interpretInternal.
@Override
public Condition interpretInternal() throws QueryException {
if (linkDefinition.getTargetDefinition().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);
Condition condition = createPropertyVsConstantCondition(propertyValuePath, value, filter);
return addIsNotNullIfNecessary(condition, propertyValuePath);
}
}
Aggregations