Search in sources :

Example 6 with DynamicFetchBuilderLegacy

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

the class CompleteResultBuilderBasicValuedStandard method buildResult.

@Override
public BasicResult<?> buildResult(JdbcValuesMetadata jdbcResultsMetadata, int resultPosition, BiFunction<String, String, DynamicFetchBuilderLegacy> legacyFetchResolver, DomainResultCreationState domainResultCreationState) {
    final DomainResultCreationStateImpl creationStateImpl = impl(domainResultCreationState);
    final SessionFactoryImplementor sessionFactory = creationStateImpl.getSessionFactory();
    final String columnName;
    if (explicitColumnName != null) {
        columnName = explicitColumnName;
    } else {
        columnName = jdbcResultsMetadata.resolveColumnName(resultPosition + 1);
    }
    // final int jdbcPosition;
    // if ( explicitColumnName != null ) {
    // jdbcPosition = jdbcResultsMetadata.resolveColumnPosition( explicitColumnName );
    // }
    // else {
    // jdbcPosition = resultPosition + 1;
    // }
    // 
    // final BasicValuedMapping basicType;
    // if ( explicitType != null ) {
    // basicType = explicitType;
    // }
    // else {
    // basicType = jdbcResultsMetadata.resolveType( jdbcPosition, explicitJavaType );
    // }
    // 
    // final SqlSelection sqlSelection = creationStateImpl.resolveSqlSelection(
    // creationStateImpl.resolveSqlExpression(
    // columnName,
    // processingState -> {
    // final int valuesArrayPosition = ResultsHelper.jdbcPositionToValuesArrayPosition( jdbcPosition );
    // return new SqlSelectionImpl( valuesArrayPosition, basicType );
    // }
    // ),
    // basicType.getExpressibleJavaType(),
    // sessionFactory.getTypeConfiguration()
    // );
    final SqlSelection sqlSelection = creationStateImpl.resolveSqlSelection(creationStateImpl.resolveSqlExpression(columnName, processingState -> {
        final int jdbcPosition;
        if (explicitColumnName != null) {
            jdbcPosition = jdbcResultsMetadata.resolveColumnPosition(explicitColumnName);
        } else {
            jdbcPosition = resultPosition + 1;
        }
        final BasicValuedMapping basicType;
        if (explicitType != null) {
            basicType = explicitType;
        } else {
            basicType = jdbcResultsMetadata.resolveType(jdbcPosition, explicitJavaType, sessionFactory);
        }
        final int valuesArrayPosition = ResultsHelper.jdbcPositionToValuesArrayPosition(jdbcPosition);
        return new ResultSetMappingSqlSelection(valuesArrayPosition, basicType);
    }), explicitJavaType, sessionFactory.getTypeConfiguration());
    return new BasicResult<>(sqlSelection.getValuesArrayPosition(), columnName, sqlSelection.getExpressionType().getJdbcMappings().get(0).getMappedJavaType());
}
Also used : DomainResultCreationState(org.hibernate.sql.results.graph.DomainResultCreationState) DynamicFetchBuilderLegacy(org.hibernate.query.results.dynamic.DynamicFetchBuilderLegacy) ResultSetMappingSqlSelection(org.hibernate.query.results.ResultSetMappingSqlSelection) BiFunction(java.util.function.BiFunction) DomainResultCreationStateImpl(org.hibernate.query.results.DomainResultCreationStateImpl) JavaType(org.hibernate.type.descriptor.java.JavaType) BasicValuedMapping(org.hibernate.metamodel.mapping.BasicValuedMapping) BasicResult(org.hibernate.sql.results.graph.basic.BasicResult) ResultsHelper.impl(org.hibernate.query.results.ResultsHelper.impl) Objects(java.util.Objects) JdbcValuesMetadata(org.hibernate.sql.results.jdbc.spi.JdbcValuesMetadata) ResultsHelper(org.hibernate.query.results.ResultsHelper) ResultBuilder(org.hibernate.query.results.ResultBuilder) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) SqlSelection(org.hibernate.sql.ast.spi.SqlSelection) BasicValuedMapping(org.hibernate.metamodel.mapping.BasicValuedMapping) DomainResultCreationStateImpl(org.hibernate.query.results.DomainResultCreationStateImpl) BasicResult(org.hibernate.sql.results.graph.basic.BasicResult) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) ResultSetMappingSqlSelection(org.hibernate.query.results.ResultSetMappingSqlSelection) ResultSetMappingSqlSelection(org.hibernate.query.results.ResultSetMappingSqlSelection) SqlSelection(org.hibernate.sql.ast.spi.SqlSelection)

