Search in sources :

Example 1 with DomainResultCreationState

use of org.hibernate.sql.results.graph.DomainResultCreationState in project hibernate-orm by hibernate.

the class ToOneAttributeMapping method generateFetch.

@Override
public EntityFetch generateFetch(FetchParent fetchParent, NavigablePath fetchablePath, FetchTiming fetchTiming, boolean selected, String resultVariable, DomainResultCreationState creationState) {
    final SqlAstCreationState sqlAstCreationState = creationState.getSqlAstCreationState();
    final FromClauseAccess fromClauseAccess = sqlAstCreationState.getFromClauseAccess();
    final TableGroup parentTableGroup = fromClauseAccess.getTableGroup(fetchParent.getNavigablePath());
    final NavigablePath parentNavigablePath = fetchablePath.getParent();
    assert parentNavigablePath.equals(fetchParent.getNavigablePath()) || fetchParent.getNavigablePath() instanceof TreatedNavigablePath && parentNavigablePath.equals(fetchParent.getNavigablePath().getRealParent());
    if (fetchTiming == FetchTiming.IMMEDIATE && selected) {
        final TableGroup tableGroup;
        if (fetchParent instanceof EntityResultJoinedSubclassImpl && ((EntityPersister) fetchParent.getReferencedModePart()).findDeclaredAttributeMapping(getPartName()) == null) {
            final TableGroupJoin tableGroupJoin = createTableGroupJoin(fetchablePath, parentTableGroup, resultVariable, getJoinType(fetchablePath, parentTableGroup), true, false, creationState.getSqlAstCreationState());
            parentTableGroup.addTableGroupJoin(tableGroupJoin);
            tableGroup = tableGroupJoin.getJoinedGroup();
            fromClauseAccess.registerTableGroup(fetchablePath, tableGroup);
        } else {
            tableGroup = fromClauseAccess.resolveTableGroup(fetchablePath, np -> {
                final TableGroupJoin tableGroupJoin = createTableGroupJoin(fetchablePath, parentTableGroup, resultVariable, getDefaultSqlAstJoinType(parentTableGroup), true, false, creationState.getSqlAstCreationState());
                parentTableGroup.addTableGroupJoin(tableGroupJoin);
                return tableGroupJoin.getJoinedGroup();
            });
        }
        final boolean added = creationState.registerVisitedAssociationKey(foreignKeyDescriptor.getAssociationKey());
        AssociationKey additionalAssociationKey = null;
        if (cardinality == Cardinality.LOGICAL_ONE_TO_ONE && bidirectionalAttributeName != null) {
            final ModelPart bidirectionalModelPart = entityMappingType.findSubPart(bidirectionalAttributeName);
            // Add the inverse association key side as well to be able to resolve to a CircularFetch
            if (bidirectionalModelPart instanceof ToOneAttributeMapping) {
                assert bidirectionalModelPart.getPartMappingType() == declaringTableGroupProducer;
                final ToOneAttributeMapping bidirectionalAttribute = (ToOneAttributeMapping) bidirectionalModelPart;
                final AssociationKey secondKey = bidirectionalAttribute.getForeignKeyDescriptor().getAssociationKey();
                if (creationState.registerVisitedAssociationKey(secondKey)) {
                    additionalAssociationKey = secondKey;
                }
            }
        }
        final EntityFetchJoinedImpl entityFetchJoined = new EntityFetchJoinedImpl(fetchParent, this, tableGroup, fetchablePath, creationState);
        if (added) {
            creationState.removeVisitedAssociationKey(foreignKeyDescriptor.getAssociationKey());
        }
        if (additionalAssociationKey != null) {
            creationState.removeVisitedAssociationKey(additionalAssociationKey);
        }
        return entityFetchJoined;
    }
    /*
			1. No JoinTable
				Model:
					EntityA{
						@ManyToOne
						EntityB b
					}

					EntityB{
						@ManyToOne
						EntityA a
					}

				Relational:
					ENTITY_A( id )
					ENTITY_B( id, entity_a_id)

				1.1 EntityA -> EntityB : as keyResult we need ENTITY_B.id
				1.2 EntityB -> EntityA : as keyResult we need ENTITY_B.entity_a_id (FK referring column)

			2. JoinTable

		 */
    final ForeignKeyDescriptor.Nature resolvingKeySideOfForeignKey = creationState.getCurrentlyResolvingForeignKeyPart();
    final ForeignKeyDescriptor.Nature side;
    if (resolvingKeySideOfForeignKey == ForeignKeyDescriptor.Nature.KEY && this.sideNature == ForeignKeyDescriptor.Nature.TARGET) {
        // If we are currently resolving the key part of a foreign key we do not want to add joins.
        // So if the lhs of this association is the target of the FK, we have to use the KEY part to avoid a join
        side = ForeignKeyDescriptor.Nature.KEY;
    } else {
        side = this.sideNature;
    }
    final DomainResult<?> keyResult = foreignKeyDescriptor.createDomainResult(fetchablePath, parentTableGroup, side, creationState);
    final boolean selectByUniqueKey = isSelectByUniqueKey(side);
    if (fetchTiming == FetchTiming.IMMEDIATE) {
        return new EntityFetchSelectImpl(fetchParent, this, fetchablePath, keyResult, selectByUniqueKey, creationState);
    }
    return new EntityDelayedFetchImpl(fetchParent, this, fetchablePath, keyResult, selectByUniqueKey);
}
Also used : EntityPersister(org.hibernate.persister.entity.EntityPersister) AbstractEntityPersister(org.hibernate.persister.entity.AbstractEntityPersister) Arrays(java.util.Arrays) EntityPersister(org.hibernate.persister.entity.EntityPersister) Property(org.hibernate.mapping.Property) TableGroupJoin(org.hibernate.sql.ast.tree.from.TableGroupJoin) TreatedNavigablePath(org.hibernate.query.spi.TreatedNavigablePath) PropertyAccess(org.hibernate.property.access.spi.PropertyAccess) EntityResultImpl(org.hibernate.sql.results.graph.entity.internal.EntityResultImpl) EntityMappingType(org.hibernate.metamodel.mapping.EntityMappingType) ToOne(org.hibernate.mapping.ToOne) SqlAstCreationContext(org.hibernate.sql.ast.spi.SqlAstCreationContext) PluralAttributeMapping(org.hibernate.metamodel.mapping.PluralAttributeMapping) EntityAssociationMapping(org.hibernate.metamodel.mapping.EntityAssociationMapping) ForeignKeyDescriptor(org.hibernate.metamodel.mapping.ForeignKeyDescriptor) PersistentClass(org.hibernate.mapping.PersistentClass) FetchOptions(org.hibernate.sql.results.graph.FetchOptions) Join(org.hibernate.mapping.Join) TableGroupProducer(org.hibernate.sql.ast.tree.from.TableGroupProducer) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) EntityDelayedResultImpl(org.hibernate.sql.results.graph.entity.internal.EntityDelayedResultImpl) CollectionPart(org.hibernate.metamodel.mapping.CollectionPart) SqlSelection(org.hibernate.sql.ast.spi.SqlSelection) CorrelatedTableGroup(org.hibernate.sql.ast.tree.from.CorrelatedTableGroup) EntityValuedFetchable(org.hibernate.sql.results.graph.entity.EntityValuedFetchable) EntityDelayedFetchImpl(org.hibernate.sql.results.graph.entity.internal.EntityDelayedFetchImpl) MappedByTableGroup(org.hibernate.sql.ast.tree.from.MappedByTableGroup) TableGroupJoinProducer(org.hibernate.sql.ast.tree.from.TableGroupJoinProducer) LazyTableGroup(org.hibernate.sql.ast.tree.from.LazyTableGroup) OneToOne(org.hibernate.mapping.OneToOne) VirtualModelPart(org.hibernate.metamodel.mapping.VirtualModelPart) NavigablePath(org.hibernate.query.spi.NavigablePath) StringHelper(org.hibernate.internal.util.StringHelper) DomainResult(org.hibernate.sql.results.graph.DomainResult) Set(java.util.Set) Value(org.hibernate.mapping.Value) Collection(org.hibernate.mapping.Collection) SqlAliasBase(org.hibernate.sql.ast.spi.SqlAliasBase) SqlExpressionResolver(org.hibernate.sql.ast.spi.SqlExpressionResolver) EntityIdentifierMapping(org.hibernate.metamodel.mapping.EntityIdentifierMapping) NavigableRole(org.hibernate.metamodel.model.domain.NavigableRole) ArrayHelper(org.hibernate.internal.util.collections.ArrayHelper) CircularBiDirectionalFetchImpl(org.hibernate.sql.results.internal.domain.CircularBiDirectionalFetchImpl) AbstractEntityPersister(org.hibernate.persister.entity.AbstractEntityPersister) SelectableConsumer(org.hibernate.metamodel.mapping.SelectableConsumer) SharedSessionContractImplementor(org.hibernate.engine.spi.SharedSessionContractImplementor) IndexedConsumer(org.hibernate.mapping.IndexedConsumer) FetchParent(org.hibernate.sql.results.graph.FetchParent) CircularFetchImpl(org.hibernate.sql.results.internal.domain.CircularFetchImpl) DomainResultCreationState(org.hibernate.sql.results.graph.DomainResultCreationState) SqlAliasBaseGenerator(org.hibernate.sql.ast.spi.SqlAliasBaseGenerator) EntityFetchSelectImpl(org.hibernate.sql.results.graph.entity.internal.EntityFetchSelectImpl) JdbcMapping(org.hibernate.metamodel.mapping.JdbcMapping) EntityResultJoinedSubclassImpl(org.hibernate.sql.results.graph.entity.internal.EntityResultJoinedSubclassImpl) SqlAliasStemHelper(org.hibernate.sql.ast.spi.SqlAliasStemHelper) EmbeddedComponentType(org.hibernate.type.EmbeddedComponentType) EntityType(org.hibernate.type.EntityType) Clause(org.hibernate.sql.ast.Clause) TableReference(org.hibernate.sql.ast.tree.from.TableReference) HashSet(java.util.HashSet) ModelPart(org.hibernate.metamodel.mapping.ModelPart) ComponentType(org.hibernate.type.ComponentType) CompositeType(org.hibernate.type.CompositeType) BiConsumer(java.util.function.BiConsumer) ManagedMappingType(org.hibernate.metamodel.mapping.ManagedMappingType) EntityIdentifierNavigablePath(org.hibernate.query.sqm.spi.EntityIdentifierNavigablePath) StandardTableGroup(org.hibernate.sql.ast.tree.from.StandardTableGroup) SqlAstCreationState(org.hibernate.sql.ast.spi.SqlAstCreationState) FetchTiming(org.hibernate.engine.FetchTiming) ManyToOne(org.hibernate.mapping.ManyToOne) LockMode(org.hibernate.LockMode) AssociationKey(org.hibernate.metamodel.mapping.AssociationKey) Predicate(org.hibernate.sql.ast.tree.predicate.Predicate) Iterator(java.util.Iterator) ModelPartContainer(org.hibernate.metamodel.mapping.ModelPartContainer) EmbeddableValuedFetchable(org.hibernate.sql.results.graph.embeddable.EmbeddableValuedFetchable) StateArrayContributorMetadataAccess(org.hibernate.metamodel.mapping.StateArrayContributorMetadataAccess) Fetch(org.hibernate.sql.results.graph.Fetch) Consumer(java.util.function.Consumer) QueryableCollection(org.hibernate.persister.collection.QueryableCollection) EntityFetch(org.hibernate.sql.results.graph.entity.EntityFetch) FetchStyle(org.hibernate.engine.FetchStyle) FromClauseAccess(org.hibernate.sql.ast.spi.FromClauseAccess) SqlAstJoinType(org.hibernate.sql.ast.SqlAstJoinType) Selectable(org.hibernate.mapping.Selectable) EmbeddableValuedModelPart(org.hibernate.metamodel.mapping.EmbeddableValuedModelPart) Collections(java.util.Collections) TableGroup(org.hibernate.sql.ast.tree.from.TableGroup) PluralTableGroup(org.hibernate.sql.ast.tree.from.PluralTableGroup) EntityFetchJoinedImpl(org.hibernate.sql.results.graph.entity.internal.EntityFetchJoinedImpl) Type(org.hibernate.type.Type) EntityFetchJoinedImpl(org.hibernate.sql.results.graph.entity.internal.EntityFetchJoinedImpl) AssociationKey(org.hibernate.metamodel.mapping.AssociationKey) CorrelatedTableGroup(org.hibernate.sql.ast.tree.from.CorrelatedTableGroup) MappedByTableGroup(org.hibernate.sql.ast.tree.from.MappedByTableGroup) LazyTableGroup(org.hibernate.sql.ast.tree.from.LazyTableGroup) StandardTableGroup(org.hibernate.sql.ast.tree.from.StandardTableGroup) TableGroup(org.hibernate.sql.ast.tree.from.TableGroup) PluralTableGroup(org.hibernate.sql.ast.tree.from.PluralTableGroup) TreatedNavigablePath(org.hibernate.query.spi.TreatedNavigablePath) NavigablePath(org.hibernate.query.spi.NavigablePath) EntityIdentifierNavigablePath(org.hibernate.query.sqm.spi.EntityIdentifierNavigablePath) VirtualModelPart(org.hibernate.metamodel.mapping.VirtualModelPart) ModelPart(org.hibernate.metamodel.mapping.ModelPart) EmbeddableValuedModelPart(org.hibernate.metamodel.mapping.EmbeddableValuedModelPart) EntityResultJoinedSubclassImpl(org.hibernate.sql.results.graph.entity.internal.EntityResultJoinedSubclassImpl) EntityDelayedFetchImpl(org.hibernate.sql.results.graph.entity.internal.EntityDelayedFetchImpl) TableGroupJoin(org.hibernate.sql.ast.tree.from.TableGroupJoin) TreatedNavigablePath(org.hibernate.query.spi.TreatedNavigablePath) FromClauseAccess(org.hibernate.sql.ast.spi.FromClauseAccess) SqlAstCreationState(org.hibernate.sql.ast.spi.SqlAstCreationState) ForeignKeyDescriptor(org.hibernate.metamodel.mapping.ForeignKeyDescriptor) EntityFetchSelectImpl(org.hibernate.sql.results.graph.entity.internal.EntityFetchSelectImpl)

