Search in sources :

Example 11 with BasicResult

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

the class DynamicResultBuilderAttribute method buildResult.

@Override
public DomainResult<?> buildResult(JdbcValuesMetadata jdbcResultsMetadata, int resultPosition, BiFunction<String, String, DynamicFetchBuilderLegacy> legacyFetchResolver, DomainResultCreationState domainResultCreationState) {
    // todo (6.0) : TableGroups + `attributeMapping#buldResult`
    final SqlExpressionResolver sqlExpressionResolver = domainResultCreationState.getSqlAstCreationState().getSqlExpressionResolver();
    final SqlSelection sqlSelection = sqlExpressionResolver.resolveSqlSelection(sqlExpressionResolver.resolveSqlExpression(columnAlias, state -> {
        final int resultSetPosition = jdbcResultsMetadata.resolveColumnPosition(columnAlias);
        final int valuesArrayPosition = resultSetPosition - 1;
        return new ResultSetMappingSqlSelection(valuesArrayPosition, attributeMapping);
    }), attributeMapping.getJavaType(), null, domainResultCreationState.getSqlAstCreationState().getCreationContext().getSessionFactory().getTypeConfiguration());
    return new BasicResult<>(sqlSelection.getValuesArrayPosition(), columnAlias, attributeMapping.getJavaType(), attributeMapping.getValueConverter());
}
Also used : DomainResultCreationState(org.hibernate.sql.results.graph.DomainResultCreationState) JdbcValuesMetadata(org.hibernate.sql.results.jdbc.spi.JdbcValuesMetadata) ResultSetMappingSqlSelection(org.hibernate.query.results.ResultSetMappingSqlSelection) Locale(java.util.Locale) SingularAttributeMapping(org.hibernate.metamodel.mapping.SingularAttributeMapping) BiFunction(java.util.function.BiFunction) NativeQuery(org.hibernate.query.NativeQuery) DomainResult(org.hibernate.sql.results.graph.DomainResult) BasicAttributeMapping(org.hibernate.metamodel.mapping.internal.BasicAttributeMapping) SqlSelection(org.hibernate.sql.ast.spi.SqlSelection) BasicResult(org.hibernate.sql.results.graph.basic.BasicResult) SqlExpressionResolver(org.hibernate.sql.ast.spi.SqlExpressionResolver) SqlExpressionResolver(org.hibernate.sql.ast.spi.SqlExpressionResolver) 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 12 with BasicResult

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

the class DynamicResultBuilderBasicStandard method buildResult.

@Override
public BasicResult<?> buildResult(JdbcValuesMetadata jdbcResultsMetadata, int resultPosition, BiFunction<String, String, DynamicFetchBuilderLegacy> legacyFetchResolver, DomainResultCreationState domainResultCreationState) {
    final SessionFactoryImplementor sessionFactory = domainResultCreationState.getSqlAstCreationState().getCreationContext().getSessionFactory();
    final SqlExpressionResolver sqlExpressionResolver = domainResultCreationState.getSqlAstCreationState().getSqlExpressionResolver();
    final Expression expression = sqlExpressionResolver.resolveSqlExpression(columnName, state -> {
        final int jdbcPosition;
        if (columnPosition > 0) {
            jdbcPosition = columnPosition;
        } else {
            jdbcPosition = jdbcResultsMetadata.resolveColumnPosition(columnName);
        }
        final int valuesArrayPosition = ResultsHelper.jdbcPositionToValuesArrayPosition(jdbcPosition);
        final BasicType<?> basicType;
        if (explicitType != null) {
            basicType = explicitType;
        } else {
            basicType = jdbcResultsMetadata.resolveType(jdbcPosition, explicitJavaType, sessionFactory);
        }
        return new ResultSetMappingSqlSelection(valuesArrayPosition, (BasicValuedMapping) basicType);
    });
    final JavaType<?> javaType;
    if (explicitJavaType != null) {
        javaType = explicitJavaType;
    } else {
        javaType = expression.getExpressionType().getJdbcMappings().get(0).getMappedJavaType();
    }
    final SqlSelection sqlSelection = sqlExpressionResolver.resolveSqlSelection(expression, javaType, null, sessionFactory.getTypeConfiguration());
    // StandardRowReader expects there to be a JavaType as part of the ResultAssembler.
    assert javaType != null;
    return new BasicResult<>(sqlSelection.getValuesArrayPosition(), resultAlias, javaType);
}
Also used : SqlExpressionResolver(org.hibernate.sql.ast.spi.SqlExpressionResolver) Expression(org.hibernate.sql.ast.tree.expression.Expression) 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 13 with BasicResult

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

the class ImplicitModelPartResultBuilderBasic method buildResult.

@Override
public BasicResult<?> buildResult(JdbcValuesMetadata jdbcResultsMetadata, int resultPosition, BiFunction<String, String, DynamicFetchBuilderLegacy> legacyFetchResolver, DomainResultCreationState domainResultCreationState) {
    final DomainResultCreationStateImpl creationStateImpl = ResultsHelper.impl(domainResultCreationState);
    final TableGroup tableGroup = creationStateImpl.getFromClauseAccess().getTableGroup(navigablePath.getParent());
    return (BasicResult<?>) modelPart.createDomainResult(navigablePath, tableGroup, null, domainResultCreationState);
}
Also used : DomainResultCreationStateImpl(org.hibernate.query.results.DomainResultCreationStateImpl) TableGroup(org.hibernate.sql.ast.tree.from.TableGroup) BasicResult(org.hibernate.sql.results.graph.basic.BasicResult)

