Add SqlSelection.getExpressionType() and remove some typecasts

This commit is contained in:
gavinking 2020-02-20 16:40:08 +01:00 committed by Steve Ebersole
parent a1a85e2517
commit 2dd745110d
3 changed files with 15 additions and 6 deletions

View File

@ -7,6 +7,7 @@
package org.hibernate.sql.ast.spi;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.metamodel.mapping.MappingModelExpressable;
import org.hibernate.sql.results.jdbc.spi.JdbcValuesMetadata;
import org.hibernate.sql.results.jdbc.spi.RowProcessingState;
import org.hibernate.sql.ast.SqlAstWalker;
@ -45,6 +46,11 @@ public interface SqlSelection {
return getValuesArrayPosition() + 1;
}
/**
* Get the type of the expression
*/
MappingModelExpressable getExpressionType();
void accept(SqlAstWalker sqlAstWalker);
default void prepare(JdbcValuesMetadata jdbcResultsMetadata, SessionFactoryImplementor sessionFactory) {

View File

@ -25,7 +25,6 @@ import org.hibernate.sql.ast.tree.predicate.PredicateContainer;
import org.hibernate.sql.results.graph.DomainResult;
import org.hibernate.sql.results.graph.DomainResultCreationState;
import org.hibernate.sql.results.graph.basic.BasicResult;
import org.hibernate.sql.results.internal.SqlSelectionImpl;
import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
import org.hibernate.type.spi.TypeConfiguration;
@ -122,15 +121,14 @@ public class QuerySpec implements SqlAstNode, PredicateContainer, Expression, Ct
@Override
public MappingModelExpressable getExpressionType() {
SqlSelection first = selectClause.getSqlSelections().get(0);
return ( (SqlSelectionImpl) first ).getWrappedSqlExpression().getExpressionType();
return first.getExpressionType();
}
@Override
public void applySqlSelections(DomainResultCreationState creationState) {
SqlSelection first = selectClause.getSqlSelections().get(0);
TypeConfiguration typeConfiguration = creationState.getSqlAstCreationState().getCreationContext().getDomainModel().getTypeConfiguration();
JavaTypeDescriptor descriptor = ( (SqlSelectionImpl) first ).getWrappedSqlExpression().getExpressionType()
.getJdbcMappings( typeConfiguration ).get(0).getJavaTypeDescriptor();
JavaTypeDescriptor descriptor = first.getExpressionType().getJdbcMappings( typeConfiguration ).get(0).getJavaTypeDescriptor();
creationState.getSqlAstCreationState().getSqlExpressionResolver().resolveSqlSelection(
this,
descriptor,
@ -142,8 +140,7 @@ public class QuerySpec implements SqlAstNode, PredicateContainer, Expression, Ct
public DomainResult createDomainResult(String resultVariable, DomainResultCreationState creationState) {
SqlSelection first = selectClause.getSqlSelections().get(0);
TypeConfiguration typeConfiguration = creationState.getSqlAstCreationState().getCreationContext().getDomainModel().getTypeConfiguration();
JavaTypeDescriptor descriptor = ( (SqlSelectionImpl) first ).getWrappedSqlExpression().getExpressionType()
.getJdbcMappings( typeConfiguration ).get(0).getJavaTypeDescriptor();
JavaTypeDescriptor descriptor = first.getExpressionType().getJdbcMappings( typeConfiguration ).get(0).getJavaTypeDescriptor();
final SqlExpressionResolver sqlExpressionResolver = creationState.getSqlAstCreationState().getSqlExpressionResolver();
final SqlSelection sqlSelection = sqlExpressionResolver.resolveSqlSelection(

View File

@ -6,6 +6,7 @@
*/
package org.hibernate.sql.results.internal;
import org.hibernate.metamodel.mapping.MappingModelExpressable;
import org.hibernate.metamodel.mapping.SqlExpressable;
import org.hibernate.sql.ast.SqlAstWalker;
import org.hibernate.sql.ast.spi.SqlSelection;
@ -65,6 +66,11 @@ public class SqlSelectionImpl implements SqlSelection {
return valuesArrayPosition;
}
@Override
public MappingModelExpressable getExpressionType() {
return getWrappedSqlExpression().getExpressionType();
}
@Override
public void accept(SqlAstWalker interpreter) {
sqlExpression.accept( interpreter );