Example 2 with DomainResultCreationState

use of org.hibernate.sql.results.graph.DomainResultCreationState in project hibernate-orm by hibernate.

the class EntityVersionMappingImpl method resolveSqlSelection.

private SqlSelection resolveSqlSelection(TableGroup tableGroup, DomainResultCreationState creationState) {
    final SqlAstCreationState sqlAstCreationState = creationState.getSqlAstCreationState();
    final SqlExpressionResolver sqlExpressionResolver = sqlAstCreationState.getSqlExpressionResolver();
    final TableReference columnTableReference = tableGroup.resolveTableReference(tableGroup.getNavigablePath().append(getNavigableRole().getNavigableName()), columnTableExpression);
    return sqlExpressionResolver.resolveSqlSelection(sqlExpressionResolver.resolveSqlExpression(SqlExpressionResolver.createColumnReferenceKey(columnTableReference, columnExpression), sqlAstProcessingState -> new ColumnReference(columnTableReference, columnExpression, false, null, null, versionBasicType, sqlAstCreationState.getCreationContext().getSessionFactory())), versionBasicType.getJdbcMapping().getJavaTypeDescriptor(), sqlAstCreationState.getCreationContext().getSessionFactory().getTypeConfiguration());
}
Also used : DomainResultCreationState(org.hibernate.sql.results.graph.DomainResultCreationState) JdbcMapping(org.hibernate.metamodel.mapping.JdbcMapping) BasicType(org.hibernate.type.BasicType) UnsavedValueFactory(org.hibernate.engine.internal.UnsavedValueFactory) RootClass(org.hibernate.mapping.RootClass) ColumnReference(org.hibernate.sql.ast.tree.expression.ColumnReference) JavaType(org.hibernate.type.descriptor.java.JavaType) Clause(org.hibernate.sql.ast.Clause) Supplier(java.util.function.Supplier) 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) FetchOptions(org.hibernate.sql.results.graph.FetchOptions) BiConsumer(java.util.function.BiConsumer) EntityVersionMapping(org.hibernate.metamodel.mapping.EntityVersionMapping) SqlSelection(org.hibernate.sql.ast.spi.SqlSelection) SqlAstCreationState(org.hibernate.sql.ast.spi.SqlAstCreationState) FetchTiming(org.hibernate.engine.FetchTiming) NavigablePath(org.hibernate.query.spi.NavigablePath) DomainResult(org.hibernate.sql.results.graph.DomainResult) VersionJavaType(org.hibernate.type.descriptor.java.VersionJavaType) 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) VersionValue(org.hibernate.engine.spi.VersionValue) TableGroup(org.hibernate.sql.ast.tree.from.TableGroup) SharedSessionContractImplementor(org.hibernate.engine.spi.SharedSessionContractImplementor) KeyValue(org.hibernate.mapping.KeyValue) 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) SqlAstCreationState(org.hibernate.sql.ast.spi.SqlAstCreationState) ColumnReference(org.hibernate.sql.ast.tree.expression.ColumnReference)

