Search in sources :

Example 31 with TableGroup

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

the class AbstractCompositeIdentifierMapping 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 TableGroup tableGroup = createRootTableGroupJoin(navigablePath, lhs, explicitSourceAlias, requestedJoinType, fetched, null, aliasBaseGenerator, sqlExpressionResolver, fromClauseAccess, creationContext);
    return new TableGroupJoin(navigablePath, joinType, tableGroup, null);
}
Also used : TableGroupJoin(org.hibernate.sql.ast.tree.from.TableGroupJoin) StandardVirtualTableGroup(org.hibernate.sql.ast.tree.from.StandardVirtualTableGroup) TableGroup(org.hibernate.sql.ast.tree.from.TableGroup) SqlAstJoinType(org.hibernate.sql.ast.SqlAstJoinType)

Example 32 with TableGroup

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

the class ImplicitModelPartResultBuilderEmbeddable method buildResult.

@Override
public EmbeddableResult buildResult(JdbcValuesMetadata jdbcResultsMetadata, int resultPosition, BiFunction<String, String, DynamicFetchBuilderLegacy> legacyFetchResolver, DomainResultCreationState domainResultCreationState) {
    final DomainResultCreationStateImpl creationStateImpl = ResultsHelper.impl(domainResultCreationState);
    creationStateImpl.disallowPositionalSelections();
    final TableGroup tableGroup = creationStateImpl.getFromClauseAccess().resolveTableGroup(navigablePath, np -> {
        if (navigablePath.getParent() == null) {
            throw new IllegalStateException("Could not determine LHS for implicit embeddable result builder - " + navigablePath);
        }
        final TableGroup parentTableGroup = creationStateImpl.getFromClauseAccess().getTableGroup(navigablePath.getParent());
        final TableGroupJoin tableGroupJoin = modelPart.createTableGroupJoin(navigablePath, parentTableGroup, null, SqlAstJoinType.INNER, true, false, creationStateImpl);
        parentTableGroup.addTableGroupJoin(tableGroupJoin);
        return tableGroupJoin.getJoinedGroup();
    });
    return (EmbeddableResult) modelPart.createDomainResult(navigablePath, tableGroup, null, domainResultCreationState);
}
Also used : TableGroupJoin(org.hibernate.sql.ast.tree.from.TableGroupJoin) DomainResultCreationStateImpl(org.hibernate.query.results.DomainResultCreationStateImpl) TableGroup(org.hibernate.sql.ast.tree.from.TableGroup) EmbeddableResult(org.hibernate.sql.results.graph.embeddable.EmbeddableResult)

Example 33 with TableGroup

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

the class ImplicitFetchBuilderEmbeddable method buildFetch.

@Override
public Fetch buildFetch(FetchParent parent, NavigablePath fetchPath, JdbcValuesMetadata jdbcResultsMetadata, BiFunction<String, String, DynamicFetchBuilderLegacy> legacyFetchResolver, DomainResultCreationState creationState) {
    final DomainResultCreationStateImpl creationStateImpl = impl(creationState);
    final TableGroup tableGroup = creationStateImpl.getFromClauseAccess().resolveTableGroup(fetchPath, navigablePath -> {
        final TableGroup parentTableGroup = creationStateImpl.getFromClauseAccess().getTableGroup(parent.getNavigablePath());
        final TableGroupJoin tableGroupJoin = fetchable.createTableGroupJoin(fetchPath, parentTableGroup, null, SqlAstJoinType.INNER, true, false, creationStateImpl);
        parentTableGroup.addTableGroupJoin(tableGroupJoin);
        return tableGroupJoin.getJoinedGroup();
    });
    final Fetch fetch = parent.generateFetchableFetch(fetchable, fetchPath, FetchTiming.IMMEDIATE, true, null, creationState);
    return fetch;
}
Also used : TableGroupJoin(org.hibernate.sql.ast.tree.from.TableGroupJoin) Fetch(org.hibernate.sql.results.graph.Fetch) DomainResultCreationStateImpl(org.hibernate.query.results.DomainResultCreationStateImpl) TableGroup(org.hibernate.sql.ast.tree.from.TableGroup)

