From cebef1618db626e206281ed11bcb24c6231f1f3a Mon Sep 17 00:00:00 2001 From: Gavin Date: Thu, 27 Apr 2023 16:37:06 +0200 Subject: [PATCH] clean up of VarcharJdbcType --- .../type/descriptor/jdbc/CharJdbcType.java | 17 +++--------- .../type/descriptor/jdbc/VarcharJdbcType.java | 26 +++++++------------ 2 files changed, 13 insertions(+), 30 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/jdbc/CharJdbcType.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/jdbc/CharJdbcType.java index de5349bae1..69c163d3c9 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/jdbc/CharJdbcType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/jdbc/CharJdbcType.java @@ -33,24 +33,13 @@ public class CharJdbcType extends VarcharJdbcType { return Types.CHAR; } - @Override - public JdbcType resolveIndicatedType( - JdbcTypeIndicators indicators, - JavaType domainJtd) { - assert domainJtd != null; - - final TypeConfiguration typeConfiguration = indicators.getTypeConfiguration(); - final JdbcTypeRegistry jdbcTypeRegistry = typeConfiguration.getJdbcTypeRegistry(); - - final int jdbcTypeCode; + protected int resolveIndicatedJdbcTypeCode(JdbcTypeIndicators indicators) { if ( indicators.isLob() ) { - jdbcTypeCode = indicators.isNationalized() ? Types.NCLOB : Types.CLOB; + return indicators.isNationalized() ? Types.NCLOB : Types.CLOB; } else { - jdbcTypeCode = indicators.isNationalized() ? Types.NCHAR : Types.CHAR; + return indicators.isNationalized() ? Types.NCHAR : Types.CHAR; } - - return jdbcTypeRegistry.getDescriptor( indicators.resolveJdbcTypeCode( jdbcTypeCode ) ); } } diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/jdbc/VarcharJdbcType.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/jdbc/VarcharJdbcType.java index 32a86cea47..f5e7fe7ade 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/jdbc/VarcharJdbcType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/jdbc/VarcharJdbcType.java @@ -19,7 +19,6 @@ import org.hibernate.type.descriptor.ValueExtractor; import org.hibernate.type.descriptor.WrapperOptions; import org.hibernate.type.descriptor.java.JavaType; import org.hibernate.type.descriptor.jdbc.internal.JdbcLiteralFormatterCharacterData; -import org.hibernate.type.descriptor.jdbc.spi.JdbcTypeRegistry; import org.hibernate.type.spi.TypeConfiguration; /** @@ -53,37 +52,32 @@ public class VarcharJdbcType implements AdjustableJdbcType { Integer length, Integer scale, TypeConfiguration typeConfiguration) { - if ( length != null && length == 1 ) { - return typeConfiguration.getJavaTypeRegistry().getDescriptor( Character.class ); - } - return typeConfiguration.getJavaTypeRegistry().getDescriptor( String.class ); + return typeConfiguration.getJavaTypeRegistry() + .getDescriptor( length != null && length == 1 ? Character.class : String.class ); } @Override public JdbcLiteralFormatter getJdbcLiteralFormatter(JavaType javaType) { - //noinspection unchecked - return new JdbcLiteralFormatterCharacterData( javaType ); + return new JdbcLiteralFormatterCharacterData<>( javaType ); } @Override public JdbcType resolveIndicatedType(JdbcTypeIndicators indicators, JavaType domainJtd) { assert domainJtd != null; + return indicators.getTypeConfiguration().getJdbcTypeRegistry() + .getDescriptor( indicators.resolveJdbcTypeCode( resolveIndicatedJdbcTypeCode( indicators ) ) ); + } - final TypeConfiguration typeConfiguration = indicators.getTypeConfiguration(); - final JdbcTypeRegistry jdbcTypeRegistry = typeConfiguration.getJdbcTypeRegistry(); - - final int jdbcTypeCode; + protected int resolveIndicatedJdbcTypeCode(JdbcTypeIndicators indicators) { if ( indicators.isLob() ) { - jdbcTypeCode = indicators.isNationalized() ? Types.NCLOB : Types.CLOB; + return indicators.isNationalized() ? Types.NCLOB : Types.CLOB; } else if ( shouldUseMaterializedLob( indicators ) ) { - jdbcTypeCode = indicators.isNationalized() ? SqlTypes.MATERIALIZED_NCLOB : SqlTypes.MATERIALIZED_CLOB; + return indicators.isNationalized() ? SqlTypes.MATERIALIZED_NCLOB : SqlTypes.MATERIALIZED_CLOB; } else { - jdbcTypeCode = indicators.isNationalized() ? Types.NVARCHAR : Types.VARCHAR; + return indicators.isNationalized() ? Types.NVARCHAR : Types.VARCHAR; } - - return jdbcTypeRegistry.getDescriptor( indicators.resolveJdbcTypeCode( jdbcTypeCode ) ); } protected boolean shouldUseMaterializedLob(JdbcTypeIndicators indicators) {