Search in sources :

Example 21 with TableGroup

use of org.hibernate.sql.ast.tree.from.TableGroup 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 22 with TableGroup

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

the class PluralAttributeMappingImpl method createTableGroupJoin.

@Override
public TableGroupJoin createTableGroupJoin(NavigablePath navigablePath, TableGroup lhs, String explicitSourceAlias, SqlAstJoinType requestedJoinType, boolean fetched, boolean addsPredicate, SqlAliasBaseGenerator aliasBaseGenerator, SqlExpressionResolver sqlExpressionResolver, FromClauseAccess fromClauseAccess, SqlAstCreationContext creationContext) {
    final SqlAstJoinType joinType;
    if (requestedJoinType == null) {
        joinType = SqlAstJoinType.INNER;
    } else {
        joinType = requestedJoinType;
    }
    final java.util.List<Predicate> predicates = new ArrayList<>(2);
    final TableGroup tableGroup = createRootTableGroupJoin(navigablePath, lhs, explicitSourceAlias, requestedJoinType, fetched, predicates::add, aliasBaseGenerator, sqlExpressionResolver, fromClauseAccess, creationContext);
    final TableGroupJoin tableGroupJoin = new TableGroupJoin(navigablePath, joinType, tableGroup, null);
    predicates.forEach(tableGroupJoin::applyPredicate);
    return tableGroupJoin;
}
Also used : TableGroupJoin(org.hibernate.sql.ast.tree.from.TableGroupJoin) CollectionTableGroup(org.hibernate.sql.ast.tree.from.CollectionTableGroup) OneToManyTableGroup(org.hibernate.sql.ast.tree.from.OneToManyTableGroup) TableGroup(org.hibernate.sql.ast.tree.from.TableGroup) SqlAstJoinType(org.hibernate.sql.ast.SqlAstJoinType) ArrayList(java.util.ArrayList) Predicate(org.hibernate.sql.ast.tree.predicate.Predicate)

Example 23 with TableGroup

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

the class PluralAttributeMappingImpl method createOneToManyTableGroup.

private TableGroup createOneToManyTableGroup(boolean canUseInnerJoins, NavigablePath navigablePath, boolean fetched, String sourceAlias, SqlAliasBase sqlAliasBase, SqlExpressionResolver sqlExpressionResolver, FromClauseAccess fromClauseAccess, SqlAstCreationContext creationContext) {
    final TableGroup elementTableGroup = ((EntityCollectionPart) elementDescriptor).createTableGroupInternal(canUseInnerJoins, navigablePath.append(CollectionPart.Nature.ELEMENT.getName()), fetched, sourceAlias, sqlAliasBase, sqlExpressionResolver, creationContext);
    final OneToManyTableGroup tableGroup = new OneToManyTableGroup(this, elementTableGroup, creationContext.getSessionFactory());
    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) OneToManyTableGroup(org.hibernate.sql.ast.tree.from.OneToManyTableGroup) CollectionTableGroup(org.hibernate.sql.ast.tree.from.CollectionTableGroup) OneToManyTableGroup(org.hibernate.sql.ast.tree.from.OneToManyTableGroup) TableGroup(org.hibernate.sql.ast.tree.from.TableGroup) TableGroupJoinProducer(org.hibernate.sql.ast.tree.from.TableGroupJoinProducer)

Example 24 with TableGroup

use of org.hibernate.sql.ast.tree.from.TableGroup 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)

Example 25 with TableGroup

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

the class BasicAttributeMapping method resolveSqlSelection.