Example 3 with DomainResultCreationState

use of org.hibernate.sql.results.graph.DomainResultCreationState in project hibernate-orm by hibernate.

the class EntityVersionMappingImpl method generateFetch.

@Override
public Fetch generateFetch(FetchParent fetchParent, NavigablePath fetchablePath, FetchTiming fetchTiming, boolean selected, String resultVariable, DomainResultCreationState creationState) {
    final SqlAstCreationState sqlAstCreationState = creationState.getSqlAstCreationState();
    final TableGroup tableGroup = sqlAstCreationState.getFromClauseAccess().findTableGroup(fetchParent.getNavigablePath());
    final SqlExpressionResolver sqlExpressionResolver = sqlAstCreationState.getSqlExpressionResolver();
    final TableReference columnTableReference = tableGroup.resolveTableReference(fetchablePath, columnTableExpression);
    final SqlSelection sqlSelection = sqlExpressionResolver.resolveSqlSelection(sqlExpressionResolver.resolveSqlExpression(SqlExpressionResolver.createColumnReferenceKey(columnTableReference, columnExpression), sqlAstProcessingState -> new ColumnReference(columnTableReference, columnExpression, false, null, null, versionBasicType, sqlAstCreationState.getCreationContext().getSessionFactory())), versionBasicType.getJdbcMapping().getJavaTypeDescriptor(), sqlAstCreationState.getCreationContext().getSessionFactory().getTypeConfiguration());
    return new BasicFetch<>(sqlSelection.getValuesArrayPosition(), fetchParent, fetchablePath, this, null, fetchTiming, creationState);
}
Also used : DomainResultCreationState(org.hibernate.sql.results.graph.DomainResultCreationState) JdbcMapping(org.hibernate.metamodel.mapping.JdbcMapping) BasicType(org.hibernate.type.BasicType) UnsavedValueFactory(org.hibernate.engine.internal.UnsavedValueFactory) RootClass(org.hibernate.mapping.RootClass) ColumnReference(org.hibernate.sql.ast.tree.expression.ColumnReference) JavaType(org.hibernate.type.descriptor.java.JavaType) Clause(org.hibernate.sql.ast.Clause) Supplier(java.util.function.Supplier) 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) FetchOptions(org.hibernate.sql.results.graph.FetchOptions) BiConsumer(java.util.function.BiConsumer) EntityVersionMapping(org.hibernate.metamodel.mapping.EntityVersionMapping) SqlSelection(org.hibernate.sql.ast.spi.SqlSelection) SqlAstCreationState(org.hibernate.sql.ast.spi.SqlAstCreationState) FetchTiming(org.hibernate.engine.FetchTiming) NavigablePath(org.hibernate.query.spi.NavigablePath) DomainResult(org.hibernate.sql.results.graph.DomainResult) VersionJavaType(org.hibernate.type.descriptor.java.VersionJavaType) 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) VersionValue(org.hibernate.engine.spi.VersionValue) TableGroup(org.hibernate.sql.ast.tree.from.TableGroup) SharedSessionContractImplementor(org.hibernate.engine.spi.SharedSessionContractImplementor) KeyValue(org.hibernate.mapping.KeyValue) IndexedConsumer(org.hibernate.mapping.IndexedConsumer) FetchParent(org.hibernate.sql.results.graph.FetchParent) BasicFetch(org.hibernate.sql.results.graph.basic.BasicFetch) TableReference(org.hibernate.sql.ast.tree.from.TableReference) TableGroup(org.hibernate.sql.ast.tree.from.TableGroup) SqlExpressionResolver(org.hibernate.sql.ast.spi.SqlExpressionResolver) SqlAstCreationState(org.hibernate.sql.ast.spi.SqlAstCreationState) SqlSelection(org.hibernate.sql.ast.spi.SqlSelection) ColumnReference(org.hibernate.sql.ast.tree.expression.ColumnReference)