Example 14 with BasicResult

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

the class EntityRowIdMappingImpl method createDomainResult.

@Override
public <T> DomainResult<T> createDomainResult(NavigablePath navigablePath, TableGroup tableGroup, String resultVariable, DomainResultCreationState creationState) {
    final SqlAstCreationState sqlAstCreationState = creationState.getSqlAstCreationState();
    final SqlExpressionResolver sqlExpressionResolver = sqlAstCreationState.getSqlExpressionResolver();
    final TableReference columnTableReference = tableGroup.resolveTableReference(navigablePath, tableExpression);
    final SqlSelection sqlSelection = sqlExpressionResolver.resolveSqlSelection(sqlExpressionResolver.resolveSqlExpression(SqlExpressionResolver.createColumnReferenceKey(columnTableReference, rowIdName), sqlAstProcessingState -> new ColumnReference(columnTableReference, rowIdName, false, // having to write a Dialect
    null, null, rowIdType, sqlAstCreationState.getCreationContext().getSessionFactory())), rowIdType.getJavaTypeDescriptor(), null, sqlAstCreationState.getCreationContext().getSessionFactory().getTypeConfiguration());
    return new BasicResult(sqlSelection.getValuesArrayPosition(), resultVariable, rowIdType.getJavaTypeDescriptor(), navigablePath);
}
Also used : DomainResultCreationState(org.hibernate.sql.results.graph.DomainResultCreationState) JdbcMapping(org.hibernate.metamodel.mapping.JdbcMapping) BasicType(org.hibernate.type.BasicType) ColumnReference(org.hibernate.sql.ast.tree.expression.ColumnReference) DomainResult(org.hibernate.sql.results.graph.DomainResult) JavaType(org.hibernate.type.descriptor.java.JavaType) Clause(org.hibernate.sql.ast.Clause) NavigablePath(org.hibernate.spi.NavigablePath) EntityMappingType(org.hibernate.metamodel.mapping.EntityMappingType) BasicResult(org.hibernate.sql.results.graph.basic.BasicResult) MappingType(org.hibernate.metamodel.mapping.MappingType) SqlExpressionResolver(org.hibernate.sql.ast.spi.SqlExpressionResolver) TableReference(org.hibernate.sql.ast.tree.from.TableReference) NavigableRole(org.hibernate.metamodel.model.domain.NavigableRole) EntityRowIdMapping(org.hibernate.metamodel.mapping.EntityRowIdMapping) SelectableMapping(org.hibernate.metamodel.mapping.SelectableMapping) BiConsumer(java.util.function.BiConsumer) TableGroup(org.hibernate.sql.ast.tree.from.TableGroup) SqlSelection(org.hibernate.sql.ast.spi.SqlSelection) SharedSessionContractImplementor(org.hibernate.engine.spi.SharedSessionContractImplementor) IndexedConsumer(org.hibernate.mapping.IndexedConsumer) SqlAstCreationState(org.hibernate.sql.ast.spi.SqlAstCreationState) TableReference(org.hibernate.sql.ast.tree.from.TableReference) SqlExpressionResolver(org.hibernate.sql.ast.spi.SqlExpressionResolver) BasicResult(org.hibernate.sql.results.graph.basic.BasicResult) SqlAstCreationState(org.hibernate.sql.ast.spi.SqlAstCreationState) SqlSelection(org.hibernate.sql.ast.spi.SqlSelection) ColumnReference(org.hibernate.sql.ast.tree.expression.ColumnReference)

Example 15 with BasicResult

use of org.hibernate.sql.results.graph.basic.BasicResult 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(), null, 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)

Aggregations

BasicResult (org.hibernate.sql.results.graph.basic.BasicResult)18 SqlSelection (org.hibernate.sql.ast.spi.SqlSelection)16 SqlExpressionResolver (org.hibernate.sql.ast.spi.SqlExpressionResolver)12 DomainResultCreationState (org.hibernate.sql.results.graph.DomainResultCreationState)9 JavaType (org.hibernate.type.descriptor.java.JavaType)9 TableGroup (org.hibernate.sql.ast.tree.from.TableGroup)8 SessionFactoryImplementor (org.hibernate.engine.spi.SessionFactoryImplementor)7 ResultSetMappingSqlSelection (org.hibernate.query.results.ResultSetMappingSqlSelection)6 SqlAstCreationState (org.hibernate.sql.ast.spi.SqlAstCreationState)6 ColumnReference (org.hibernate.sql.ast.tree.expression.ColumnReference)6 Expression (org.hibernate.sql.ast.tree.expression.Expression)6 DomainResult (org.hibernate.sql.results.graph.DomainResult)6 BiConsumer (java.util.function.BiConsumer)5 BiFunction (java.util.function.BiFunction)5 EntityMappingType (org.hibernate.metamodel.mapping.EntityMappingType)5 JdbcMapping (org.hibernate.metamodel.mapping.JdbcMapping)5 NavigablePath (org.hibernate.spi.NavigablePath)5 TableReference (org.hibernate.sql.ast.tree.from.TableReference)5 JdbcValuesMetadata (org.hibernate.sql.results.jdbc.spi.JdbcValuesMetadata)5 SharedSessionContractImplementor (org.hibernate.engine.spi.SharedSessionContractImplementor)4