Example 7 with DynamicFetchBuilderLegacy

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

the class DomainResultCreationStateImpl method visitFetches.

@Override
public List<Fetch> visitFetches(FetchParent fetchParent) {
    final FetchableContainer fetchableContainer = fetchParent.getReferencedMappingContainer();
    final List<Fetch> fetches = CollectionHelper.arrayList(fetchableContainer.getNumberOfFetchables());
    final Consumer<Fetchable> fetchableConsumer = fetchable -> {
        final String fetchableName = fetchable.getFetchableName();
        Map.Entry<String, NavigablePath> currentEntry;
        if (relativePathStack.isEmpty()) {
            currentEntry = new AbstractMap.SimpleEntry<>(getRelativePath("", fetchable, fetchableContainer), new NavigablePath(fetchableName));
        } else {
            final Map.Entry<String, NavigablePath> oldEntry = relativePathStack.getCurrent();
            final String key = oldEntry.getKey();
            currentEntry = new AbstractMap.SimpleEntry<>(getRelativePath(key, fetchable, fetchableContainer), oldEntry.getValue().append(fetchableName));
        }
        // todo (6.0): figure out if we can somehow create the navigable paths in a better way
        final String fullPath = currentEntry.getKey();
        FetchBuilder explicitFetchBuilder = fetchBuilderResolverStack.getCurrent().apply(fullPath);
        DynamicFetchBuilderLegacy fetchBuilderLegacy;
        if (explicitFetchBuilder == null) {
            fetchBuilderLegacy = legacyFetchResolver.resolve(fromClauseAccess.findTableGroup(fetchParent.getNavigablePath()).getPrimaryTableReference().getIdentificationVariable(), fetchableName);
        } else {
            fetchBuilderLegacy = null;
        }
        if (fetchable instanceof Association && fetchable.getMappedFetchOptions().getTiming() == FetchTiming.DELAYED) {
            final Association association = (Association) fetchable;
            final ForeignKeyDescriptor foreignKeyDescriptor = association.getForeignKeyDescriptor();
            final String partName = attributeName(foreignKeyDescriptor.getSide(association.getSideNature().inverse()).getModelPart());
            // If there are no fetch builders for this association, we only want to fetch the FK
            if (explicitFetchBuilder == null && fetchBuilderLegacy == null && partName != null) {
                currentEntry = new AbstractMap.SimpleEntry<>(currentEntry.getKey() + "." + partName, currentEntry.getValue().append(partName));
                explicitFetchBuilder = fetchBuilderResolverStack.getCurrent().apply(currentEntry.getKey());
                if (explicitFetchBuilder == null) {
                    fetchBuilderLegacy = legacyFetchResolver.resolve(fromClauseAccess.findTableGroup(fetchParent.getNavigablePath()).getPrimaryTableReference().getIdentificationVariable(), fetchableName);
                }
            }
        }
        relativePathStack.push(currentEntry);
        try {
            final NavigablePath fetchPath = fetchParent.resolveNavigablePath(fetchable);
            final FetchBuilder fetchBuilder;
            if (explicitFetchBuilder != null) {
                fetchBuilder = explicitFetchBuilder;
            } else {
                if (fetchBuilderLegacy == null) {
                    fetchBuilder = Builders.implicitFetchBuilder(fetchPath, fetchable, this);
                } else {
                    fetchBuilder = fetchBuilderLegacy;
                }
            }
            final Fetch fetch = fetchBuilder.buildFetch(fetchParent, fetchPath, jdbcResultsMetadata, (s, s2) -> {
                throw new UnsupportedOperationException();
            }, this);
            fetches.add(fetch);
        } finally {
            relativePathStack.pop();
        }
    };
    boolean previous = this.processingKeyFetches;
    this.processingKeyFetches = true;
    if (fetchableContainer instanceof EntityValuedModelPart) {
        final EntityValuedModelPart entityValuedFetchable = (EntityValuedModelPart) fetchableContainer;
        final EntityIdentifierMapping identifierMapping = entityValuedFetchable.getEntityMappingType().getIdentifierMapping();
        final boolean idClass = identifierMapping instanceof NonAggregatedIdentifierMapping;
        final String identifierAttributeName = attributeName(identifierMapping);
        if (idClass) {
            final Map.Entry<String, NavigablePath> oldEntry = relativePathStack.getCurrent();
            relativePathStack.push(new AbstractMap.SimpleEntry<>(oldEntry == null ? "" : oldEntry.getKey(), new EntityIdentifierNavigablePath(oldEntry == null ? fetchParent.getNavigablePath() : oldEntry.getValue(), identifierAttributeName)));
        } else if (identifierMapping instanceof CompositeIdentifierMapping) {
            final Map.Entry<String, NavigablePath> oldEntry = relativePathStack.getCurrent();
            relativePathStack.push(new AbstractMap.SimpleEntry<>(oldEntry == null ? identifierAttributeName : oldEntry.getKey() + "." + identifierAttributeName, new EntityIdentifierNavigablePath(oldEntry == null ? fetchParent.getNavigablePath() : oldEntry.getValue(), identifierAttributeName)));
        }
        try {
            if (identifierMapping instanceof FetchableContainer) {
                // essentially means the entity has a composite id - ask the embeddable to visit its fetchables
                ((FetchableContainer) identifierMapping).visitFetchables(fetchableConsumer, null);
            } else {
                fetchableConsumer.accept((Fetchable) identifierMapping);
            }
        } finally {
            this.processingKeyFetches = previous;
            if (idClass) {
                this.relativePathStack.pop();
            }
        }
    }
    fetchableContainer.visitKeyFetchables(fetchableConsumer, null);
    fetchableContainer.visitFetchables(fetchableConsumer, null);
    return fetches;
}
Also used : CollectionHelper(org.hibernate.internal.util.collections.CollectionHelper) DomainResultCreationState(org.hibernate.sql.results.graph.DomainResultCreationState) SqlAliasBaseGenerator(org.hibernate.sql.ast.spi.SqlAliasBaseGenerator) ResultsLogger(org.hibernate.sql.results.ResultsLogger) SingleAttributeIdentifierMapping(org.hibernate.metamodel.mapping.internal.SingleAttributeIdentifierMapping) CompositeIdentifierMapping(org.hibernate.metamodel.mapping.CompositeIdentifierMapping) ColumnReference(org.hibernate.sql.ast.tree.expression.ColumnReference) JavaType(org.hibernate.type.descriptor.java.JavaType) ResultsHelper.attributeName(org.hibernate.query.results.ResultsHelper.attributeName) HashMap(java.util.HashMap) EntityValuedModelPart(org.hibernate.metamodel.mapping.EntityValuedModelPart) Function(java.util.function.Function) BasicValuedCollectionPart(org.hibernate.metamodel.mapping.internal.BasicValuedCollectionPart) Internal(org.hibernate.Internal) SqlAstCreationContext(org.hibernate.sql.ast.spi.SqlAstCreationContext) ModelPart(org.hibernate.metamodel.mapping.ModelPart) FetchableContainer(org.hibernate.sql.results.graph.FetchableContainer) ForeignKeyDescriptor(org.hibernate.metamodel.mapping.ForeignKeyDescriptor) Map(java.util.Map) EntityIdentifierNavigablePath(org.hibernate.query.sqm.spi.EntityIdentifierNavigablePath) SqlAliasBaseManager(org.hibernate.sql.ast.spi.SqlAliasBaseManager) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) SqlSelection(org.hibernate.sql.ast.spi.SqlSelection) SqlAstCreationState(org.hibernate.sql.ast.spi.SqlAstCreationState) Fetchable(org.hibernate.sql.results.graph.Fetchable) FetchTiming(org.hibernate.engine.FetchTiming) LockMode(org.hibernate.LockMode) AssociationKey(org.hibernate.metamodel.mapping.AssociationKey) DynamicFetchBuilderLegacy(org.hibernate.query.results.dynamic.DynamicFetchBuilderLegacy) TypeConfiguration(org.hibernate.type.spi.TypeConfiguration) LegacyFetchResolver(org.hibernate.query.results.dynamic.LegacyFetchResolver) NavigablePath(org.hibernate.query.spi.NavigablePath) Expression(org.hibernate.sql.ast.tree.expression.Expression) Fetch(org.hibernate.sql.results.graph.Fetch) SqlAstProcessingState(org.hibernate.sql.ast.spi.SqlAstProcessingState) SqlExpressionResolver(org.hibernate.sql.ast.spi.SqlExpressionResolver) Consumer(java.util.function.Consumer) StandardStack(org.hibernate.internal.util.collections.StandardStack) Association(org.hibernate.metamodel.mapping.Association) EntityIdentifierMapping(org.hibernate.metamodel.mapping.EntityIdentifierMapping) JdbcValuesMetadata(org.hibernate.sql.results.jdbc.spi.JdbcValuesMetadata) AbstractMap(java.util.AbstractMap) List(java.util.List) NonAggregatedIdentifierMapping(org.hibernate.metamodel.mapping.NonAggregatedIdentifierMapping) Stack(org.hibernate.internal.util.collections.Stack) AttributeMapping(org.hibernate.metamodel.mapping.AttributeMapping) TableGroup(org.hibernate.sql.ast.tree.from.TableGroup) FetchParent(org.hibernate.sql.results.graph.FetchParent) Fetchable(org.hibernate.sql.results.graph.Fetchable) EntityIdentifierNavigablePath(org.hibernate.query.sqm.spi.EntityIdentifierNavigablePath) NavigablePath(org.hibernate.query.spi.NavigablePath) CompositeIdentifierMapping(org.hibernate.metamodel.mapping.CompositeIdentifierMapping) Fetch(org.hibernate.sql.results.graph.Fetch) AbstractMap(java.util.AbstractMap) Association(org.hibernate.metamodel.mapping.Association) EntityValuedModelPart(org.hibernate.metamodel.mapping.EntityValuedModelPart) ForeignKeyDescriptor(org.hibernate.metamodel.mapping.ForeignKeyDescriptor) DynamicFetchBuilderLegacy(org.hibernate.query.results.dynamic.DynamicFetchBuilderLegacy) FetchableContainer(org.hibernate.sql.results.graph.FetchableContainer) NonAggregatedIdentifierMapping(org.hibernate.metamodel.mapping.NonAggregatedIdentifierMapping) EntityIdentifierNavigablePath(org.hibernate.query.sqm.spi.EntityIdentifierNavigablePath) EntityIdentifierMapping(org.hibernate.metamodel.mapping.EntityIdentifierMapping) HashMap(java.util.HashMap) Map(java.util.Map) AbstractMap(java.util.AbstractMap)

