Search in sources :

Example 1 with DynamicFetchBuilderLegacy

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

the class NativeQueryImpl method addFetch.

@Override
public FetchReturn addFetch(String tableAlias, String ownerTableAlias, String joinPropertyName) {
    final DynamicFetchBuilderLegacy fetchBuilder = Builders.fetch(tableAlias, ownerTableAlias, joinPropertyName);
    resultSetMapping.addLegacyFetchBuilder(fetchBuilder);
    return fetchBuilder;
}
Also used : DynamicFetchBuilderLegacy(org.hibernate.query.results.dynamic.DynamicFetchBuilderLegacy)

Example 2 with DynamicFetchBuilderLegacy

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

the class FetchMementoHbmStandard method resolve.

@Override
public FetchBuilder resolve(Parent parent, Consumer<String> querySpaceConsumer, ResultSetMappingResolutionContext context) {
    final Map<String, FetchBuilder> fetchBuilderMap = new HashMap<>();
    fetchMementoMap.forEach((attrName, fetchMemento) -> fetchBuilderMap.put(attrName, fetchMemento.resolve(this, querySpaceConsumer, context)));
    final DynamicResultBuilderEntityStandard resultBuilder;
    if (fetchable instanceof PluralAttributeMapping) {
        resultBuilder = new DynamicResultBuilderEntityStandard((EntityMappingType) ((PluralAttributeMapping) fetchable).getElementDescriptor().getPartMappingType(), tableAlias, navigablePath);
        FetchBuilder element = fetchBuilderMap.get("element");
        if (element != null) {
            if (element instanceof DynamicFetchBuilder) {
                resultBuilder.addIdColumnAliases(((DynamicFetchBuilder) element).getColumnAliases().toArray(new String[0]));
            } else {
                resultBuilder.addIdColumnAliases(((CompleteFetchBuilderEntityValuedModelPart) element).getColumnAliases().toArray(new String[0]));
            }
        }
        FetchBuilder index = fetchBuilderMap.get("index");
        if (index != null) {
            resultBuilder.addFetchBuilder(CollectionPart.Nature.INDEX.getName(), index);
        }
        for (Map.Entry<String, FetchBuilder> entry : fetchBuilderMap.entrySet()) {
            if (entry.getKey().startsWith(ELEMENT_PREFIX)) {
                resultBuilder.addFetchBuilder(entry.getKey().substring(ELEMENT_PREFIX.length()), entry.getValue());
            }
        }
    } else {
        resultBuilder = new DynamicResultBuilderEntityStandard(((ToOneAttributeMapping) fetchable).getEntityMappingType(), tableAlias, navigablePath);
        fetchBuilderMap.forEach(resultBuilder::addFetchBuilder);
    }
    return new DynamicFetchBuilderLegacy(tableAlias, ownerTableAlias, fetchable.getFetchableName(), keyColumnNames, fetchBuilderMap, resultBuilder);
}
Also used : DynamicFetchBuilder(org.hibernate.query.results.dynamic.DynamicFetchBuilder) FetchBuilder(org.hibernate.query.results.FetchBuilder) CompleteFetchBuilderEntityValuedModelPart(org.hibernate.query.results.complete.CompleteFetchBuilderEntityValuedModelPart) HashMap(java.util.HashMap) PluralAttributeMapping(org.hibernate.metamodel.mapping.PluralAttributeMapping) DynamicFetchBuilder(org.hibernate.query.results.dynamic.DynamicFetchBuilder) ToOneAttributeMapping(org.hibernate.metamodel.mapping.internal.ToOneAttributeMapping) DynamicFetchBuilderLegacy(org.hibernate.query.results.dynamic.DynamicFetchBuilderLegacy) DynamicResultBuilderEntityStandard(org.hibernate.query.results.dynamic.DynamicResultBuilderEntityStandard) EntityMappingType(org.hibernate.metamodel.mapping.EntityMappingType) HashMap(java.util.HashMap) Map(java.util.Map)

Example 3 with DynamicFetchBuilderLegacy

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

the class CompleteResultBuilderBasicModelPart method buildResult.

