clean up of VarcharJdbcType

This commit is contained in:
Gavin 2023-04-27 16:37:06 +02:00
parent aa9bb26498
commit cebef1618d
2 changed files with 13 additions and 30 deletions

View File

@ -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 ) );
}
}

View File

@ -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 <T> JdbcLiteralFormatter<T> getJdbcLiteralFormatter(JavaType<T> 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) {