Search in sources :

Example 6 with BasicResult

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

the class DynamicResultBuilderBasicConverted method buildResult.

@Override
public BasicResult<?> buildResult(JdbcValuesMetadata jdbcResultsMetadata, int resultPosition, BiFunction<String, String, DynamicFetchBuilderLegacy> legacyFetchResolver, DomainResultCreationState domainResultCreationState) {
    final TypeConfiguration typeConfiguration = domainResultCreationState.getSqlAstCreationState().getCreationContext().getSessionFactory().getTypeConfiguration();
    final SqlExpressionResolver sqlExpressionResolver = domainResultCreationState.getSqlAstCreationState().getSqlExpressionResolver();
    final SqlSelection sqlSelection = sqlExpressionResolver.resolveSqlSelection(sqlExpressionResolver.resolveSqlExpression(columnAlias, state -> {
        final int currentJdbcPosition = resultPosition + 1;
        final int jdbcPosition;
        if (columnAlias != null) {
            jdbcPosition = jdbcResultsMetadata.resolveColumnPosition(columnAlias);
        } else {
            jdbcPosition = currentJdbcPosition;
        }
        final BasicType<?> basicType = jdbcResultsMetadata.resolveType(jdbcPosition, basicValueConverter.getRelationalJavaType(), domainResultCreationState.getSqlAstCreationState().getCreationContext().getSessionFactory());
        final int valuesArrayPosition = ResultsHelper.jdbcPositionToValuesArrayPosition(jdbcPosition);
        return new ResultSetMappingSqlSelection(valuesArrayPosition, (BasicValuedMapping) basicType);
    }), basicValueConverter.getDomainJavaType(), null, typeConfiguration);
    return new BasicResult<>(sqlSelection.getValuesArrayPosition(), columnAlias, basicValueConverter.getDomainJavaType(), basicValueConverter);
}
Also used : DomainResultCreationState(org.hibernate.sql.results.graph.DomainResultCreationState) JpaAttributeConverterImpl(org.hibernate.metamodel.model.convert.internal.JpaAttributeConverterImpl) ProvidedInstanceManagedBeanImpl(org.hibernate.resource.beans.spi.ProvidedInstanceManagedBeanImpl) ResultSetMappingSqlSelection(org.hibernate.query.results.ResultSetMappingSqlSelection) TypeConfiguration(org.hibernate.type.spi.TypeConfiguration) BasicType(org.hibernate.type.BasicType) BiFunction(java.util.function.BiFunction) JavaType(org.hibernate.type.descriptor.java.JavaType) BasicValuedMapping(org.hibernate.metamodel.mapping.BasicValuedMapping) BasicResult(org.hibernate.sql.results.graph.basic.BasicResult) SqlExpressionResolver(org.hibernate.sql.ast.spi.SqlExpressionResolver) 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) ManagedBeanRegistry(org.hibernate.resource.beans.spi.ManagedBeanRegistry) BasicValueConverter(org.hibernate.metamodel.model.convert.spi.BasicValueConverter) AttributeConverter(jakarta.persistence.AttributeConverter) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) SqlSelection(org.hibernate.sql.ast.spi.SqlSelection) JavaTypeRegistry(org.hibernate.type.descriptor.java.spi.JavaTypeRegistry) BasicValuedMapping(org.hibernate.metamodel.mapping.BasicValuedMapping) BasicType(org.hibernate.type.BasicType) SqlExpressionResolver(org.hibernate.sql.ast.spi.SqlExpressionResolver) BasicResult(org.hibernate.sql.results.graph.basic.BasicResult) TypeConfiguration(org.hibernate.type.spi.TypeConfiguration) ResultSetMappingSqlSelection(org.hibernate.query.results.ResultSetMappingSqlSelection) ResultSetMappingSqlSelection(org.hibernate.query.results.ResultSetMappingSqlSelection) SqlSelection(org.hibernate.sql.ast.spi.SqlSelection)

Example 7 with BasicResult

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

the class JdbcLiteral method createDomainResult.

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// DomainResultProducer
@Override
public DomainResult<T> createDomainResult(String resultVariable, DomainResultCreationState creationState) {
    final SqlAstCreationState sqlAstCreationState = creationState.getSqlAstCreationState();
    final SqlExpressionResolver sqlExpressionResolver = sqlAstCreationState.getSqlExpressionResolver();
    final SqlSelection sqlSelection = sqlExpressionResolver.resolveSqlSelection(this, jdbcMapping.getJavaTypeDescriptor(), null, sqlAstCreationState.getCreationContext().getMappingMetamodel().getTypeConfiguration());
    // noinspection unchecked
    return new BasicResult(sqlSelection.getValuesArrayPosition(), resultVariable, jdbcMapping.getJavaTypeDescriptor());
}
Also used : 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)

Example 8 with BasicResult

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

the class QueryLiteral method createDomainResult.