Example 4 with DomainResultCreationState

use of org.hibernate.sql.results.graph.DomainResultCreationState 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)

Example 5 with DomainResultCreationState

use of org.hibernate.sql.results.graph.DomainResultCreationState in project hibernate-orm by hibernate.

the class CollectionIdentifierDescriptorImpl method generateFetch.

@Override
public Fetch generateFetch(FetchParent fetchParent, NavigablePath fetchablePath, FetchTiming fetchTiming, boolean selected, String resultVariable, DomainResultCreationState creationState) {
    // get the collection TableGroup
    final FromClauseAccess fromClauseAccess = creationState.getSqlAstCreationState().getFromClauseAccess();
    final TableGroup tableGroup = fromClauseAccess.getTableGroup(fetchablePath.getParent());
    final SqlAstCreationState astCreationState = creationState.getSqlAstCreationState();
    final SqlAstCreationContext astCreationContext = astCreationState.getCreationContext();
    final SessionFactoryImplementor sessionFactory = astCreationContext.getSessionFactory();
    final SqlExpressionResolver sqlExpressionResolver = astCreationState.getSqlExpressionResolver();
    final SqlSelection sqlSelection = sqlExpressionResolver.resolveSqlSelection(sqlExpressionResolver.resolveSqlExpression(SqlExpressionResolver.createColumnReferenceKey(tableGroup.getPrimaryTableReference(), columnName), p -> new ColumnReference(tableGroup.getPrimaryTableReference().getIdentificationVariable(), columnName, false, null, null, type, sessionFactory)), type.getJavaTypeDescriptor(), sessionFactory.getTypeConfiguration());
    return new BasicFetch<>(sqlSelection.getValuesArrayPosition(), fetchParent, fetchablePath, this, null, FetchTiming.IMMEDIATE, creationState);
}
Also used : DomainResultCreationState(org.hibernate.sql.results.graph.DomainResultCreationState) JdbcMapping(org.hibernate.metamodel.mapping.JdbcMapping) BasicType(org.hibernate.type.BasicType) ColumnReference(org.hibernate.sql.ast.tree.expression.ColumnReference) JavaType(org.hibernate.type.descriptor.java.JavaType) CollectionIdentifierDescriptor(org.hibernate.metamodel.mapping.CollectionIdentifierDescriptor) Clause(org.hibernate.sql.ast.Clause) BasicFetch(org.hibernate.sql.results.graph.basic.BasicFetch) EntityMappingType(org.hibernate.metamodel.mapping.EntityMappingType) MappingType(org.hibernate.metamodel.mapping.MappingType) SqlAstCreationContext(org.hibernate.sql.ast.spi.SqlAstCreationContext) FetchOptions(org.hibernate.sql.results.graph.FetchOptions) BiConsumer(java.util.function.BiConsumer) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) SqlSelection(org.hibernate.sql.ast.spi.SqlSelection) SqlAstCreationState(org.hibernate.sql.ast.spi.SqlAstCreationState) FetchTiming(org.hibernate.engine.FetchTiming) NavigablePath(org.hibernate.query.spi.NavigablePath) DomainResult(org.hibernate.sql.results.graph.DomainResult) 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) FromClauseAccess(org.hibernate.sql.ast.spi.FromClauseAccess) CollectionPersister(org.hibernate.persister.collection.CollectionPersister) 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) BasicFetch(org.hibernate.sql.results.graph.basic.BasicFetch) TableGroup(org.hibernate.sql.ast.tree.from.TableGroup) FromClauseAccess(org.hibernate.sql.ast.spi.FromClauseAccess) SqlAstCreationContext(org.hibernate.sql.ast.spi.SqlAstCreationContext) SqlExpressionResolver(org.hibernate.sql.ast.spi.SqlExpressionResolver) SqlAstCreationState(org.hibernate.sql.ast.spi.SqlAstCreationState) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) SqlSelection(org.hibernate.sql.ast.spi.SqlSelection) ColumnReference(org.hibernate.sql.ast.tree.expression.ColumnReference)