private SqlSelection resolveSqlSelection(NavigablePath navigablePath, TableGroup tableGroup, boolean allowFkOptimization, DomainResultCreationState creationState) {
    final SqlExpressionResolver expressionResolver = creationState.getSqlAstCreationState().getSqlExpressionResolver();
    final TableReference tableReference = tableGroup.resolveTableReference(navigablePath, getContainingTableExpression(), allowFkOptimization);
    return expressionResolver.resolveSqlSelection(expressionResolver.resolveSqlExpression(SqlExpressionResolver.createColumnReferenceKey(tableReference, mappedColumnExpression), sqlAstProcessingState -> new ColumnReference(tableReference, this, creationState.getSqlAstCreationState().getCreationContext().getSessionFactory())), valueConverter == null ? getMappedType().getMappedJavaType() : valueConverter.getRelationalJavaType(), creationState.getSqlAstCreationState().getCreationContext().getSessionFactory().getTypeConfiguration());
}
Also used : BasicValuedModelPart(org.hibernate.metamodel.mapping.BasicValuedModelPart) DomainResultCreationState(org.hibernate.sql.results.graph.DomainResultCreationState) JdbcMapping(org.hibernate.metamodel.mapping.JdbcMapping) ColumnReference(org.hibernate.sql.ast.tree.expression.ColumnReference) JavaType(org.hibernate.type.descriptor.java.JavaType) Clause(org.hibernate.sql.ast.Clause) PropertyAccess(org.hibernate.property.access.spi.PropertyAccess) BasicFetch(org.hibernate.sql.results.graph.basic.BasicFetch) EntityMappingType(org.hibernate.metamodel.mapping.EntityMappingType) MappingType(org.hibernate.metamodel.mapping.MappingType) TableReference(org.hibernate.sql.ast.tree.from.TableReference) ValueGeneration(org.hibernate.tuple.ValueGeneration) ConvertibleModelPart(org.hibernate.metamodel.mapping.ConvertibleModelPart) BiConsumer(java.util.function.BiConsumer) ManagedMappingType(org.hibernate.metamodel.mapping.ManagedMappingType) SqlSelection(org.hibernate.sql.ast.spi.SqlSelection) SqlAstCreationState(org.hibernate.sql.ast.spi.SqlAstCreationState) FetchTiming(org.hibernate.engine.FetchTiming) SingularAttributeMapping(org.hibernate.metamodel.mapping.SingularAttributeMapping) NavigablePath(org.hibernate.query.spi.NavigablePath) DomainResult(org.hibernate.sql.results.graph.DomainResult) StateArrayContributorMetadataAccess(org.hibernate.metamodel.mapping.StateArrayContributorMetadataAccess) Fetch(org.hibernate.sql.results.graph.Fetch) BasicResult(org.hibernate.sql.results.graph.basic.BasicResult) SqlExpressionResolver(org.hibernate.sql.ast.spi.SqlExpressionResolver) NavigableRole(org.hibernate.metamodel.model.domain.NavigableRole) FetchStyle(org.hibernate.engine.FetchStyle) SelectableMapping(org.hibernate.metamodel.mapping.SelectableMapping) BasicValueConverter(org.hibernate.metamodel.model.convert.spi.BasicValueConverter) SelectableConsumer(org.hibernate.metamodel.mapping.SelectableConsumer) TableGroup(org.hibernate.sql.ast.tree.from.TableGroup) SharedSessionContractImplementor(org.hibernate.engine.spi.SharedSessionContractImplementor) IndexedConsumer(org.hibernate.mapping.IndexedConsumer) FetchParent(org.hibernate.sql.results.graph.FetchParent) TableReference(org.hibernate.sql.ast.tree.from.TableReference) SqlExpressionResolver(org.hibernate.sql.ast.spi.SqlExpressionResolver) ColumnReference(org.hibernate.sql.ast.tree.expression.ColumnReference)

Aggregations

TableGroup (org.hibernate.sql.ast.tree.from.TableGroup)144 NavigablePath (org.hibernate.query.spi.NavigablePath)56 LazyTableGroup (org.hibernate.sql.ast.tree.from.LazyTableGroup)56 PluralTableGroup (org.hibernate.sql.ast.tree.from.PluralTableGroup)46 TableGroupJoin (org.hibernate.sql.ast.tree.from.TableGroupJoin)41 TableReference (org.hibernate.sql.ast.tree.from.TableReference)40 PluralAttributeMapping (org.hibernate.metamodel.mapping.PluralAttributeMapping)37 ColumnReference (org.hibernate.sql.ast.tree.expression.ColumnReference)35 CorrelatedTableGroup (org.hibernate.sql.ast.tree.from.CorrelatedTableGroup)33 QueryPartTableGroup (org.hibernate.sql.ast.tree.from.QueryPartTableGroup)31 VirtualTableGroup (org.hibernate.sql.ast.tree.from.VirtualTableGroup)31 EntityMappingType (org.hibernate.metamodel.mapping.EntityMappingType)30 SqlExpressionResolver (org.hibernate.sql.ast.spi.SqlExpressionResolver)29 SqlSelection (org.hibernate.sql.ast.spi.SqlSelection)29 QuerySpec (org.hibernate.sql.ast.tree.select.QuerySpec)29 Fetch (org.hibernate.sql.results.graph.Fetch)29 Expression (org.hibernate.sql.ast.tree.expression.Expression)28 CorrelatedPluralTableGroup (org.hibernate.sql.ast.tree.from.CorrelatedPluralTableGroup)28 SessionFactoryImplementor (org.hibernate.engine.spi.SessionFactoryImplementor)27 SelectStatement (org.hibernate.sql.ast.tree.select.SelectStatement)27