Search in sources :

Example 11 with Condition

use of com.evolveum.midpoint.repo.sql.query.hqm.condition.Condition in project midpoint by Evolveum.

the class ItemPathResolver method findExistingAlias.

private String findExistingAlias(RootHibernateQuery hibernateQuery, JpaLinkDefinition<?> joinedItemDefinition, String joinedItemFullPath) throws QueryException {
    for (JoinSpecification existingJoin : hibernateQuery.getPrimaryEntity().getJoinsFor(joinedItemFullPath)) {
        // but let's check the condition as well
        String existingAlias = existingJoin.getAlias();
        // we have to create condition for existing alias, to be matched to existing condition
        Condition conditionForExistingAlias = createJoinCondition(existingAlias, joinedItemDefinition, hibernateQuery);
        if (Objects.equals(conditionForExistingAlias, existingJoin.getCondition())) {
            LOGGER.trace("Reusing alias '{}' for joined path '{}'", existingAlias, joinedItemFullPath);
            return existingAlias;
        }
    }
    return null;
}
Also used : AndCondition(com.evolveum.midpoint.repo.sql.query.hqm.condition.AndCondition) Condition(com.evolveum.midpoint.repo.sql.query.hqm.condition.Condition) JoinSpecification(com.evolveum.midpoint.repo.sql.query.hqm.JoinSpecification)

Example 12 with Condition

use of com.evolveum.midpoint.repo.sql.query.hqm.condition.Condition in project midpoint by Evolveum.

the class ItemPathResolver method reuseOrAddJoin.

String reuseOrAddJoin(JpaLinkDefinition<?> joinedItemDefinition, String currentHqlPath, boolean reuseMultivaluedJoins) throws QueryException {
    RootHibernateQuery hibernateQuery = context.getHibernateQuery();
    String joinedItemJpaName = joinedItemDefinition.getJpaName();
    String joinedItemFullPath = currentHqlPath + "." + joinedItemJpaName;
    String joinedItemAlias;
    if (joinedItemDefinition.isMultivalued()) {
        if (reuseMultivaluedJoins) {
            String existingAlias = findExistingAlias(hibernateQuery, joinedItemDefinition, joinedItemFullPath);
            if (existingAlias != null) {
                return existingAlias;
            } else {
                // TODO better explanation
                throw new QueryException("Couldn't reuse existing join for " + joinedItemDefinition + " in the context of " + currentHqlPath);
            }
        }
    } else {
        /*
             * Let's check if we were already here i.e. if we had already created this join.
             * This is to avoid useless creation of redundant joins for singleton items.
             *
             * But how can we be sure that item is singleton if we look only at the last segment (which is single-valued)?
             * Imagine we are creating join for single-valued entity of u.abc.(...).xyz.ent where
             * ent is single-valued and not embedded (so we are to create something like "left join u.abc.(...).xyz.ent e").
             * Then "u" is certainly a single value: either the root object, or some value pointed to by Exists restriction.
             * Also, abc, ..., xyz are surely single-valued: otherwise they would be connected by a join. So,
             * u.abc.(...).xyz.ent is a singleton.
             *
             * Look at it in other way: if e.g. xyz was multivalued, then we would have something like:
             * left join u.abc.(...).uvw.xyz x
             * left join x.ent e
             * And, therefore we would not be looking for u.abc.(...).xyz.ent.
             */
        String existingAlias = findExistingAlias(hibernateQuery, joinedItemDefinition, joinedItemFullPath);
        if (existingAlias != null) {
            return existingAlias;
        }
    }
    joinedItemAlias = hibernateQuery.createAlias(joinedItemDefinition);
    Condition condition = createJoinCondition(joinedItemAlias, joinedItemDefinition, hibernateQuery);
    hibernateQuery.getPrimaryEntity().addJoin(new JoinSpecification(joinedItemAlias, joinedItemFullPath, condition));
    return joinedItemAlias;
}
Also used : AndCondition(com.evolveum.midpoint.repo.sql.query.hqm.condition.AndCondition) Condition(com.evolveum.midpoint.repo.sql.query.hqm.condition.Condition) QueryException(com.evolveum.midpoint.repo.sqlbase.QueryException) RootHibernateQuery(com.evolveum.midpoint.repo.sql.query.hqm.RootHibernateQuery) JoinSpecification(com.evolveum.midpoint.repo.sql.query.hqm.JoinSpecification)

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