@Override
public DomainResult<T> createDomainResult(String resultVariable, DomainResultCreationState creationState) {
    final SqlExpressionResolver sqlExpressionResolver = creationState.getSqlAstCreationState().getSqlExpressionResolver();
    final SqlSelection sqlSelection = sqlExpressionResolver.resolveSqlSelection(this, type.getMappedType().getMappedJavaType(), null, creationState.getSqlAstCreationState().getCreationContext().getSessionFactory().getTypeConfiguration());
    return new BasicResult(sqlSelection.getValuesArrayPosition(), resultVariable, type.getMappedType().getMappedJavaType());
}
Also used : SqlExpressionResolver(org.hibernate.sql.ast.spi.SqlExpressionResolver) BasicResult(org.hibernate.sql.results.graph.basic.BasicResult) SqlSelection(org.hibernate.sql.ast.spi.SqlSelection)

Example 9 with BasicResult

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

the class SimpleForeignKeyDescriptor method createDomainResult.

private <T> DomainResult<T> createDomainResult(NavigablePath navigablePath, TableGroup tableGroup, SelectableMapping selectableMapping, DomainResultCreationState creationState) {
    final SqlAstCreationState sqlAstCreationState = creationState.getSqlAstCreationState();
    final SqlExpressionResolver sqlExpressionResolver = sqlAstCreationState.getSqlExpressionResolver();
    final TableReference tableReference = tableGroup.resolveTableReference(navigablePath.append(getTargetPart().getFetchableName()), selectableMapping.getContainingTableExpression());
    final String identificationVariable = tableReference.getIdentificationVariable();
    final SqlSelection sqlSelection = sqlExpressionResolver.resolveSqlSelection(sqlExpressionResolver.resolveSqlExpression(SqlExpressionResolver.createColumnReferenceKey(tableReference, selectableMapping.getSelectionExpression()), s -> new ColumnReference(identificationVariable, selectableMapping, creationState.getSqlAstCreationState().getCreationContext().getSessionFactory())), selectableMapping.getJdbcMapping().getJavaTypeDescriptor(), sqlAstCreationState.getCreationContext().getSessionFactory().getTypeConfiguration());
    // noinspection unchecked
    return new BasicResult<T>(sqlSelection.getValuesArrayPosition(), null, selectableMapping.getJdbcMapping().getJavaTypeDescriptor());
}
Also used : BasicValuedModelPart(org.hibernate.metamodel.mapping.BasicValuedModelPart) DomainResultCreationState(org.hibernate.sql.results.graph.DomainResultCreationState) JdbcMapping(org.hibernate.metamodel.mapping.JdbcMapping) ColumnReference(org.hibernate.sql.ast.tree.expression.ColumnReference) JavaType(org.hibernate.type.descriptor.java.JavaType) Clause(org.hibernate.sql.ast.Clause) PropertyAccess(org.hibernate.property.access.spi.PropertyAccess) EntityMappingType(org.hibernate.metamodel.mapping.EntityMappingType) MappingType(org.hibernate.metamodel.mapping.MappingType) SqlAstCreationContext(org.hibernate.sql.ast.spi.SqlAstCreationContext) TableReference(org.hibernate.sql.ast.tree.from.TableReference) ModelPart(org.hibernate.metamodel.mapping.ModelPart) ComparisonPredicate(org.hibernate.sql.ast.tree.predicate.ComparisonPredicate) ForeignKeyDescriptor(org.hibernate.metamodel.mapping.ForeignKeyDescriptor) HibernateProxy(org.hibernate.proxy.HibernateProxy) FetchOptions(org.hibernate.sql.results.graph.FetchOptions) BiConsumer(java.util.function.BiConsumer) ManagedMappingType(org.hibernate.metamodel.mapping.ManagedMappingType) ComparisonOperator(org.hibernate.query.sqm.ComparisonOperator) TableGroupProducer(org.hibernate.sql.ast.tree.from.TableGroupProducer) SqlSelection(org.hibernate.sql.ast.spi.SqlSelection) IntFunction(java.util.function.IntFunction) SqlAstCreationState(org.hibernate.sql.ast.spi.SqlAstCreationState) FetchTiming(org.hibernate.engine.FetchTiming) AssociationKey(org.hibernate.metamodel.mapping.AssociationKey) Predicate(org.hibernate.sql.ast.tree.predicate.Predicate) NavigablePath(org.hibernate.query.spi.NavigablePath) DomainResult(org.hibernate.sql.results.graph.DomainResult) Expression(org.hibernate.sql.ast.tree.expression.Expression) PropertyBasedMapping(org.hibernate.metamodel.mapping.PropertyBasedMapping) Fetch(org.hibernate.sql.results.graph.Fetch) BasicResult(org.hibernate.sql.results.graph.basic.BasicResult) SqlExpressionResolver(org.hibernate.sql.ast.spi.SqlExpressionResolver) NavigableRole(org.hibernate.metamodel.model.domain.NavigableRole) FetchStyle(org.hibernate.engine.FetchStyle) List(java.util.List) SelectableMapping(org.hibernate.metamodel.mapping.SelectableMapping) Collections(java.util.Collections) SelectableConsumer(org.hibernate.metamodel.mapping.SelectableConsumer) TableGroup(org.hibernate.sql.ast.tree.from.TableGroup) SharedSessionContractImplementor(org.hibernate.engine.spi.SharedSessionContractImplementor) IndexedConsumer(org.hibernate.mapping.IndexedConsumer) FetchParent(org.hibernate.sql.results.graph.FetchParent) 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 10 with BasicResult

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

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