Search in sources :

Example 6 with BasicFetch

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

the class ImplicitFetchBuilderBasic method buildFetch.

@Override
public BasicFetch<?> buildFetch(FetchParent parent, NavigablePath fetchPath, JdbcValuesMetadata jdbcResultsMetadata, BiFunction<String, String, DynamicFetchBuilderLegacy> legacyFetchResolver, DomainResultCreationState domainResultCreationState) {
    final DomainResultCreationStateImpl creationStateImpl = ResultsHelper.impl(domainResultCreationState);
    final TableGroup parentTableGroup = creationStateImpl.getFromClauseAccess().getTableGroup(parent.getNavigablePath());
    final String table = fetchable.getContainingTableExpression();
    final String column;
    // In case of a formula we look for a result set position with the fetchable name
    if (fetchable.isFormula()) {
        column = fetchable.getFetchableName();
    } else {
        column = fetchable.getSelectionExpression();
    }
    final Expression expression = creationStateImpl.resolveSqlExpression(createColumnReferenceKey(parentTableGroup.resolveTableReference(fetchPath, table), fetchable.getSelectionExpression()), processingState -> {
        final int jdbcPosition = jdbcResultsMetadata.resolveColumnPosition(column);
        final int valuesArrayPosition = jdbcPositionToValuesArrayPosition(jdbcPosition);
        return new ResultSetMappingSqlSelection(valuesArrayPosition, fetchable);
    });
    final SqlSelection sqlSelection = creationStateImpl.resolveSqlSelection(expression, fetchable.getJavaType(), parent, domainResultCreationState.getSqlAstCreationState().getCreationContext().getSessionFactory().getTypeConfiguration());
    final BasicValueConverter<?, ?> valueConverter;
    if (fetchable instanceof ConvertibleModelPart) {
        valueConverter = ((ConvertibleModelPart) fetchable).getValueConverter();
    } else {
        valueConverter = null;
    }
    return new BasicFetch<>(sqlSelection.getValuesArrayPosition(), parent, fetchPath, fetchable, valueConverter, FetchTiming.IMMEDIATE, domainResultCreationState);
}
Also used : BasicFetch(org.hibernate.sql.results.graph.basic.BasicFetch) DomainResultCreationStateImpl(org.hibernate.query.results.DomainResultCreationStateImpl) TableGroup(org.hibernate.sql.ast.tree.from.TableGroup) ConvertibleModelPart(org.hibernate.metamodel.mapping.ConvertibleModelPart) Expression(org.hibernate.sql.ast.tree.expression.Expression) ResultSetMappingSqlSelection(org.hibernate.query.results.ResultSetMappingSqlSelection) ResultSetMappingSqlSelection(org.hibernate.query.results.ResultSetMappingSqlSelection) SqlSelection(org.hibernate.sql.ast.spi.SqlSelection)

Example 7 with BasicFetch

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

the class AnyDiscriminatorPart method generateFetch.

