Search in sources :

Example 11 with JoinType

use of org.hibernate.sql.JoinType in project hibernate-orm by hibernate.

the class FromElementFactory method createCollection.

public FromElement createCollection(QueryableCollection queryableCollection, String role, JoinType joinType, boolean fetchFlag, boolean indexed) throws SemanticException {
    if (!collection) {
        throw new IllegalStateException("FromElementFactory not initialized for collections!");
    }
    this.inElementsFunction = indexed;
    FromElement elem;
    this.queryableCollection = queryableCollection;
    collectionType = queryableCollection.getCollectionType();
    String roleAlias = fromClause.getAliasGenerator().createName(role);
    // Correlated subqueries create 'special' implied from nodes
    // because correlated subselects can't use an ANSI-style join
    boolean explicitSubqueryFromElement = fromClause.isSubQuery() && !implied;
    if (explicitSubqueryFromElement) {
        String pathRoot = StringHelper.root(path);
        FromElement origin = fromClause.getFromElement(pathRoot);
        if (origin == null || origin.getFromClause() != fromClause) {
            implied = true;
        }
    }
    // super-duper-classic-parser-regression-testing-mojo-magic...
    if (explicitSubqueryFromElement && DotNode.useThetaStyleImplicitJoins) {
        implied = true;
    }
    Type elementType = queryableCollection.getElementType();
    if (elementType.isEntityType()) {
        // A collection of entities...
        elem = createEntityAssociation(role, roleAlias, joinType);
    } else if (elementType.isComponentType()) {
        // A collection of components...
        JoinSequence joinSequence = createJoinSequence(roleAlias, joinType);
        elem = createCollectionJoin(joinSequence, roleAlias);
    } else {
        // A collection of scalar elements...
        JoinSequence joinSequence = createJoinSequence(roleAlias, joinType);
        elem = createCollectionJoin(joinSequence, roleAlias);
    }
    elem.setRole(role);
    elem.setQueryableCollection(queryableCollection);
    // Don't include sub-classes for implied collection joins or subquery joins.
    if (implied) {
        elem.setIncludeSubclasses(false);
    }
    if (explicitSubqueryFromElement) {
        // Treat explict from elements in sub-queries properly.
        elem.setInProjectionList(true);
    }
    if (fetchFlag) {
        elem.setFetch(true);
    }
    return elem;
}
Also used : JoinType(org.hibernate.sql.JoinType) CollectionType(org.hibernate.type.CollectionType) EntityType(org.hibernate.type.EntityType) CompositeType(org.hibernate.type.CompositeType) AssociationType(org.hibernate.type.AssociationType) Type(org.hibernate.type.Type) JoinSequence(org.hibernate.engine.internal.JoinSequence)

Aggregations

JoinType (org.hibernate.sql.JoinType)11 CompositeType (org.hibernate.type.CompositeType)6 AssociationType (org.hibernate.type.AssociationType)5 EntityType (org.hibernate.type.EntityType)5 Type (org.hibernate.type.Type)5 CollectionType (org.hibernate.type.CollectionType)3 SemanticException (antlr.SemanticException)2 QueryException (org.hibernate.QueryException)2 JoinSequence (org.hibernate.engine.internal.JoinSequence)2 EntityPersister (org.hibernate.persister.entity.EntityPersister)2 FetchMode (org.hibernate.FetchMode)1 DotNode (org.hibernate.hql.internal.ast.tree.DotNode)1 EntityJoinFromElement (org.hibernate.hql.internal.ast.tree.EntityJoinFromElement)1 FromElement (org.hibernate.hql.internal.ast.tree.FromElement)1 FromElementFactory (org.hibernate.hql.internal.ast.tree.FromElementFactory)1 FromReferenceNode (org.hibernate.hql.internal.ast.tree.FromReferenceNode)1 SessionFactoryHelper (org.hibernate.hql.internal.ast.util.SessionFactoryHelper)1 CriteriaImpl (org.hibernate.internal.CriteriaImpl)1 QueryableCollection (org.hibernate.persister.collection.QueryableCollection)1 JoinFragment (org.hibernate.sql.JoinFragment)1