Example 34 with TableGroup

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

the class DynamicResultBuilderEntityCalculated method buildResult.

@Override
public EntityResult buildResult(JdbcValuesMetadata jdbcResultsMetadata, int resultPosition, BiFunction<String, String, DynamicFetchBuilderLegacy> legacyFetchResolver, DomainResultCreationState domainResultCreationState) {
    final DomainResultCreationStateImpl creationStateImpl = ResultsHelper.impl(domainResultCreationState);
    final TableGroup tableGroup = entityMapping.createRootTableGroup(true, navigablePath, tableAlias, null, new SqlAliasBaseConstant(tableAlias), creationStateImpl, creationStateImpl.getFromClauseAccess(), creationStateImpl.getCreationContext());
    creationStateImpl.getFromClauseAccess().registerTableGroup(navigablePath, tableGroup);
    if (explicitLockMode != null) {
        domainResultCreationState.getSqlAstCreationState().registerLockMode(tableAlias, explicitLockMode);
    }
    return (EntityResult) entityMapping.createDomainResult(navigablePath, tableGroup, tableAlias, domainResultCreationState);
}
Also used : DomainResultCreationStateImpl(org.hibernate.query.results.DomainResultCreationStateImpl) TableGroup(org.hibernate.sql.ast.tree.from.TableGroup) SqlAliasBaseConstant(org.hibernate.sql.ast.spi.SqlAliasBaseConstant) EntityResult(org.hibernate.sql.results.graph.entity.EntityResult)

Example 35 with TableGroup

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

the class DynamicFetchBuilderStandard method buildFetch.