@Override
public Fetch generateFetch(FetchParent fetchParent, NavigablePath fetchablePath, FetchTiming fetchTiming, boolean selected, String resultVariable, DomainResultCreationState creationState) {
    final SqlAstCreationState sqlAstCreationState = creationState.getSqlAstCreationState();
    final SessionFactoryImplementor sessionFactory = sqlAstCreationState.getCreationContext().getSessionFactory();
    final FromClauseAccess fromClauseAccess = sqlAstCreationState.getFromClauseAccess();
    final SqlExpressionResolver sqlExpressionResolver = sqlAstCreationState.getSqlExpressionResolver();
    final TableGroup tableGroup = fromClauseAccess.getTableGroup(fetchablePath.getParent().getParent());
    final TableReference tableReference = tableGroup.resolveTableReference(fetchablePath, table);
    final Expression columnReference = sqlExpressionResolver.resolveSqlExpression(createColumnReferenceKey(tableReference, column), processingState -> new ColumnReference(tableReference, column, false, null, null, jdbcMapping(), sessionFactory));
    final SqlSelection sqlSelection = sqlExpressionResolver.resolveSqlSelection(columnReference, jdbcMapping().getMappedJavaType(), fetchParent, sessionFactory.getTypeConfiguration());
    return new BasicFetch<>(sqlSelection.getValuesArrayPosition(), fetchParent, fetchablePath, this, null, fetchTiming, creationState);
}
Also used : BasicFetch(org.hibernate.sql.results.graph.basic.BasicFetch) TableReference(org.hibernate.sql.ast.tree.from.TableReference) TableGroup(org.hibernate.sql.ast.tree.from.TableGroup) FromClauseAccess(org.hibernate.sql.ast.spi.FromClauseAccess) SqlExpressionResolver(org.hibernate.sql.ast.spi.SqlExpressionResolver) Expression(org.hibernate.sql.ast.tree.expression.Expression) SqlAstCreationState(org.hibernate.sql.ast.spi.SqlAstCreationState) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) ColumnReference(org.hibernate.sql.ast.tree.expression.ColumnReference) SqlSelection(org.hibernate.sql.ast.spi.SqlSelection)

Example 8 with BasicFetch

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

the class AnyKeyPart method generateFetch.

@Override
public Fetch generateFetch(FetchParent fetchParent, NavigablePath fetchablePath, FetchTiming fetchTiming, boolean selected, String resultVariable, DomainResultCreationState creationState) {
    final FromClauseAccess fromClauseAccess = creationState.getSqlAstCreationState().getFromClauseAccess();
    final SqlExpressionResolver sqlExpressionResolver = creationState.getSqlAstCreationState().getSqlExpressionResolver();
    final SessionFactoryImplementor sessionFactory = creationState.getSqlAstCreationState().getCreationContext().getSessionFactory();
    final TableGroup tableGroup = fromClauseAccess.getTableGroup(fetchParent.getNavigablePath().getParent());
    final TableReference tableReference = tableGroup.resolveTableReference(fetchablePath, table);
    final Expression columnReference = sqlExpressionResolver.resolveSqlExpression(SqlExpressionResolver.createColumnReferenceKey(tableReference, column), processingState -> new ColumnReference(tableReference, column, false, null, null, jdbcMapping, sessionFactory));
    final SqlSelection sqlSelection = sqlExpressionResolver.resolveSqlSelection(columnReference, getJavaType(), fetchParent, sessionFactory.getTypeConfiguration());
    return new BasicFetch<>(sqlSelection.getValuesArrayPosition(), fetchParent, fetchablePath, this, null, fetchTiming, creationState);
}
Also used : BasicFetch(org.hibernate.sql.results.graph.basic.BasicFetch) TableReference(org.hibernate.sql.ast.tree.from.TableReference) TableGroup(org.hibernate.sql.ast.tree.from.TableGroup) FromClauseAccess(org.hibernate.sql.ast.spi.FromClauseAccess) SqlExpressionResolver(org.hibernate.sql.ast.spi.SqlExpressionResolver) Expression(org.hibernate.sql.ast.tree.expression.Expression) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) ColumnReference(org.hibernate.sql.ast.tree.expression.ColumnReference) SqlSelection(org.hibernate.sql.ast.spi.SqlSelection)

Example 9 with BasicFetch

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

the class BasicValuedCollectionPart method generateFetch.