Example 8 with DynamicFetchBuilderLegacy

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

the class CompleteFetchBuilderEntityValuedModelPart method buildFetch.

@Override
public Fetch buildFetch(FetchParent parent, NavigablePath fetchPath, JdbcValuesMetadata jdbcResultsMetadata, BiFunction<String, String, DynamicFetchBuilderLegacy> legacyFetchResolver, DomainResultCreationState domainResultCreationState) {
    assert fetchPath.equals(navigablePath);
    final DomainResultCreationStateImpl creationStateImpl = impl(domainResultCreationState);
    final TableGroup tableGroup = creationStateImpl.getFromClauseAccess().getTableGroup(navigablePath.getParent());
    modelPart.forEachSelectable((selectionIndex, selectableMapping) -> {
        final TableReference tableReference = tableGroup.resolveTableReference(navigablePath, selectableMapping.getContainingTableExpression());
        final String mappedColumn = selectableMapping.getSelectionExpression();
        final String columnAlias = columnAliases.get(selectionIndex);
        creationStateImpl.resolveSqlSelection(creationStateImpl.resolveSqlExpression(SqlExpressionResolver.createColumnReferenceKey(tableReference, mappedColumn), processingState -> {
            final int jdbcPosition = jdbcResultsMetadata.resolveColumnPosition(columnAlias);
            final int valuesArrayPosition = jdbcPositionToValuesArrayPosition(jdbcPosition);
            return new ResultSetMappingSqlSelection(valuesArrayPosition, selectableMapping.getJdbcMapping());
        }), modelPart.getJavaType(), creationStateImpl.getSessionFactory().getTypeConfiguration());
    });
    return parent.generateFetchableFetch(modelPart, fetchPath, FetchTiming.DELAYED, true, null, domainResultCreationState);
}
Also used : DomainResultCreationState(org.hibernate.sql.results.graph.DomainResultCreationState) FetchTiming(org.hibernate.engine.FetchTiming) DynamicFetchBuilderLegacy(org.hibernate.query.results.dynamic.DynamicFetchBuilderLegacy) ResultSetMappingSqlSelection(org.hibernate.query.results.ResultSetMappingSqlSelection) BiFunction(java.util.function.BiFunction) NavigablePath(org.hibernate.query.spi.NavigablePath) DomainResultCreationStateImpl(org.hibernate.query.results.DomainResultCreationStateImpl) Fetch(org.hibernate.sql.results.graph.Fetch) SqlExpressionResolver(org.hibernate.sql.ast.spi.SqlExpressionResolver) TableReference(org.hibernate.sql.ast.tree.from.TableReference) ResultsHelper.impl(org.hibernate.query.results.ResultsHelper.impl) JdbcValuesMetadata(org.hibernate.sql.results.jdbc.spi.JdbcValuesMetadata) List(java.util.List) ResultsHelper.jdbcPositionToValuesArrayPosition(org.hibernate.query.results.ResultsHelper.jdbcPositionToValuesArrayPosition) FetchBuilder(org.hibernate.query.results.FetchBuilder) TableGroup(org.hibernate.sql.ast.tree.from.TableGroup) FetchParent(org.hibernate.sql.results.graph.FetchParent) EntityValuedFetchable(org.hibernate.sql.results.graph.entity.EntityValuedFetchable) TableReference(org.hibernate.sql.ast.tree.from.TableReference) DomainResultCreationStateImpl(org.hibernate.query.results.DomainResultCreationStateImpl) TableGroup(org.hibernate.sql.ast.tree.from.TableGroup) ResultSetMappingSqlSelection(org.hibernate.query.results.ResultSetMappingSqlSelection)

