From 92d447cddd45c1b452f57c78c9f865e83091f676 Mon Sep 17 00:00:00 2001 From: Christian Beikov Date: Tue, 22 Nov 2022 18:15:03 +0100 Subject: [PATCH] Make use of JavaType in SqlSelection --- .../sql/ast/tree/expression/Expression.java | 1 + .../sql/exec/internal/AbstractJdbcParameter.java | 1 + .../sql/results/internal/ResolvedSqlSelection.java | 2 +- .../sql/results/internal/SqlSelectionImpl.java | 14 +++++++++++++- 4 files changed, 16 insertions(+), 2 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/expression/Expression.java b/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/expression/Expression.java index c016ae83f1..21993ee72e 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/expression/Expression.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/expression/Expression.java @@ -38,6 +38,7 @@ public interface Expression extends SqlAstNode, SqlSelectionProducer { return new SqlSelectionImpl( jdbcPosition, valuesArrayPosition, + javaType, this ); } diff --git a/hibernate-core/src/main/java/org/hibernate/sql/exec/internal/AbstractJdbcParameter.java b/hibernate-core/src/main/java/org/hibernate/sql/exec/internal/AbstractJdbcParameter.java index aa5dfbf798..62b51976ba 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/exec/internal/AbstractJdbcParameter.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/exec/internal/AbstractJdbcParameter.java @@ -68,6 +68,7 @@ public abstract class AbstractJdbcParameter return new SqlSelectionImpl( jdbcPosition, valuesArrayPosition, + javaType, this ); } diff --git a/hibernate-core/src/main/java/org/hibernate/sql/results/internal/ResolvedSqlSelection.java b/hibernate-core/src/main/java/org/hibernate/sql/results/internal/ResolvedSqlSelection.java index 9c30293991..4058f977c8 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/results/internal/ResolvedSqlSelection.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/results/internal/ResolvedSqlSelection.java @@ -27,7 +27,7 @@ public class ResolvedSqlSelection extends SqlSelectionImpl { int valuesArrayPosition, Expression sqlExpression, BasicType resolvedType) { - super( jdbcPosition, valuesArrayPosition, sqlExpression ); + super( jdbcPosition, valuesArrayPosition, null, sqlExpression ); this.resolvedType = resolvedType; } diff --git a/hibernate-core/src/main/java/org/hibernate/sql/results/internal/SqlSelectionImpl.java b/hibernate-core/src/main/java/org/hibernate/sql/results/internal/SqlSelectionImpl.java index b5515b11f3..3ebc7049aa 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/results/internal/SqlSelectionImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/results/internal/SqlSelectionImpl.java @@ -9,6 +9,7 @@ package org.hibernate.sql.results.internal; import java.util.Objects; import org.hibernate.engine.spi.SessionFactoryImplementor; +import org.hibernate.metamodel.mapping.JdbcMapping; import org.hibernate.metamodel.mapping.JdbcMappingContainer; import org.hibernate.metamodel.mapping.SqlExpressible; import org.hibernate.sql.ast.SqlAstWalker; @@ -19,6 +20,7 @@ import org.hibernate.sql.results.jdbc.spi.JdbcValuesMetadata; import org.hibernate.type.BasicType; import org.hibernate.type.JavaObjectType; import org.hibernate.type.descriptor.ValueExtractor; +import org.hibernate.type.descriptor.java.JavaType; /** * @asciidoc @@ -43,10 +45,16 @@ public class SqlSelectionImpl implements SqlSelection, SqlExpressionAccess { private final int jdbcPosition; private final int valuesArrayPosition; private final Expression sqlExpression; + private final JavaType jdbcJavaType; public SqlSelectionImpl(int jdbcPosition, int valuesArrayPosition, Expression sqlExpression) { + this( jdbcPosition, valuesArrayPosition, null, sqlExpression ); + } + + public SqlSelectionImpl(int jdbcPosition, int valuesArrayPosition, JavaType jdbcJavaType, Expression sqlExpression) { this.jdbcPosition = jdbcPosition; this.valuesArrayPosition = valuesArrayPosition; + this.jdbcJavaType = jdbcJavaType; this.sqlExpression = sqlExpression; } @@ -57,7 +65,11 @@ public class SqlSelectionImpl implements SqlSelection, SqlExpressionAccess { @Override public ValueExtractor getJdbcValueExtractor() { - return ( (SqlExpressible) sqlExpression.getExpressionType() ).getJdbcMapping().getJdbcValueExtractor(); + final JdbcMapping jdbcMapping = ( (SqlExpressible) sqlExpression.getExpressionType() ).getJdbcMapping(); + if ( jdbcJavaType == null || jdbcMapping.getMappedJavaType() == jdbcJavaType ) { + return jdbcMapping.getJdbcValueExtractor(); + } + return jdbcMapping.getJdbcType().getExtractor( jdbcJavaType ); } @Override