@Override
public Fetch generateFetch(FetchParent fetchParent, NavigablePath fetchablePath, FetchTiming fetchTiming, boolean selected, String resultVariable, DomainResultCreationState creationState) {
    ResultsLogger.RESULTS_LOGGER.debugf("Generating Fetch for collection-part : `%s` -> `%s`", collectionDescriptor.getRole(), nature.getName());
    NavigablePath parentNavigablePath = fetchablePath.getParent();
    if (parentNavigablePath instanceof EntityIdentifierNavigablePath) {
        parentNavigablePath = parentNavigablePath.getParent();
    }
    final TableGroup tableGroup = creationState.getSqlAstCreationState().getFromClauseAccess().findTableGroup(parentNavigablePath);
    final SqlSelection sqlSelection = resolveSqlSelection(fetchablePath, tableGroup, true, fetchParent, creationState);
    return new BasicFetch<>(sqlSelection.getValuesArrayPosition(), fetchParent, fetchablePath, this, valueConverter, FetchTiming.IMMEDIATE, creationState);
}
Also used : BasicFetch(org.hibernate.sql.results.graph.basic.BasicFetch) NavigablePath(org.hibernate.spi.NavigablePath) EntityIdentifierNavigablePath(org.hibernate.spi.EntityIdentifierNavigablePath) TableGroup(org.hibernate.sql.ast.tree.from.TableGroup) PluralTableGroup(org.hibernate.sql.ast.tree.from.PluralTableGroup) EntityIdentifierNavigablePath(org.hibernate.spi.EntityIdentifierNavigablePath) SqlSelection(org.hibernate.sql.ast.spi.SqlSelection)

Example 10 with BasicFetch

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

the class AbstractDiscriminatorMapping method generateFetch.

@Override
public BasicFetch generateFetch(FetchParent fetchParent, NavigablePath fetchablePath, FetchTiming fetchTiming, boolean selected, String resultVariable, DomainResultCreationState creationState) {
    final SqlAstCreationState sqlAstCreationState = creationState.getSqlAstCreationState();
    final TableGroup tableGroup = sqlAstCreationState.getFromClauseAccess().getTableGroup(fetchParent.getNavigablePath());
    assert tableGroup != null;
    final SqlSelection sqlSelection = resolveSqlSelection(fetchablePath, getUnderlyingJdbcMappingType(), tableGroup, fetchParent, creationState.getSqlAstCreationState());
    return new BasicFetch<>(sqlSelection.getValuesArrayPosition(), fetchParent, fetchablePath, this, null, fetchTiming, creationState);
}
Also used : BasicFetch(org.hibernate.sql.results.graph.basic.BasicFetch) TableGroup(org.hibernate.sql.ast.tree.from.TableGroup) SqlAstCreationState(org.hibernate.sql.ast.spi.SqlAstCreationState) SqlSelection(org.hibernate.sql.ast.spi.SqlSelection)

Aggregations

TableGroup (org.hibernate.sql.ast.tree.from.TableGroup)11 BasicFetch (org.hibernate.sql.results.graph.basic.BasicFetch)11 SqlSelection (org.hibernate.sql.ast.spi.SqlSelection)9 SqlAstCreationState (org.hibernate.sql.ast.spi.SqlAstCreationState)6 ColumnReference (org.hibernate.sql.ast.tree.expression.ColumnReference)5 TableReference (org.hibernate.sql.ast.tree.from.TableReference)5 SessionFactoryImplementor (org.hibernate.engine.spi.SessionFactoryImplementor)4 EntityMappingType (org.hibernate.metamodel.mapping.EntityMappingType)4 SqlExpressionResolver (org.hibernate.sql.ast.spi.SqlExpressionResolver)4 FetchTiming (org.hibernate.engine.FetchTiming)3 SharedSessionContractImplementor (org.hibernate.engine.spi.SharedSessionContractImplementor)3 NavigablePath (org.hibernate.spi.NavigablePath)3 Expression (org.hibernate.sql.ast.tree.expression.Expression)3 BiConsumer (java.util.function.BiConsumer)2 FetchStyle (org.hibernate.engine.FetchStyle)2 IndexedConsumer (org.hibernate.mapping.IndexedConsumer)2 JdbcMapping (org.hibernate.metamodel.mapping.JdbcMapping)2 MappingType (org.hibernate.metamodel.mapping.MappingType)2 NavigableRole (org.hibernate.metamodel.model.domain.NavigableRole)2 DomainResultCreationStateImpl (org.hibernate.query.results.DomainResultCreationStateImpl)2