Search in sources :

Example 1 with DomainResultCreationStateImpl

use of org.hibernate.query.results.DomainResultCreationStateImpl 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 2 with DomainResultCreationStateImpl

use of org.hibernate.query.results.DomainResultCreationStateImpl 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 3 with DomainResultCreationStateImpl

use of org.hibernate.query.results.DomainResultCreationStateImpl 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 4 with DomainResultCreationStateImpl

use of org.hibernate.query.results.DomainResultCreationStateImpl 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)

Example 5 with DomainResultCreationStateImpl

use of org.hibernate.query.results.DomainResultCreationStateImpl in project hibernate-orm by hibernate.

the class ImplicitModelPartResultBuilderEntity method buildResult.

@Override
public EntityResult 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) {
            return creationStateImpl.getFromClauseAccess().getTableGroup(navigablePath.getParent());
        }
        return modelPart.getEntityMappingType().createRootTableGroup(// since this is only used for result set mappings, the canUseInnerJoins value is irrelevant.
        true, navigablePath, null, null, creationStateImpl, creationStateImpl.getCreationContext());
    });
    return (EntityResult) modelPart.createDomainResult(navigablePath, tableGroup, null, domainResultCreationState);
}
Also used : DomainResultCreationStateImpl(org.hibernate.query.results.DomainResultCreationStateImpl) TableGroup(org.hibernate.sql.ast.tree.from.TableGroup) EntityResult(org.hibernate.sql.results.graph.entity.EntityResult)

Aggregations

DomainResultCreationStateImpl (org.hibernate.query.results.DomainResultCreationStateImpl)20 TableGroup (org.hibernate.sql.ast.tree.from.TableGroup)15 ResultSetMappingSqlSelection (org.hibernate.query.results.ResultSetMappingSqlSelection)9 BiFunction (java.util.function.BiFunction)7 NavigablePath (org.hibernate.query.spi.NavigablePath)7 DomainResultCreationState (org.hibernate.sql.results.graph.DomainResultCreationState)7 JdbcValuesMetadata (org.hibernate.sql.results.jdbc.spi.JdbcValuesMetadata)7 ResultsHelper.impl (org.hibernate.query.results.ResultsHelper.impl)6 DynamicFetchBuilderLegacy (org.hibernate.query.results.dynamic.DynamicFetchBuilderLegacy)6 SqlAliasBaseConstant (org.hibernate.sql.ast.spi.SqlAliasBaseConstant)6 TableReference (org.hibernate.sql.ast.tree.from.TableReference)6 SqlExpressionResolver (org.hibernate.sql.ast.spi.SqlExpressionResolver)5 Fetch (org.hibernate.sql.results.graph.Fetch)5 SessionFactoryImplementor (org.hibernate.engine.spi.SessionFactoryImplementor)4 BasicValuedMapping (org.hibernate.metamodel.mapping.BasicValuedMapping)4 ResultBuilder (org.hibernate.query.results.ResultBuilder)4 ResultsHelper (org.hibernate.query.results.ResultsHelper)4 SqlSelection (org.hibernate.sql.ast.spi.SqlSelection)4 BasicResult (org.hibernate.sql.results.graph.basic.BasicResult)4 List (java.util.List)3