Search in sources :

Example 11 with Condition

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());
        }
    }
}
Also used : Condition(com.evolveum.midpoint.repo.sql.query2.hqm.condition.Condition) RootHibernateQuery(com.evolveum.midpoint.repo.sql.query2.hqm.RootHibernateQuery) ObjectPagingAfterOid(com.evolveum.midpoint.repo.sql.ObjectPagingAfterOid) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) RPolyString(com.evolveum.midpoint.repo.sql.data.common.embedded.RPolyString)

Example 12 with Condition

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);
    }
}
Also used : Condition(com.evolveum.midpoint.repo.sql.query2.hqm.condition.Condition)

Example 13 with Condition

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);
}
Also used : QueryException(com.evolveum.midpoint.repo.sql.query.QueryException) RootHibernateQuery(com.evolveum.midpoint.repo.sql.query2.hqm.RootHibernateQuery)

Example 14 with Condition

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);
    }
}
Also used : Condition(com.evolveum.midpoint.repo.sql.query2.hqm.condition.Condition) OrCondition(com.evolveum.midpoint.repo.sql.query2.hqm.condition.OrCondition) HqlDataInstance(com.evolveum.midpoint.repo.sql.query2.resolution.HqlDataInstance) QueryException(com.evolveum.midpoint.repo.sql.query.QueryException) RootHibernateQuery(com.evolveum.midpoint.repo.sql.query2.hqm.RootHibernateQuery) ComparativeFilter(com.evolveum.midpoint.prism.query.ComparativeFilter) EqualFilter(com.evolveum.midpoint.prism.query.EqualFilter) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) OrCondition(com.evolveum.midpoint.repo.sql.query2.hqm.condition.OrCondition)

Example 15 with Condition

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);
    }
}
Also used : Condition(com.evolveum.midpoint.repo.sql.query2.hqm.condition.Condition) OrCondition(com.evolveum.midpoint.repo.sql.query2.hqm.condition.OrCondition) QueryException(com.evolveum.midpoint.repo.sql.query.QueryException) PolyString(com.evolveum.midpoint.prism.polystring.PolyString)

Aggregations

Condition (com.evolveum.midpoint.repo.sql.query2.hqm.condition.Condition)12 QueryException (com.evolveum.midpoint.repo.sql.query.QueryException)8 RootHibernateQuery (com.evolveum.midpoint.repo.sql.query2.hqm.RootHibernateQuery)8 AndCondition (com.evolveum.midpoint.repo.sql.query2.hqm.condition.AndCondition)7 QueryInterpreter2 (com.evolveum.midpoint.repo.sql.query2.QueryInterpreter2)5 InterpretationContext (com.evolveum.midpoint.repo.sql.query2.InterpretationContext)4 OrCondition (com.evolveum.midpoint.repo.sql.query2.hqm.condition.OrCondition)4 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)3 HqlDataInstance (com.evolveum.midpoint.repo.sql.query2.resolution.HqlDataInstance)3 IsNotNullCondition (com.evolveum.midpoint.repo.sql.query2.hqm.condition.IsNotNullCondition)2 IsNullCondition (com.evolveum.midpoint.repo.sql.query2.hqm.condition.IsNullCondition)2 RUtil.qnameToString (com.evolveum.midpoint.repo.sql.util.RUtil.qnameToString)2 QName (javax.xml.namespace.QName)2 PrismReferenceValue (com.evolveum.midpoint.prism.PrismReferenceValue)1 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)1 AllFilter (com.evolveum.midpoint.prism.query.AllFilter)1 ComparativeFilter (com.evolveum.midpoint.prism.query.ComparativeFilter)1 EqualFilter (com.evolveum.midpoint.prism.query.EqualFilter)1 ObjectFilter (com.evolveum.midpoint.prism.query.ObjectFilter)1 ObjectPagingAfterOid (com.evolveum.midpoint.repo.sql.ObjectPagingAfterOid)1