Aggregations

DomainResultCreationState (org.hibernate.sql.results.graph.DomainResultCreationState)20 SqlExpressionResolver (org.hibernate.sql.ast.spi.SqlExpressionResolver)17 NavigablePath (org.hibernate.query.spi.NavigablePath)16 TableGroup (org.hibernate.sql.ast.tree.from.TableGroup)16 SqlSelection (org.hibernate.sql.ast.spi.SqlSelection)14 FetchTiming (org.hibernate.engine.FetchTiming)13 Fetch (org.hibernate.sql.results.graph.Fetch)13 FetchParent (org.hibernate.sql.results.graph.FetchParent)13 BasicResult (org.hibernate.sql.results.graph.basic.BasicResult)13 TableReference (org.hibernate.sql.ast.tree.from.TableReference)12 JdbcMapping (org.hibernate.metamodel.mapping.JdbcMapping)11 JavaType (org.hibernate.type.descriptor.java.JavaType)11 BiConsumer (java.util.function.BiConsumer)10 BiFunction (java.util.function.BiFunction)10 EntityMappingType (org.hibernate.metamodel.mapping.EntityMappingType)10 ResultSetMappingSqlSelection (org.hibernate.query.results.ResultSetMappingSqlSelection)10 DomainResult (org.hibernate.sql.results.graph.DomainResult)10 JdbcValuesMetadata (org.hibernate.sql.results.jdbc.spi.JdbcValuesMetadata)10 SharedSessionContractImplementor (org.hibernate.engine.spi.SharedSessionContractImplementor)9 IndexedConsumer (org.hibernate.mapping.IndexedConsumer)9