@Override
public Fetch buildFetch(FetchParent parent, NavigablePath fetchPath, JdbcValuesMetadata jdbcResultsMetadata, BiFunction<String, String, DynamicFetchBuilderLegacy> legacyFetchResolver, DomainResultCreationState domainResultCreationState) {
    final DomainResultCreationStateImpl creationStateImpl = ResultsHelper.impl(domainResultCreationState);
    final TableGroup ownerTableGroup = creationStateImpl.getFromClauseAccess().getTableGroup(parent.getNavigablePath());
    final Fetchable attributeMapping = (Fetchable) parent.getReferencedMappingContainer().findSubPart(fetchableName, null);
    final SqlExpressionResolver sqlExpressionResolver = domainResultCreationState.getSqlAstCreationState().getSqlExpressionResolver();
    final SelectableConsumer selectableConsumer = (selectionIndex, selectableMapping) -> {
        final TableReference tableReference = ownerTableGroup.resolveTableReference(fetchPath, selectableMapping.getContainingTableExpression());
        final String columnAlias = columnNames.get(selectionIndex);
        sqlExpressionResolver.resolveSqlSelection(sqlExpressionResolver.resolveSqlExpression(createColumnReferenceKey(tableReference, selectableMapping.getSelectionExpression()), state -> {
            final int resultSetPosition = jdbcResultsMetadata.resolveColumnPosition(columnAlias);
            final int valuesArrayPosition = resultSetPosition - 1;
            return new ResultSetMappingSqlSelection(valuesArrayPosition, selectableMapping.getJdbcMapping());
        }), selectableMapping.getJdbcMapping().getMappedJavaType(), domainResultCreationState.getSqlAstCreationState().getCreationContext().getSessionFactory().getTypeConfiguration());
    };
    if (attributeMapping instanceof BasicValuedMapping) {
        attributeMapping.forEachSelectable(selectableConsumer);
        return parent.generateFetchableFetch(attributeMapping, fetchPath, FetchTiming.IMMEDIATE, true, null, creationStateImpl);
    } else if (attributeMapping instanceof EmbeddedAttributeMapping) {
        attributeMapping.forEachSelectable(selectableConsumer);
        return parent.generateFetchableFetch(attributeMapping, fetchPath, FetchTiming.IMMEDIATE, false, null, creationStateImpl);
    } else if (attributeMapping instanceof ToOneAttributeMapping) {
        final ToOneAttributeMapping toOneAttributeMapping = (ToOneAttributeMapping) attributeMapping;
        toOneAttributeMapping.getForeignKeyDescriptor().getPart(toOneAttributeMapping.getSideNature()).forEachSelectable(selectableConsumer);
        return parent.generateFetchableFetch(attributeMapping, fetchPath, FetchTiming.DELAYED, false, null, creationStateImpl);
    } else {
        assert attributeMapping instanceof PluralAttributeMapping;
        final PluralAttributeMapping pluralAttributeMapping = (PluralAttributeMapping) attributeMapping;
        pluralAttributeMapping.getKeyDescriptor().visitTargetSelectables(selectableConsumer);
        return parent.generateFetchableFetch(attributeMapping, fetchPath, FetchTiming.DELAYED, false, null, creationStateImpl);
    }
}
Also used : DomainResultCreationState(org.hibernate.sql.results.graph.DomainResultCreationState) Fetchable(org.hibernate.sql.results.graph.Fetchable) FetchTiming(org.hibernate.engine.FetchTiming) ResultSetMappingSqlSelection(org.hibernate.query.results.ResultSetMappingSqlSelection) BiFunction(java.util.function.BiFunction) NavigablePath(org.hibernate.query.spi.NavigablePath) DomainResultCreationStateImpl(org.hibernate.query.results.DomainResultCreationStateImpl) BasicValuedMapping(org.hibernate.metamodel.mapping.BasicValuedMapping) Fetch(org.hibernate.sql.results.graph.Fetch) ArrayList(java.util.ArrayList) SqlExpressionResolver(org.hibernate.sql.ast.spi.SqlExpressionResolver) TableReference(org.hibernate.sql.ast.tree.from.TableReference) JdbcValuesMetadata(org.hibernate.sql.results.jdbc.spi.JdbcValuesMetadata) PluralAttributeMapping(org.hibernate.metamodel.mapping.PluralAttributeMapping) ResultsHelper(org.hibernate.query.results.ResultsHelper) List(java.util.List) NativeQuery(org.hibernate.query.NativeQuery) ToOneAttributeMapping(org.hibernate.metamodel.mapping.internal.ToOneAttributeMapping) SelectableConsumer(org.hibernate.metamodel.mapping.SelectableConsumer) TableGroup(org.hibernate.sql.ast.tree.from.TableGroup) EmbeddedAttributeMapping(org.hibernate.metamodel.mapping.internal.EmbeddedAttributeMapping) SqlExpressionResolver.createColumnReferenceKey(org.hibernate.sql.ast.spi.SqlExpressionResolver.createColumnReferenceKey) FetchParent(org.hibernate.sql.results.graph.FetchParent) Fetchable(org.hibernate.sql.results.graph.Fetchable) DomainResultCreationStateImpl(org.hibernate.query.results.DomainResultCreationStateImpl) TableGroup(org.hibernate.sql.ast.tree.from.TableGroup) SelectableConsumer(org.hibernate.metamodel.mapping.SelectableConsumer) PluralAttributeMapping(org.hibernate.metamodel.mapping.PluralAttributeMapping) ResultSetMappingSqlSelection(org.hibernate.query.results.ResultSetMappingSqlSelection) BasicValuedMapping(org.hibernate.metamodel.mapping.BasicValuedMapping) TableReference(org.hibernate.sql.ast.tree.from.TableReference) EmbeddedAttributeMapping(org.hibernate.metamodel.mapping.internal.EmbeddedAttributeMapping) ToOneAttributeMapping(org.hibernate.metamodel.mapping.internal.ToOneAttributeMapping) SqlExpressionResolver(org.hibernate.sql.ast.spi.SqlExpressionResolver)

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