Search in sources :

Example 1 with CollectionTableGroup

use of org.hibernate.sql.ast.tree.from.CollectionTableGroup in project hibernate-orm by hibernate.

the class PluralAttributeMappingImpl method generateFetch.

@Override
public Fetch generateFetch(FetchParent fetchParent, NavigablePath fetchablePath, FetchTiming fetchTiming, boolean selected, String resultVariable, DomainResultCreationState creationState) {
    final SqlAstCreationState sqlAstCreationState = creationState.getSqlAstCreationState();
    final boolean added = creationState.registerVisitedAssociationKey(fkDescriptor.getAssociationKey());
    try {
        if (fetchTiming == FetchTiming.IMMEDIATE) {
            if (selected) {
                final TableGroup collectionTableGroup = resolveCollectionTableGroup(fetchParent, fetchablePath, creationState, sqlAstCreationState);
                return new EagerCollectionFetch(fetchablePath, this, collectionTableGroup, fetchParent, creationState);
            } else {
                return createSelectEagerCollectionFetch(fetchParent, fetchablePath, creationState, sqlAstCreationState);
            }
        }
        if (getCollectionDescriptor().getCollectionType().hasHolder()) {
            return createSelectEagerCollectionFetch(fetchParent, fetchablePath, creationState, sqlAstCreationState);
        }
        return createDelayedCollectionFetch(fetchParent, fetchablePath, creationState, sqlAstCreationState);
    } finally {
        // and on top of this, we are not handling circular fetches for plural attributes yet
        if (added) {
            creationState.removeVisitedAssociationKey(fkDescriptor.getAssociationKey());
        }
    }
}
Also used : CollectionTableGroup(org.hibernate.sql.ast.tree.from.CollectionTableGroup) OneToManyTableGroup(org.hibernate.sql.ast.tree.from.OneToManyTableGroup) TableGroup(org.hibernate.sql.ast.tree.from.TableGroup) SqlAstCreationState(org.hibernate.sql.ast.spi.SqlAstCreationState) SelectEagerCollectionFetch(org.hibernate.sql.results.graph.collection.internal.SelectEagerCollectionFetch) EagerCollectionFetch(org.hibernate.sql.results.graph.collection.internal.EagerCollectionFetch)

Example 2 with CollectionTableGroup

use of org.hibernate.sql.ast.tree.from.CollectionTableGroup in project hibernate-orm by hibernate.

the class PluralAttributeMappingImpl method createCollectionTableGroup.

private TableGroup createCollectionTableGroup(boolean canUseInnerJoins, NavigablePath navigablePath, boolean fetched, String sourceAlias, SqlAliasBase sqlAliasBase, SqlExpressionResolver sqlExpressionResolver, FromClauseAccess fromClauseAccess, SqlAstCreationContext creationContext) {
    assert !getCollectionDescriptor().isOneToMany();
    final String collectionTableName = ((Joinable) collectionDescriptor).getTableName();
    final TableReference collectionTableReference = new NamedTableReference(collectionTableName, sqlAliasBase.generateNewAlias(), true, creationContext.getSessionFactory());
    final CollectionTableGroup tableGroup = new CollectionTableGroup(canUseInnerJoins, navigablePath, this, fetched, sourceAlias, collectionTableReference, true, sqlAliasBase, s -> false, null, creationContext.getSessionFactory());
    if (elementDescriptor instanceof TableGroupJoinProducer) {
        final TableGroupJoin tableGroupJoin = ((TableGroupJoinProducer) elementDescriptor).createTableGroupJoin(navigablePath.append(CollectionPart.Nature.ELEMENT.getName()), tableGroup, null, SqlAstJoinType.INNER, fetched, false, stem -> sqlAliasBase, sqlExpressionResolver, fromClauseAccess, creationContext);
        tableGroup.registerElementTableGroup(tableGroupJoin);
    }
    if (indexDescriptor instanceof TableGroupJoinProducer) {
        final TableGroupJoin tableGroupJoin = ((TableGroupJoinProducer) indexDescriptor).createTableGroupJoin(navigablePath.append(CollectionPart.Nature.INDEX.getName()), tableGroup, null, SqlAstJoinType.INNER, fetched, false, stem -> sqlAliasBase, sqlExpressionResolver, fromClauseAccess, creationContext);
        tableGroup.registerIndexTableGroup(tableGroupJoin);
    }
    return tableGroup;
}
Also used : TableGroupJoin(org.hibernate.sql.ast.tree.from.TableGroupJoin) TableReference(org.hibernate.sql.ast.tree.from.TableReference) NamedTableReference(org.hibernate.sql.ast.tree.from.NamedTableReference) NamedTableReference(org.hibernate.sql.ast.tree.from.NamedTableReference) TableGroupJoinProducer(org.hibernate.sql.ast.tree.from.TableGroupJoinProducer) Joinable(org.hibernate.persister.entity.Joinable) CollectionTableGroup(org.hibernate.sql.ast.tree.from.CollectionTableGroup)

Example 3 with CollectionTableGroup

use of org.hibernate.sql.ast.tree.from.CollectionTableGroup in project hibernate-orm by hibernate.

the class PluralAttributeMappingImpl method createDomainResult.

@Override
public <T> DomainResult<T> createDomainResult(NavigablePath navigablePath, TableGroup tableGroup, String resultVariable, DomainResultCreationState creationState) {
    final TableGroup collectionTableGroup = creationState.getSqlAstCreationState().getFromClauseAccess().getTableGroup(navigablePath);
    assert collectionTableGroup != null;
    // This is only used for collection initialization where we know the owner is available, so we mark it as visited
    // which will cause bidirectional to-one associations to be treated as such and avoid a join
    creationState.registerVisitedAssociationKey(fkDescriptor.getAssociationKey());
    // noinspection unchecked
    return new CollectionDomainResult(navigablePath, this, resultVariable, tableGroup, creationState);
}
Also used : CollectionDomainResult(org.hibernate.sql.results.graph.collection.internal.CollectionDomainResult) CollectionTableGroup(org.hibernate.sql.ast.tree.from.CollectionTableGroup) OneToManyTableGroup(org.hibernate.sql.ast.tree.from.OneToManyTableGroup) TableGroup(org.hibernate.sql.ast.tree.from.TableGroup)

Aggregations

CollectionTableGroup (org.hibernate.sql.ast.tree.from.CollectionTableGroup)3 OneToManyTableGroup (org.hibernate.sql.ast.tree.from.OneToManyTableGroup)2 TableGroup (org.hibernate.sql.ast.tree.from.TableGroup)2 Joinable (org.hibernate.persister.entity.Joinable)1 SqlAstCreationState (org.hibernate.sql.ast.spi.SqlAstCreationState)1 NamedTableReference (org.hibernate.sql.ast.tree.from.NamedTableReference)1 TableGroupJoin (org.hibernate.sql.ast.tree.from.TableGroupJoin)1 TableGroupJoinProducer (org.hibernate.sql.ast.tree.from.TableGroupJoinProducer)1 TableReference (org.hibernate.sql.ast.tree.from.TableReference)1 CollectionDomainResult (org.hibernate.sql.results.graph.collection.internal.CollectionDomainResult)1 EagerCollectionFetch (org.hibernate.sql.results.graph.collection.internal.EagerCollectionFetch)1 SelectEagerCollectionFetch (org.hibernate.sql.results.graph.collection.internal.SelectEagerCollectionFetch)1