Search in sources :

Example 6 with Condition

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

Example 7 with Condition

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;
}
Also used : AndCondition(com.evolveum.midpoint.repo.sql.query.hqm.condition.AndCondition) Condition(com.evolveum.midpoint.repo.sql.query.hqm.condition.Condition) ExtItemDictionary(com.evolveum.midpoint.repo.sql.data.common.dictionary.ExtItemDictionary) ArrayList(java.util.ArrayList) List(java.util.List) RObject(com.evolveum.midpoint.repo.sql.data.common.RObject) RExtItem(com.evolveum.midpoint.repo.sql.data.common.any.RExtItem) AndCondition(com.evolveum.midpoint.repo.sql.query.hqm.condition.AndCondition)

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

Example 9 with Condition

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

Example 10 with Condition

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

Aggregations

Condition (com.evolveum.midpoint.repo.sql.query.hqm.condition.Condition)12 RootHibernateQuery (com.evolveum.midpoint.repo.sql.query.hqm.RootHibernateQuery)4 QueryException (com.evolveum.midpoint.repo.sqlbase.QueryException)4 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)3 AndCondition (com.evolveum.midpoint.repo.sql.query.hqm.condition.AndCondition)3 InterpretationContext (com.evolveum.midpoint.repo.sql.query.InterpretationContext)2 QueryInterpreter (com.evolveum.midpoint.repo.sql.query.QueryInterpreter)2 JoinSpecification (com.evolveum.midpoint.repo.sql.query.hqm.JoinSpecification)2 ConstantCondition (com.evolveum.midpoint.repo.sql.query.hqm.condition.ConstantCondition)2 ComparativeFilter (com.evolveum.midpoint.prism.query.ComparativeFilter)1 EqualFilter (com.evolveum.midpoint.prism.query.EqualFilter)1 ObjectFilter (com.evolveum.midpoint.prism.query.ObjectFilter)1 RObject (com.evolveum.midpoint.repo.sql.data.common.RObject)1 RExtItem (com.evolveum.midpoint.repo.sql.data.common.any.RExtItem)1 ExtItemDictionary (com.evolveum.midpoint.repo.sql.data.common.dictionary.ExtItemDictionary)1 RPolyString (com.evolveum.midpoint.repo.sql.data.common.embedded.RPolyString)1 RObjectType (com.evolveum.midpoint.repo.sql.data.common.other.RObjectType)1 JpaPropertyDefinition (com.evolveum.midpoint.repo.sql.query.definition.JpaPropertyDefinition)1 JunctionCondition (com.evolveum.midpoint.repo.sql.query.hqm.condition.JunctionCondition)1 HqlDataInstance (com.evolveum.midpoint.repo.sql.query.resolution.HqlDataInstance)1