@Override
public BasicResult<?> buildResult(JdbcValuesMetadata jdbcResultsMetadata, int resultPosition, BiFunction<String, String, DynamicFetchBuilderLegacy> legacyFetchResolver, DomainResultCreationState domainResultCreationState) {
    final DomainResultCreationStateImpl creationStateImpl = impl(domainResultCreationState);
    final TableGroup tableGroup = creationStateImpl.getFromClauseAccess().getTableGroup(navigablePath.getParent());
    final TableReference tableReference = tableGroup.resolveTableReference(navigablePath, modelPart.getContainingTableExpression());
    final String mappedColumn = modelPart.getSelectionExpression();
    final SqlSelection sqlSelection = creationStateImpl.resolveSqlSelection(creationStateImpl.resolveSqlExpression(SqlExpressionResolver.createColumnReferenceKey(tableReference, mappedColumn), processingState -> {
        final int jdbcPosition = jdbcResultsMetadata.resolveColumnPosition(columnAlias);
        final int valuesArrayPosition = jdbcPositionToValuesArrayPosition(jdbcPosition);
        return new ResultSetMappingSqlSelection(valuesArrayPosition, modelPart);
    }), modelPart.getJavaType(), creationStateImpl.getSessionFactory().getTypeConfiguration());
    // noinspection unchecked
    return new BasicResult(sqlSelection.getValuesArrayPosition(), columnAlias, modelPart.getJavaType());
}
Also used : BasicValuedModelPart(org.hibernate.metamodel.mapping.BasicValuedModelPart) 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) NavigablePath(org.hibernate.query.spi.NavigablePath) DomainResultCreationStateImpl(org.hibernate.query.results.DomainResultCreationStateImpl) BasicResult(org.hibernate.sql.results.graph.basic.BasicResult) 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) ResultsHelper.jdbcPositionToValuesArrayPosition(org.hibernate.query.results.ResultsHelper.jdbcPositionToValuesArrayPosition) ResultBuilder(org.hibernate.query.results.ResultBuilder) TableGroup(org.hibernate.sql.ast.tree.from.TableGroup) SqlSelection(org.hibernate.sql.ast.spi.SqlSelection) TableReference(org.hibernate.sql.ast.tree.from.TableReference) DomainResultCreationStateImpl(org.hibernate.query.results.DomainResultCreationStateImpl) TableGroup(org.hibernate.sql.ast.tree.from.TableGroup) BasicResult(org.hibernate.sql.results.graph.basic.BasicResult) ResultSetMappingSqlSelection(org.hibernate.query.results.ResultSetMappingSqlSelection) ResultSetMappingSqlSelection(org.hibernate.query.results.ResultSetMappingSqlSelection) SqlSelection(org.hibernate.sql.ast.spi.SqlSelection)

Example 4 with DynamicFetchBuilderLegacy

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

the class CompleteFetchBuilderEmbeddableValuedModelPart 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.IMMEDIATE, 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) EmbeddableValuedModelPart(org.hibernate.metamodel.mapping.EmbeddableValuedModelPart) 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 5 with DynamicFetchBuilderLegacy

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

the class ResultSetMappingImpl method addLegacyFetchBuilder.

@Override
public void addLegacyFetchBuilder(DynamicFetchBuilderLegacy fetchBuilder) {
    final Map<String, DynamicFetchBuilderLegacy> existingFetchBuildersByOwner;
    if (legacyFetchBuilders == null) {
        legacyFetchBuilders = new HashMap<>();
        existingFetchBuildersByOwner = null;
    } else {
        existingFetchBuildersByOwner = legacyFetchBuilders.get(fetchBuilder.getOwnerAlias());
    }
    final Map<String, DynamicFetchBuilderLegacy> fetchBuildersByOwner;
    if (existingFetchBuildersByOwner == null) {
        fetchBuildersByOwner = new HashMap<>();
        legacyFetchBuilders.put(fetchBuilder.getOwnerAlias(), fetchBuildersByOwner);
    } else {
        fetchBuildersByOwner = existingFetchBuildersByOwner;
    }
    final DynamicFetchBuilderLegacy previousBuilder = fetchBuildersByOwner.put(fetchBuilder.getFetchableName(), fetchBuilder);
    if (previousBuilder != null) {
    // todo (6.0) : error?  log?  nothing?
    }
}
Also used : DynamicFetchBuilderLegacy(org.hibernate.query.results.dynamic.DynamicFetchBuilderLegacy)

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