Example 9 with DynamicFetchBuilderLegacy

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

the class CompleteResultBuilderBasicValuedConverted method buildResult.

@Override
public BasicResult<?> buildResult(JdbcValuesMetadata jdbcResultsMetadata, int resultPosition, BiFunction<String, String, DynamicFetchBuilderLegacy> legacyFetchResolver, DomainResultCreationState domainResultCreationState) {
    final DomainResultCreationStateImpl creationStateImpl = impl(domainResultCreationState);
    final SessionFactoryImplementor sessionFactory = creationStateImpl.getSessionFactory();
    final String columnName;
    if (explicitColumnName != null) {
        columnName = explicitColumnName;
    } else {
        columnName = jdbcResultsMetadata.resolveColumnName(resultPosition + 1);
    }
    // final int jdbcPosition;
    // if ( explicitColumnName != null ) {
    // jdbcPosition = jdbcResultsMetadata.resolveColumnPosition( explicitColumnName );
    // }
    // else {
    // jdbcPosition = resultPosition + 1;
    // }
    // 
    // final BasicValuedMapping basicType;
    // if ( explicitType != null ) {
    // basicType = explicitType;
    // }
    // else {
    // basicType = jdbcResultsMetadata.resolveType( jdbcPosition, explicitJavaType );
    // }
    // 
    // final SqlSelection sqlSelection = creationStateImpl.resolveSqlSelection(
    // creationStateImpl.resolveSqlExpression(
    // columnName,
    // processingState -> {
    // final int valuesArrayPosition = ResultsHelper.jdbcPositionToValuesArrayPosition( jdbcPosition );
    // return new SqlSelectionImpl( valuesArrayPosition, basicType );
    // }
    // ),
    // basicType.getExpressibleJavaType(),
    // sessionFactory.getTypeConfiguration()
    // );
    final SqlSelection sqlSelection = creationStateImpl.resolveSqlSelection(creationStateImpl.resolveSqlExpression(columnName, processingState -> {
        final int jdbcPosition;
        if (explicitColumnName != null) {
            jdbcPosition = jdbcResultsMetadata.resolveColumnPosition(explicitColumnName);
        } else {
            jdbcPosition = resultPosition + 1;
        }
        final int valuesArrayPosition = ResultsHelper.jdbcPositionToValuesArrayPosition(jdbcPosition);
        return new ResultSetMappingSqlSelection(valuesArrayPosition, underlyingMapping);
    }), valueConverter.getDomainJavaType(), sessionFactory.getTypeConfiguration());
    return new BasicResult<>(sqlSelection.getValuesArrayPosition(), columnName, valueConverter.getDomainJavaType(), valueConverter);
}
Also used : DomainResultCreationState(org.hibernate.sql.results.graph.DomainResultCreationState) BasicJavaType(org.hibernate.type.descriptor.java.BasicJavaType) JpaAttributeConverterImpl(org.hibernate.metamodel.model.convert.internal.JpaAttributeConverterImpl) DynamicFetchBuilderLegacy(org.hibernate.query.results.dynamic.DynamicFetchBuilderLegacy) ResultSetMappingSqlSelection(org.hibernate.query.results.ResultSetMappingSqlSelection) BiFunction(java.util.function.BiFunction) DomainResultCreationStateImpl(org.hibernate.query.results.DomainResultCreationStateImpl) JavaType(org.hibernate.type.descriptor.java.JavaType) BasicValuedMapping(org.hibernate.metamodel.mapping.BasicValuedMapping) BasicResult(org.hibernate.sql.results.graph.basic.BasicResult) ResultsHelper.impl(org.hibernate.query.results.ResultsHelper.impl) Objects(java.util.Objects) JdbcValuesMetadata(org.hibernate.sql.results.jdbc.spi.JdbcValuesMetadata) ResultsHelper(org.hibernate.query.results.ResultsHelper) ManagedBean(org.hibernate.resource.beans.spi.ManagedBean) ResultBuilder(org.hibernate.query.results.ResultBuilder) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) AttributeConverter(jakarta.persistence.AttributeConverter) SqlSelection(org.hibernate.sql.ast.spi.SqlSelection) DomainResultCreationStateImpl(org.hibernate.query.results.DomainResultCreationStateImpl) BasicResult(org.hibernate.sql.results.graph.basic.BasicResult) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) ResultSetMappingSqlSelection(org.hibernate.query.results.ResultSetMappingSqlSelection) ResultSetMappingSqlSelection(org.hibernate.query.results.ResultSetMappingSqlSelection) SqlSelection(org.hibernate.sql.ast.spi.SqlSelection)

