Search in sources :

Example 11 with RootHibernateQuery

use of com.evolveum.midpoint.repo.sql.query2.hqm.RootHibernateQuery 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 12 with RootHibernateQuery

use of com.evolveum.midpoint.repo.sql.query2.hqm.RootHibernateQuery 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 13 with RootHibernateQuery

use of com.evolveum.midpoint.repo.sql.query2.hqm.RootHibernateQuery 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;
}
Also used : QName(javax.xml.namespace.QName) RUtil.qnameToString(com.evolveum.midpoint.repo.sql.util.RUtil.qnameToString) JpaAnyReferenceDefinition(com.evolveum.midpoint.repo.sql.query2.definition.JpaAnyReferenceDefinition) AndCondition(com.evolveum.midpoint.repo.sql.query2.hqm.condition.AndCondition)

Example 14 with RootHibernateQuery

use of com.evolveum.midpoint.repo.sql.query2.hqm.RootHibernateQuery in project midpoint by Evolveum.

the class TypeRestriction method interpret.

@Override
public Condition interpret() throws QueryException {
    InterpretationContext context = getContext();
    RootHibernateQuery hibernateQuery = context.getHibernateQuery();
    String property = getBaseHqlEntity().getHqlPath() + "." + RObject.F_OBJECT_TYPE_CLASS;
    Set<RObjectType> values = getValues(filter.getType());
    Condition basedOnType;
    if (values.size() > 1) {
        basedOnType = hibernateQuery.createIn(property, values);
    } else {
        basedOnType = hibernateQuery.createEq(property, values.iterator().next());
    }
    if (filter.getFilter() == null) {
        return basedOnType;
    }
    QueryInterpreter2 interpreter = context.getInterpreter();
    Condition basedOnFilter = interpreter.interpretFilter(context, filter.getFilter(), this);
    return hibernateQuery.createAnd(basedOnType, basedOnFilter);
}
Also used : Condition(com.evolveum.midpoint.repo.sql.query2.hqm.condition.Condition) RObjectType(com.evolveum.midpoint.repo.sql.data.common.other.RObjectType) InterpretationContext(com.evolveum.midpoint.repo.sql.query2.InterpretationContext) RootHibernateQuery(com.evolveum.midpoint.repo.sql.query2.hqm.RootHibernateQuery) QueryInterpreter2(com.evolveum.midpoint.repo.sql.query2.QueryInterpreter2)

Example 15 with RootHibernateQuery

use of com.evolveum.midpoint.repo.sql.query2.hqm.RootHibernateQuery 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;
}
Also used : AndCondition(com.evolveum.midpoint.repo.sql.query2.hqm.condition.AndCondition) Condition(com.evolveum.midpoint.repo.sql.query2.hqm.condition.Condition) JpaAnyItemLinkDefinition(com.evolveum.midpoint.repo.sql.query2.definition.JpaAnyItemLinkDefinition) VirtualQueryParam(com.evolveum.midpoint.repo.sql.query.definition.VirtualQueryParam) VirtualCollectionSpecification(com.evolveum.midpoint.repo.sql.query2.definition.VirtualCollectionSpecification) ArrayList(java.util.ArrayList) List(java.util.List) RObject(com.evolveum.midpoint.repo.sql.data.common.RObject) AndCondition(com.evolveum.midpoint.repo.sql.query2.hqm.condition.AndCondition)

Aggregations

RootHibernateQuery (com.evolveum.midpoint.repo.sql.query2.hqm.RootHibernateQuery)13 QueryException (com.evolveum.midpoint.repo.sql.query.QueryException)7 Condition (com.evolveum.midpoint.repo.sql.query2.hqm.condition.Condition)6 AndCondition (com.evolveum.midpoint.repo.sql.query2.hqm.condition.AndCondition)5 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)4 RPolyString (com.evolveum.midpoint.repo.sql.data.common.embedded.RPolyString)3 QName (javax.xml.namespace.QName)3 QueryInterpreter2 (com.evolveum.midpoint.repo.sql.query2.QueryInterpreter2)2 JoinSpecification (com.evolveum.midpoint.repo.sql.query2.hqm.JoinSpecification)2 OrCondition (com.evolveum.midpoint.repo.sql.query2.hqm.condition.OrCondition)2 HqlDataInstance (com.evolveum.midpoint.repo.sql.query2.resolution.HqlDataInstance)2 RUtil.qnameToString (com.evolveum.midpoint.repo.sql.util.RUtil.qnameToString)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 ObjectPagingAfterOid (com.evolveum.midpoint.repo.sql.ObjectPagingAfterOid)1 RObject (com.evolveum.midpoint.repo.sql.data.common.RObject)1 RObjectType (com.evolveum.midpoint.repo.sql.data.common.other.RObjectType)1