Search in sources :

Example 1 with JoinSpecification

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

the class ItemPathResolver method addJoin.

String addJoin(JpaLinkDefinition joinedItemDefinition, String currentHqlPath) throws QueryException {
    RootHibernateQuery hibernateQuery = context.getHibernateQuery();
    String joinedItemJpaName = joinedItemDefinition.getJpaName();
    String joinedItemFullPath = currentHqlPath + "." + joinedItemJpaName;
    String joinedItemAlias;
    if (!joinedItemDefinition.isMultivalued()) {
        /*
             * 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.
             */
        JoinSpecification existingJoin = hibernateQuery.getPrimaryEntity().findJoinFor(joinedItemFullPath);
        if (existingJoin != null) {
            // 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 (ObjectUtils.equals(conditionForExistingAlias, existingJoin.getCondition())) {
                LOGGER.trace("Reusing alias '{}' for joined path '{}'", existingAlias, joinedItemFullPath);
                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.query2.hqm.condition.AndCondition) Condition(com.evolveum.midpoint.repo.sql.query2.hqm.condition.Condition) RootHibernateQuery(com.evolveum.midpoint.repo.sql.query2.hqm.RootHibernateQuery) JoinSpecification(com.evolveum.midpoint.repo.sql.query2.hqm.JoinSpecification)

Example 2 with JoinSpecification

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

the class ItemPathResolver method addTextInfoJoin.

public String addTextInfoJoin(String currentHqlPath) throws QueryException {
    RootHibernateQuery hibernateQuery = context.getHibernateQuery();
    String joinedItemJpaName = RObject.F_TEXT_INFO_ITEMS;
    String joinedItemFullPath = currentHqlPath + "." + joinedItemJpaName;
    String joinedItemAlias = hibernateQuery.createAlias(joinedItemJpaName, false);
    hibernateQuery.getPrimaryEntity().addJoin(new JoinSpecification(joinedItemAlias, joinedItemFullPath, null));
    return joinedItemAlias;
}
Also used : RootHibernateQuery(com.evolveum.midpoint.repo.sql.query2.hqm.RootHibernateQuery) JoinSpecification(com.evolveum.midpoint.repo.sql.query2.hqm.JoinSpecification)

Aggregations

JoinSpecification (com.evolveum.midpoint.repo.sql.query2.hqm.JoinSpecification)2 RootHibernateQuery (com.evolveum.midpoint.repo.sql.query2.hqm.RootHibernateQuery)2 AndCondition (com.evolveum.midpoint.repo.sql.query2.hqm.condition.AndCondition)1 Condition (com.evolveum.midpoint.repo.sql.query2.hqm.condition.Condition)1