Example 10 with DynamicFetchBuilderLegacy

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

the class ResultSetMappingProcessor method applyFetchBuilder.

private void applyFetchBuilder(ResultSetMappingImpl resultSetMapping, DynamicFetchBuilderLegacy fetchBuilder, Set<String> visited) {
    if (!visited.add(fetchBuilder.getTableAlias())) {
        return;
    }
    final String suffix = alias2Suffix.get(fetchBuilder.getTableAlias());
    if (suffix == null) {
        resultSetMapping.addLegacyFetchBuilder(fetchBuilder);
    } else {
        if (!visited.contains(fetchBuilder.getOwnerAlias())) {
            applyFetchBuilder(resultSetMapping, // At this point, only legacy fetch builders weren't visited
            (DynamicFetchBuilderLegacy) alias2Return.get(fetchBuilder.getOwnerAlias()), visited);
        }
        // At this point, the owner builder must be a DynamicResultBuilderEntityStandard to which we can add this builder to
        final DynamicResultBuilderEntityStandard ownerBuilder = (DynamicResultBuilderEntityStandard) alias2Return.get(fetchBuilder.getOwnerAlias());
        final DynamicResultBuilderEntityStandard resultBuilderEntity = createSuffixedResultBuilder(alias2Persister.get(fetchBuilder.getTableAlias()).findContainingEntityMapping(), fetchBuilder.getTableAlias(), suffix, null, determineNavigablePath(fetchBuilder));
        final SQLLoadable loadable = (SQLLoadable) alias2Persister.get(fetchBuilder.getOwnerAlias());
        final List<String> columnNames;
        final String[] columnAliases = loadable.getSubclassPropertyColumnAliases(fetchBuilder.getFetchableName(), alias2Suffix.get(fetchBuilder.getOwnerAlias()));
        if (columnAliases.length == 0) {
            final CollectionPersister collectionPersister = alias2CollectionPersister.get(fetchBuilder.getTableAlias());
            if (collectionPersister == null) {
                columnNames = Collections.emptyList();
            } else {
                final String collectionSuffix = alias2CollectionSuffix.get(fetchBuilder.getTableAlias());
                final String[] keyColumnAliases = collectionPersister.getKeyColumnAliases(collectionSuffix);
                columnNames = Arrays.asList(keyColumnAliases);
                if (collectionPersister.hasIndex()) {
                    resultBuilderEntity.addProperty(CollectionPart.Nature.INDEX.getName(), collectionPersister.getIndexColumnAliases(collectionSuffix));
                }
            }
        } else {
            columnNames = Arrays.asList(columnAliases);
        }
        ownerBuilder.addFetchBuilder(fetchBuilder.getFetchableName(), new DynamicFetchBuilderLegacy(fetchBuilder.getTableAlias(), fetchBuilder.getOwnerAlias(), fetchBuilder.getFetchableName(), columnNames, Collections.emptyMap(), resultBuilderEntity));
        // resultSetMapping.addResultBuilder( resultBuilderEntity );
        alias2Return.put(fetchBuilder.getTableAlias(), resultBuilderEntity);
    }
}
Also used : CollectionPersister(org.hibernate.persister.collection.CollectionPersister) DynamicFetchBuilderLegacy(org.hibernate.query.results.dynamic.DynamicFetchBuilderLegacy) SQLLoadable(org.hibernate.persister.entity.SQLLoadable) DynamicResultBuilderEntityStandard(org.hibernate.query.results.dynamic.DynamicResultBuilderEntityStandard)

