diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/hbm/RelationalObjectBinder.java b/hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/hbm/RelationalObjectBinder.java index 851470dfad..3808cb6804 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/hbm/RelationalObjectBinder.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/hbm/RelationalObjectBinder.java @@ -105,7 +105,7 @@ public class RelationalObjectBinder { SimpleValue simpleValue, boolean areColumnsNullableByDefault, ColumnNamingDelegate columnNamingDelegate) { - Table table = simpleValue.getTable(); + final Table table = simpleValue.getTable(); final Column column = new Column(); column.setValue( simpleValue ); diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/temptable/TemporaryTable.java b/hibernate-core/src/main/java/org/hibernate/dialect/temptable/TemporaryTable.java index a4c405d8de..ea474a3aeb 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/temptable/TemporaryTable.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/temptable/TemporaryTable.java @@ -187,8 +187,6 @@ public class TemporaryTable implements Exportable, Contributable { column.getText( dialect ), jdbcMapping, column.getSqlType( - runtimeModelCreationContext.getTypeConfiguration(), - dialect, runtimeModelCreationContext.getMetadata() ), column.getColumnSize( @@ -234,8 +232,6 @@ public class TemporaryTable implements Exportable, Contributable { column.getText( dialect ), selection.getJdbcMapping(), column.getSqlType( - runtimeModelCreationContext.getTypeConfiguration(), - dialect, runtimeModelCreationContext.getMetadata() ), column.getColumnSize( @@ -289,8 +285,6 @@ public class TemporaryTable implements Exportable, Contributable { ENTITY_TABLE_IDENTITY_COLUMN, jdbcMapping, column.getSqlType( - runtimeModelCreationContext.getTypeConfiguration(), - dialect, runtimeModelCreationContext.getMetadata() ) + " " + dialect.getIdentityColumnSupport().getIdentityColumnString( column.getSqlTypeCode( runtimeModelCreationContext.getMetadata() ) ), @@ -325,8 +319,6 @@ public class TemporaryTable implements Exportable, Contributable { column.getText( dialect ), jdbcMapping, column.getSqlType( - runtimeModelCreationContext.getTypeConfiguration(), - dialect, runtimeModelCreationContext.getMetadata() ), column.getColumnSize( @@ -349,8 +341,6 @@ public class TemporaryTable implements Exportable, Contributable { discriminator.getText( dialect ), discriminatorMapping.getJdbcMapping(), discriminator.getSqlType( - runtimeModelCreationContext.getTypeConfiguration(), - dialect, runtimeModelCreationContext.getMetadata() ), discriminator.getColumnSize( @@ -381,8 +371,6 @@ public class TemporaryTable implements Exportable, Contributable { selectable.getText( dialect ), selection.getJdbcMapping(), column.getSqlType( - runtimeModelCreationContext.getTypeConfiguration(), - dialect, runtimeModelCreationContext.getMetadata() ), column.getColumnSize( diff --git a/hibernate-core/src/main/java/org/hibernate/id/ExportableColumn.java b/hibernate-core/src/main/java/org/hibernate/id/ExportableColumn.java index 05f943051d..8328bc02c1 100644 --- a/hibernate-core/src/main/java/org/hibernate/id/ExportableColumn.java +++ b/hibernate-core/src/main/java/org/hibernate/id/ExportableColumn.java @@ -13,7 +13,6 @@ import java.util.NoSuchElementException; import org.hibernate.FetchMode; import org.hibernate.MappingException; import org.hibernate.boot.model.relational.Database; -import org.hibernate.boot.spi.MetadataBuildingContext; import org.hibernate.engine.spi.Mapping; import org.hibernate.internal.util.collections.ArrayHelper; import org.hibernate.mapping.Column; diff --git a/hibernate-core/src/main/java/org/hibernate/mapping/Column.java b/hibernate-core/src/main/java/org/hibernate/mapping/Column.java index e60752d95c..02eb46de55 100644 --- a/hibernate-core/src/main/java/org/hibernate/mapping/Column.java +++ b/hibernate-core/src/main/java/org/hibernate/mapping/Column.java @@ -9,15 +9,16 @@ package org.hibernate.mapping; import java.io.Serializable; import java.sql.Types; import java.util.Locale; +import java.util.Objects; -import org.hibernate.HibernateException; +import org.hibernate.AssertionFailure; import org.hibernate.MappingException; import org.hibernate.boot.Metadata; import org.hibernate.boot.model.TruthValue; +import org.hibernate.boot.model.relational.Database; import org.hibernate.dialect.Dialect; import org.hibernate.engine.jdbc.Size; import org.hibernate.engine.spi.Mapping; -import org.hibernate.internal.util.StringHelper; import org.hibernate.loader.internal.AliasConstantsHelper; import org.hibernate.metamodel.mapping.JdbcMapping; import org.hibernate.query.sqm.function.SqmFunctionRegistry; @@ -28,11 +29,13 @@ import org.hibernate.type.BasicType; import org.hibernate.type.ComponentType; import org.hibernate.type.EntityType; import org.hibernate.type.Type; -import org.hibernate.type.descriptor.java.JavaType; import org.hibernate.type.descriptor.jdbc.ArrayJdbcType; -import org.hibernate.type.descriptor.jdbc.JdbcType; +import org.hibernate.type.descriptor.sql.spi.DdlTypeRegistry; import org.hibernate.type.spi.TypeConfiguration; +import static org.hibernate.internal.util.StringHelper.isEmpty; +import static org.hibernate.internal.util.StringHelper.lastIndexOfLetter; +import static org.hibernate.internal.util.StringHelper.nullIfEmpty; import static org.hibernate.internal.util.StringHelper.safeInterning; /** @@ -51,7 +54,7 @@ public class Column implements Selectable, Serializable, Cloneable, ColumnTypeIn private String name; private boolean nullable = true; private boolean unique; - private String sqlType; + private String sqlTypeName; private Integer sqlTypeCode; private boolean quoted; int uniqueInteger; @@ -97,10 +100,7 @@ public class Column implements Selectable, Serializable, Cloneable, ColumnTypeIn } public void setName(String name) { - if ( - StringHelper.isNotEmpty( name ) && - Dialect.QUOTE.indexOf( name.charAt( 0 ) ) > -1 //TODO: deprecated, remove eventually - ) { + if ( isQuoted( name ) ) { quoted = true; this.name = name.substring( 1, name.length() - 1 ); } @@ -109,8 +109,24 @@ public class Column implements Selectable, Serializable, Cloneable, ColumnTypeIn } } + private static boolean isQuoted(String name) { + //TODO: deprecated, remove eventually + return name != null + && name.length() >= 2 + && isOpenQuote( name.charAt( 0 ) ) + && isCloseQuote( name.charAt( name.length() - 1 ) ); + } + + private static boolean isOpenQuote(char ch) { + return Dialect.QUOTE.indexOf( ch ) > -1; + } + + private static boolean isCloseQuote(char ch) { + return Dialect.CLOSED_QUOTE.indexOf( ch ) > -1; + } + /** - * returns quoted name as it would be in the mapping file. + * @return the quoted name as it would occur in the mapping file */ public String getQuotedName() { return safeInterning( @@ -120,17 +136,20 @@ public class Column implements Selectable, Serializable, Cloneable, ColumnTypeIn ); } - public String getQuotedName(Dialect d) { + /** + * @return the quoted name using the quoting syntax of the given dialect + */ + public String getQuotedName(Dialect dialect) { return safeInterning( quoted ? - d.openQuote() + name + d.closeQuote() : + dialect.openQuote() + name + dialect.closeQuote() : name ); } @Override public String getAlias(Dialect dialect) { - final int lastLetter = StringHelper.lastIndexOfLetter( name ); + final int lastLetter = lastIndexOfLetter( name ); final String suffix = AliasConstantsHelper.get( uniqueInteger ); String alias = name.toLowerCase( Locale.ROOT ); @@ -142,7 +161,9 @@ public class Column implements Selectable, Serializable, Cloneable, ColumnTypeIn } boolean useRawName = name.length() + suffix.length() <= dialect.getMaxAliasLength() - && !quoted && !name.toLowerCase( Locale.ROOT ).equals( "rowid" ); + && !quoted + // TODO: get the row id name from the Dialect + && !name.equalsIgnoreCase( "rowid" ); if ( !useRawName ) { if ( suffix.length() >= dialect.getMaxAliasLength() ) { throw new MappingException( @@ -164,7 +185,10 @@ public class Column implements Selectable, Serializable, Cloneable, ColumnTypeIn */ @Override public String getAlias(Dialect dialect, Table table) { - return safeInterning( getAlias( dialect ) + AliasConstantsHelper.get( table.getUniqueInteger() ) ); + return safeInterning( + getAlias( dialect ) + + AliasConstantsHelper.get( table.getUniqueInteger() ) + ); } public boolean isNullable() { @@ -190,86 +214,102 @@ public class Column implements Selectable, Serializable, Cloneable, ColumnTypeIn @Override public int hashCode() { //used also for generation of FK names! - return isQuoted() ? - name.hashCode() : - name.toLowerCase( Locale.ROOT ).hashCode(); + return isQuoted() + ? name.hashCode() + : name.toLowerCase( Locale.ROOT ).hashCode(); } @Override public boolean equals(Object object) { - return object instanceof Column && equals( (Column) object ); + return object instanceof Column + && equals( (Column) object ); } public boolean equals(Column column) { - return column != null && ( - this == column || isQuoted() ? name.equals( column.name ) : name.equalsIgnoreCase( column.name ) - ); + return column != null + && ( this == column || isQuoted() + ? name.equals( column.name ) + : name.equalsIgnoreCase( column.name ) ); } public int getSqlTypeCode(Mapping mapping) throws MappingException { if ( sqlTypeCode == null ) { - Type type = getValue().getType(); + final Type type = getValue().getType(); + int[] sqlTypeCodes; try { - int sqlTypeCode = type.getSqlTypeCodes( mapping )[getTypeIndex()]; - if ( getSqlTypeCode() != null && getSqlTypeCode() != sqlTypeCode ) { - throw new MappingException( "SQL type codes do not match, mapped as " + sqlTypeCode + " but is " + getSqlTypeCode() ); - } - return this.sqlTypeCode = sqlTypeCode; + sqlTypeCodes = type.getSqlTypeCodes( mapping ); } - catch (MappingException me) { - throw me; - } - catch (Exception e) { + catch ( Exception cause ) { throw new MappingException( - "Could not determine type for column " + - name + - " of type " + - type.getClass().getName() + - ": " + - e.getClass().getName(), - e + String.format( + Locale.ROOT, + "Unable to resolve JDBC type code for column '%s' of table '%s'", + getName(), + getValue().getTable().getName() + ), + cause ); } + final int index = getTypeIndex(); + if ( index >= sqlTypeCodes.length ) { + throw new MappingException( + String.format( + Locale.ROOT, + "Unable to resolve JDBC type code for column '%s' of table '%s'", + getName(), + getValue().getTable().getName() + ) + ); + } + sqlTypeCode = sqlTypeCodes[index]; } return sqlTypeCode; } - private String getSqlTypeName(TypeConfiguration typeConfiguration, Dialect dialect, Mapping mapping) { - final Type type = getValue().getType(); - if ( type instanceof BasicPluralType && ( (BasicType) type ).getJdbcType() instanceof ArrayJdbcType ) { - final BasicPluralType containerType = (BasicPluralType) type; - final BasicType elementType = containerType.getElementType(); - final int sqlTypeCode; + private String getSqlTypeName(DdlTypeRegistry ddlTypeRegistry, Dialect dialect, Mapping mapping) { + if ( sqlTypeName == null ) { try { - sqlTypeCode = elementType.getJdbcType().getDdlTypeCode(); + final Type type = getValue().getType(); + sqlTypeName = isArray( type ) + ? dialect.getArrayTypeName( getArrayElementTypeName( dialect, ddlTypeRegistry, getArrayElementType( type ) ) ) + : ddlTypeRegistry.getTypeName( getSqlTypeCode( mapping ), getColumnSize( dialect, mapping ) ); } - catch (Exception e) { + catch ( Exception cause ) { throw new MappingException( - "Could not determine type for column " + - name + - " of type " + - type.getClass().getName() + - ": " + - e.getClass().getName(), - e + String.format( + Locale.ROOT, + "Unable to determine SQL type name for column '%s' of table '%s'", + getName(), + getValue().getTable().getName() + ), + cause ); } + } + return sqlTypeName; + } - final String elementTypeName = typeConfiguration.getDdlTypeRegistry().getTypeName( - sqlTypeCode, - dialect.getSizeStrategy().resolveSize( - elementType.getJdbcMapping().getJdbcType(), - elementType.getJavaTypeDescriptor(), - precision, - scale, - length - ) - ); - return dialect.getArrayTypeName( elementTypeName ); - } - else { - return typeConfiguration.getDdlTypeRegistry().getTypeName( getSqlTypeCode( mapping ), getColumnSize( dialect, mapping ) ); - } + private String getArrayElementTypeName(Dialect dialect, DdlTypeRegistry ddlTypeRegistry, BasicType elementType) { + return ddlTypeRegistry.getTypeName( + elementType.getJdbcType().getDdlTypeCode(), + dialect.getSizeStrategy().resolveSize( + elementType.getJdbcMapping().getJdbcType(), + elementType.getJavaTypeDescriptor(), + precision, + scale, + length + ) + ); + } + + private static BasicType getArrayElementType(Type arrayType) { + final BasicPluralType containerType = (BasicPluralType) arrayType; + return containerType.getElementType(); + } + + private static boolean isArray(Type type) { + return type instanceof BasicPluralType + && ((BasicType) type).getJdbcType() instanceof ArrayJdbcType; } /** @@ -279,47 +319,35 @@ public class Column implements Selectable, Serializable, Cloneable, ColumnTypeIn * Use {@link #getSqlTypeCode(Mapping)} to retrieve the type code * using {@link Value} associated with the column. * - * @return sqlTypeCode if it is set, otherwise null. + * @return the type code, if it is set, otherwise null. */ public Integer getSqlTypeCode() { return sqlTypeCode; } public void setSqlTypeCode(Integer typeCode) { + if ( sqlTypeCode != null && !Objects.equals( sqlTypeCode, typeCode ) ) { + throw new AssertionFailure( "conflicting type codes" ); + } sqlTypeCode = typeCode; } - public String getSqlType(Metadata mapping) throws HibernateException { - return getSqlType( mapping.getDatabase().getTypeConfiguration(), mapping.getDatabase().getDialect(), mapping ); + public String getSqlType(Metadata mapping) { + final Database database = mapping.getDatabase(); + return getSqlTypeName( database.getTypeConfiguration().getDdlTypeRegistry(), database.getDialect(), mapping ); } /** * @deprecated use {@link #getSqlType(Metadata)} */ @Deprecated(since = "6.2") - public String getSqlType(TypeConfiguration typeConfiguration, Dialect dialect, Mapping mapping) throws HibernateException { - if ( sqlType == null ) { - try { - sqlType = getSqlTypeName( typeConfiguration, dialect, mapping ); - } - catch (HibernateException cause) { - throw new HibernateException( - String.format( - Locale.ROOT, - "Unable to resolve JDBC type code for column `%s.%s`", - getValue().getTable().getName(), - getName() - ), - cause - ); - } - } - return sqlType; + public String getSqlType(TypeConfiguration typeConfiguration, Dialect dialect, Mapping mapping) { + return getSqlTypeName( typeConfiguration.getDdlTypeRegistry(), dialect, mapping ); } @Override public String getTypeName() { - return sqlType; + return sqlTypeName; } @Override @@ -337,7 +365,9 @@ public class Column implements Selectable, Serializable, Cloneable, ColumnTypeIn if ( length == null ) { return precision == null ? 0 : precision; } - return length.intValue(); + else { + return length.intValue(); + } } @Override @@ -346,46 +376,43 @@ public class Column implements Selectable, Serializable, Cloneable, ColumnTypeIn } public Size getColumnSize(Dialect dialect, Mapping mapping) { - if ( columnSize != null ) { - return columnSize; + if ( columnSize == null ) { + Type type = getValue().getType(); + if ( type instanceof EntityType ) { + type = getTypeForEntityValue( mapping, type, getTypeIndex() ); + } + if ( type instanceof ComponentType ) { + type = getTypeForComponentValue( mapping, type, getTypeIndex() ); + } + if ( type == null ) { + throw new AssertionFailure( "no typing information available to determine column size" ); + } + final JdbcMapping jdbcMapping = (JdbcMapping) type; + columnSize = dialect.getSizeStrategy().resolveSize( + jdbcMapping.getJdbcType(), + jdbcMapping.getJdbcJavaType(), + precision, + scale, + length + ); } - - Type type = getValue().getType(); - if ( type instanceof EntityType ) { - type = getTypeForEntityValue( mapping, type, getTypeIndex() ); - } - if ( type instanceof ComponentType ) { - type = getTypeForComponentValue( mapping, type, getTypeIndex() ); - } - final JdbcMapping jdbcMapping = (JdbcMapping) type; - final JdbcType jdbcType = jdbcMapping.getJdbcType(); - final JavaType javaType = jdbcMapping.getJdbcJavaType(); - columnSize = dialect.getSizeStrategy().resolveSize( - jdbcType, - javaType, - precision, - scale, - length - ); - return columnSize; } private Type getTypeForComponentValue(Mapping mapping, Type type, int typeIndex) { final Type[] subtypes = ( (ComponentType) type ).getSubtypes(); int typeStartIndex = 0; - for ( int i = 0; i <= subtypes.length; i++ ) { - Type subtype = subtypes[i]; - int columnSpan = subtype.getColumnSpan( mapping ); - if ( typeStartIndex + columnSpan > typeIndex ) { - int subtypeIndex = typeIndex - typeStartIndex; - if ( subtype instanceof EntityType ) { - return getTypeForEntityValue( mapping, subtype, subtypeIndex ); + for ( Type subtype : subtypes ) { + final int columnSpan = subtype.getColumnSpan(mapping); + if (typeStartIndex + columnSpan > typeIndex) { + final int subtypeIndex = typeIndex - typeStartIndex; + if (subtype instanceof EntityType) { + return getTypeForEntityValue(mapping, subtype, subtypeIndex); } - if ( subtype instanceof ComponentType ) { - return getTypeForComponentValue( mapping, subtype, subtypeIndex ); + if (subtype instanceof ComponentType) { + return getTypeForComponentValue(mapping, subtype, subtypeIndex); } - if ( subtypeIndex == 0 ) { + if (subtypeIndex == 0) { return subtype; } break; @@ -393,12 +420,12 @@ public class Column implements Selectable, Serializable, Cloneable, ColumnTypeIn typeStartIndex += columnSpan; } - throw new HibernateException( + throw new MappingException( String.format( Locale.ROOT, - "Unable to resolve org.hibernate.type.Type for column `%s.%s`", - getValue().getTable().getName(), - getName() + "Unable to resolve Hibernate type for column '%s' of table '%s'", + getName(), + getValue().getTable().getName() ) ); } @@ -406,12 +433,12 @@ public class Column implements Selectable, Serializable, Cloneable, ColumnTypeIn private Type getTypeForEntityValue(Mapping mapping, Type type, int typeIndex) { int index = 0; if ( type instanceof EntityType ) { - EntityType entityType = (EntityType) type; + final EntityType entityType = (EntityType) type; return getTypeForEntityValue( mapping, entityType.getIdentifierOrUniqueKeyType( mapping ), typeIndex ); } else if ( type instanceof ComponentType ) { for (Type subtype : ((ComponentType) type).getSubtypes() ) { - Type result = getTypeForEntityValue( mapping, subtype, typeIndex - index ); + final Type result = getTypeForEntityValue( mapping, subtype, typeIndex - index ); if ( result != null ) { return result; } @@ -428,11 +455,14 @@ public class Column implements Selectable, Serializable, Cloneable, ColumnTypeIn } public String getSqlType() { - return sqlType; + return sqlTypeName; } - public void setSqlType(String sqlType) { - this.sqlType = sqlType; + public void setSqlType(String typeName) { + if ( sqlTypeName != null && !Objects.equals( sqlTypeName, typeName ) ) { + throw new AssertionFailure( "conflicting type names" ); + } + sqlTypeName = typeName; } public void setUnique(boolean unique) { @@ -473,22 +503,16 @@ public class Column implements Selectable, Serializable, Cloneable, ColumnTypeIn } public String checkConstraint() { - if ( checkConstraint == null ) { - return null; - } - return " check (" + checkConstraint + ")"; + return checkConstraint == null ? null : " check (" + checkConstraint + ")"; } @Override - public String getTemplate( - Dialect dialect, - TypeConfiguration typeConfiguration, - SqmFunctionRegistry functionRegistry) { + public String getTemplate(Dialect dialect, TypeConfiguration typeConfiguration, SqmFunctionRegistry registry) { return safeInterning( hasCustomRead() - // see note in renderTransformerReadFragment wrt access to SessionFactory - ? Template.renderTransformerReadFragment( customRead, getQuotedName( dialect ) ) - : Template.TEMPLATE + '.' + getQuotedName( dialect ) + // see note in renderTransformerReadFragment wrt access to SessionFactory + ? Template.renderTransformerReadFragment( customRead, getQuotedName( dialect ) ) + : Template.TEMPLATE + '.' + getQuotedName( dialect ) ); } @@ -501,7 +525,7 @@ public class Column implements Selectable, Serializable, Cloneable, ColumnTypeIn } public String getWriteExpr() { - return ( customWrite != null && customWrite.length() > 0 ) ? customWrite : "?"; + return customWrite != null && customWrite.length() > 0 ? customWrite : "?"; } @Override @@ -590,12 +614,12 @@ public class Column implements Selectable, Serializable, Cloneable, ColumnTypeIn } public void setResolvedCustomRead(String customRead) { - assert customRead == null || ! StringHelper.isEmpty( customRead.trim() ); + assert customRead == null || ! isEmpty( customRead.trim() ); this.customRead = safeInterning( customRead ); } public void setCustomRead(String customRead) { - this.customRead = safeInterning( StringHelper.nullIfEmpty( customRead ) ); + this.customRead = safeInterning( nullIfEmpty( customRead ) ); } public String getCanonicalName() { @@ -616,7 +640,7 @@ public class Column implements Selectable, Serializable, Cloneable, ColumnTypeIn copy.setNullable( nullable ); copy.setPrecision( precision ); copy.setUnique( unique ); - copy.setSqlType( sqlType ); + copy.setSqlType( sqlTypeName ); copy.setSqlTypeCode( sqlTypeCode ); copy.uniqueInteger = uniqueInteger; //usually useless copy.setCheckConstraint( checkConstraint ); diff --git a/hibernate-core/src/main/java/org/hibernate/mapping/Formula.java b/hibernate-core/src/main/java/org/hibernate/mapping/Formula.java index fea982f7ba..9533982fda 100644 --- a/hibernate-core/src/main/java/org/hibernate/mapping/Formula.java +++ b/hibernate-core/src/main/java/org/hibernate/mapping/Formula.java @@ -41,11 +41,8 @@ public class Formula implements Selectable, Serializable { } @Override - public String getTemplate( - Dialect dialect, - TypeConfiguration typeConfiguration, - SqmFunctionRegistry functionRegistry) { - String template = Template.renderWhereStringTemplate( formula, dialect, typeConfiguration, functionRegistry ); + public String getTemplate(Dialect dialect, TypeConfiguration typeConfiguration, SqmFunctionRegistry registry) { + final String template = Template.renderWhereStringTemplate( formula, dialect, typeConfiguration, registry ); return safeInterning( StringHelper.replace( template, "{alias}", Template.TEMPLATE ) ); } diff --git a/hibernate-core/src/main/java/org/hibernate/mapping/Selectable.java b/hibernate-core/src/main/java/org/hibernate/mapping/Selectable.java index 80dac00654..d8ec6dad37 100644 --- a/hibernate-core/src/main/java/org/hibernate/mapping/Selectable.java +++ b/hibernate-core/src/main/java/org/hibernate/mapping/Selectable.java @@ -61,8 +61,5 @@ public interface Selectable { @Deprecated(since = "6.0") String getAlias(Dialect dialect, Table table); - String getTemplate( - Dialect dialect, - TypeConfiguration typeConfiguration, - SqmFunctionRegistry functionRegistry); + String getTemplate(Dialect dialect, TypeConfiguration typeConfiguration, SqmFunctionRegistry functionRegistry); } diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/function/SelfRenderingFunctionSqlAstExpression.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/function/SelfRenderingFunctionSqlAstExpression.java index 6607861c54..547244fb69 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/function/SelfRenderingFunctionSqlAstExpression.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/function/SelfRenderingFunctionSqlAstExpression.java @@ -22,7 +22,6 @@ import org.hibernate.query.sqm.sql.internal.DomainResultProducer; import org.hibernate.sql.ast.SqlAstTranslator; import org.hibernate.sql.ast.spi.SqlAppender; import org.hibernate.sql.ast.spi.SqlAstCreationState; -import org.hibernate.sql.ast.spi.SqlExpressionResolver; import org.hibernate.sql.ast.spi.SqlSelection; import org.hibernate.sql.ast.tree.SqlAstNode; import org.hibernate.sql.ast.tree.expression.FunctionExpression; @@ -112,13 +111,14 @@ public class SelfRenderingFunctionSqlAstExpression jdbcJavaType = type.getExpressibleJavaType(); converter = null; } + final SqlAstCreationState sqlAstCreationState = creationState.getSqlAstCreationState(); return new BasicResult( - creationState.getSqlAstCreationState().getSqlExpressionResolver() + sqlAstCreationState.getSqlExpressionResolver() .resolveSqlSelection( this, jdbcJavaType, null, - creationState.getSqlAstCreationState().getCreationContext() + sqlAstCreationState.getCreationContext() .getMappingMetamodel().getTypeConfiguration() ) .getValuesArrayPosition(), @@ -152,10 +152,7 @@ public class SelfRenderingFunctionSqlAstExpression } @Override - public String getTemplate( - Dialect dialect, - TypeConfiguration typeConfiguration, - SqmFunctionRegistry functionRegistry) { + public String getTemplate(Dialect dialect, TypeConfiguration typeConfiguration, SqmFunctionRegistry registry) { return null; } @@ -181,33 +178,25 @@ public class SelfRenderingFunctionSqlAstExpression @Override public JdbcMapping getJdbcMapping() { - if ( type instanceof SqlExpressible) { - return ( (SqlExpressible) type ).getJdbcMapping(); - } - else { - return ( (SqlExpressible) expressible).getJdbcMapping(); - } + return type instanceof SqlExpressible + ? ( (SqlExpressible) type ).getJdbcMapping() + : ( (SqlExpressible) expressible ).getJdbcMapping(); } @Override public void applySqlSelections(DomainResultCreationState creationState) { final SqlAstCreationState sqlAstCreationState = creationState.getSqlAstCreationState(); - final SqlExpressionResolver sqlExpressionResolver = sqlAstCreationState.getSqlExpressionResolver(); - final JdbcMapping jdbcMapping = getJdbcMapping(); - final JavaType jdbcJavaType; - if ( jdbcMapping != null ) { - jdbcJavaType = jdbcMapping.getJdbcJavaType(); - } - else { - jdbcJavaType = type.getExpressibleJavaType(); - } - sqlExpressionResolver.resolveSqlSelection( - this, - jdbcJavaType, - null, - sqlAstCreationState.getCreationContext().getMappingMetamodel().getTypeConfiguration() - ); + sqlAstCreationState.getSqlExpressionResolver() + .resolveSqlSelection( + this, + jdbcMapping != null + ? jdbcMapping.getJdbcJavaType() + : type.getExpressibleJavaType(), + null, + sqlAstCreationState.getCreationContext() + .getMappingMetamodel().getTypeConfiguration() + ); } @Override