Aggregations

DynamicFetchBuilderLegacy (org.hibernate.query.results.dynamic.DynamicFetchBuilderLegacy)11 DomainResultCreationState (org.hibernate.sql.results.graph.DomainResultCreationState)6 JdbcValuesMetadata (org.hibernate.sql.results.jdbc.spi.JdbcValuesMetadata)6 BiFunction (java.util.function.BiFunction)5 DomainResultCreationStateImpl (org.hibernate.query.results.DomainResultCreationStateImpl)5 ResultSetMappingSqlSelection (org.hibernate.query.results.ResultSetMappingSqlSelection)5 ResultsHelper.impl (org.hibernate.query.results.ResultsHelper.impl)5 NavigablePath (org.hibernate.query.spi.NavigablePath)4 SqlExpressionResolver (org.hibernate.sql.ast.spi.SqlExpressionResolver)4 SqlSelection (org.hibernate.sql.ast.spi.SqlSelection)4 TableGroup (org.hibernate.sql.ast.tree.from.TableGroup)4 HashMap (java.util.HashMap)3 List (java.util.List)3 Map (java.util.Map)3 FetchTiming (org.hibernate.engine.FetchTiming)3 SessionFactoryImplementor (org.hibernate.engine.spi.SessionFactoryImplementor)3 ResultBuilder (org.hibernate.query.results.ResultBuilder)3 Fetch (org.hibernate.sql.results.graph.Fetch)3 FetchParent (org.hibernate.sql.results.graph.FetchParent)3 BasicResult (org.hibernate.sql.results.graph.basic.BasicResult)3