From d075093ebfa7de6f5b7fb8c7f8021780e2b3059e Mon Sep 17 00:00:00 2001 From: Gavin Date: Fri, 28 Apr 2023 04:52:18 +0200 Subject: [PATCH] HHH-16125 clean up legacy EnumType --- .../org/hibernate/mapping/BasicValue.java | 13 +- .../org/hibernate/mapping/SimpleValue.java | 14 +- .../internal/JdbcParameterBindingImpl.java | 3 +- .../schema/internal/SchemaCreatorImpl.java | 12 +- .../java/org/hibernate/type/EnumType.java | 334 +++++------------- .../type/internal/UserTypeSqlTypeAdapter.java | 1 - 6 files changed, 101 insertions(+), 276 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/mapping/BasicValue.java b/hibernate-core/src/main/java/org/hibernate/mapping/BasicValue.java index 74cbf070f3..f9d0d109dd 100644 --- a/hibernate-core/src/main/java/org/hibernate/mapping/BasicValue.java +++ b/hibernate-core/src/main/java/org/hibernate/mapping/BasicValue.java @@ -64,6 +64,7 @@ import jakarta.persistence.AttributeConverter; import jakarta.persistence.EnumType; import jakarta.persistence.TemporalType; +import static java.lang.Boolean.parseBoolean; import static org.hibernate.mapping.MappingHelper.injectParameters; /** @@ -370,9 +371,9 @@ public class BasicValue extends SimpleValue implements JdbcTypeIndicators, Resol protected Resolution buildResolution() { Properties typeParameters = getTypeParameters(); - if ( typeParameters != null - && Boolean.parseBoolean( typeParameters.getProperty( DynamicParameterizedType.IS_DYNAMIC ) ) - && typeParameters.get( DynamicParameterizedType.PARAMETER_TYPE ) == null ) { + if (typeParameters != null + && parseBoolean(typeParameters.getProperty(DynamicParameterizedType.IS_DYNAMIC)) + && typeParameters.get(DynamicParameterizedType.PARAMETER_TYPE) == null ) { createParameterImpl(); } if ( explicitTypeName != null ) { @@ -830,10 +831,10 @@ public class BasicValue extends SimpleValue implements JdbcTypeIndicators, Resol } if ( typeInstance instanceof DynamicParameterizedType ) { - if ( Boolean.parseBoolean( properties.getProperty( DynamicParameterizedType.IS_DYNAMIC ) ) ) { - if ( properties.get( DynamicParameterizedType.PARAMETER_TYPE ) == null ) { + if (parseBoolean(properties.getProperty(DynamicParameterizedType.IS_DYNAMIC))) { + if (properties.get(DynamicParameterizedType.PARAMETER_TYPE) == null) { final DynamicParameterizedType.ParameterType parameterType = makeParameterImpl(); - properties.put( DynamicParameterizedType.PARAMETER_TYPE, parameterType ); + properties.put(DynamicParameterizedType.PARAMETER_TYPE, parameterType); } } } diff --git a/hibernate-core/src/main/java/org/hibernate/mapping/SimpleValue.java b/hibernate-core/src/main/java/org/hibernate/mapping/SimpleValue.java index 6da35fe1b7..e8579208d9 100644 --- a/hibernate-core/src/main/java/org/hibernate/mapping/SimpleValue.java +++ b/hibernate-core/src/main/java/org/hibernate/mapping/SimpleValue.java @@ -45,7 +45,6 @@ import org.hibernate.id.factory.spi.CustomIdGeneratorCreationContext; import org.hibernate.internal.CoreLogging; import org.hibernate.internal.CoreMessageLogger; import org.hibernate.internal.util.ReflectHelper; -import org.hibernate.internal.util.collections.ArrayHelper; import org.hibernate.type.descriptor.converter.spi.JpaAttributeConverter; import org.hibernate.resource.beans.spi.ManagedBeanRegistry; import org.hibernate.service.ServiceRegistry; @@ -63,6 +62,7 @@ import org.hibernate.usertype.DynamicParameterizedType; import jakarta.persistence.AttributeConverter; +import static java.lang.Boolean.parseBoolean; import static org.hibernate.boot.model.convert.spi.ConverterDescriptor.TYPE_NAME_PREFIX; import static org.hibernate.id.factory.internal.IdentifierGeneratorUtil.createLegacyIdentifierGenerator; import static org.hibernate.internal.util.collections.ArrayHelper.toBooleanArray; @@ -930,7 +930,7 @@ public abstract class SimpleValue implements KeyValue { final XProperty xProperty = (XProperty) typeParameters.get( DynamicParameterizedType.XPROPERTY ); // todo : not sure this works for handling @MapKeyEnumerated final Annotation[] annotations = xProperty == null - ? null + ? new Annotation[0] : xProperty.getAnnotations(); final ClassLoaderService classLoaderService = getMetadata() @@ -941,13 +941,13 @@ public abstract class SimpleValue implements KeyValue { DynamicParameterizedType.PARAMETER_TYPE, new ParameterTypeImpl( classLoaderService.classForTypeName( - typeParameters.getProperty( DynamicParameterizedType.RETURNED_CLASS ) + typeParameters.getProperty(DynamicParameterizedType.RETURNED_CLASS) ), annotations, table.getCatalog(), table.getSchema(), table.getName(), - Boolean.parseBoolean( typeParameters.getProperty( DynamicParameterizedType.IS_PRIMARY_KEY ) ), + parseBoolean(typeParameters.getProperty(DynamicParameterizedType.IS_PRIMARY_KEY)), columnNames, columnLengths ) @@ -974,7 +974,7 @@ public abstract class SimpleValue implements KeyValue { final XProperty xProperty = (XProperty) typeParameters.get( DynamicParameterizedType.XPROPERTY ); // todo : not sure this works for handling @MapKeyEnumerated final Annotation[] annotations = xProperty == null - ? null + ? new Annotation[0] : xProperty.getAnnotations(); final ClassLoaderService classLoaderService = getMetadata() @@ -983,12 +983,12 @@ public abstract class SimpleValue implements KeyValue { .getService( ClassLoaderService.class ); return new ParameterTypeImpl( - classLoaderService.classForTypeName( typeParameters.getProperty( DynamicParameterizedType.RETURNED_CLASS ) ), + classLoaderService.classForTypeName(typeParameters.getProperty(DynamicParameterizedType.RETURNED_CLASS)), annotations, table.getCatalog(), table.getSchema(), table.getName(), - Boolean.parseBoolean( typeParameters.getProperty( DynamicParameterizedType.IS_PRIMARY_KEY ) ), + parseBoolean(typeParameters.getProperty(DynamicParameterizedType.IS_PRIMARY_KEY)), columnNames, columnLengths ); diff --git a/hibernate-core/src/main/java/org/hibernate/sql/exec/internal/JdbcParameterBindingImpl.java b/hibernate-core/src/main/java/org/hibernate/sql/exec/internal/JdbcParameterBindingImpl.java index 9881d388c3..4d4b3dc361 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/exec/internal/JdbcParameterBindingImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/exec/internal/JdbcParameterBindingImpl.java @@ -20,7 +20,8 @@ public class JdbcParameterBindingImpl implements JdbcParameterBinding { public JdbcParameterBindingImpl(JdbcMapping jdbcMapping, Object bindValue) { assert bindValue == null || jdbcMapping == null || jdbcMapping.getJdbcJavaType().isInstance( bindValue ) - : String.format( Locale.ROOT, "Unexpected value type (expected : %s) : %s (%s)", jdbcMapping.getJdbcJavaType().getJavaTypeClass().getName(), bindValue, bindValue.getClass().getName() ); + : String.format( Locale.ROOT, "Unexpected value type (expected : %s) : %s (%s)", + jdbcMapping.getJdbcJavaType().getJavaTypeClass().getName(), bindValue, bindValue.getClass().getName() ); this.jdbcMapping = jdbcMapping; this.bindValue = bindValue; diff --git a/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/SchemaCreatorImpl.java b/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/SchemaCreatorImpl.java index b4aeb0edb5..fa185dc343 100644 --- a/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/SchemaCreatorImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/SchemaCreatorImpl.java @@ -227,14 +227,14 @@ public class SchemaCreatorImpl implements SchemaCreator { Dialect dialect, Formatter formatter, GenerationTarget... targets) { - final SqlStringGenerationContext context = createSqlStringGenerationContext( options, metadata ); - final Set exportIdentifiers = setOfSize( 50 ); + final SqlStringGenerationContext context = createSqlStringGenerationContext(options, metadata); + final Set exportIdentifiers = setOfSize(50); - createSchemasAndCatalogs( metadata, options, dialect, formatter, context, targets ); - // next, create all UDTs - createUserDefinedTypes( metadata, options, dialect, formatter, context, targets ); + createSchemasAndCatalogs(metadata, options, dialect, formatter, context, targets); // next, create all "before table" auxiliary objects - createAuxiliaryObjectsBeforeTables( metadata, options, dialect, formatter, context, exportIdentifiers, targets ); + createAuxiliaryObjectsBeforeTables(metadata, options, dialect, formatter, context, exportIdentifiers, targets); + // next, create all UDTs + createUserDefinedTypes(metadata, options, dialect, formatter, context, targets); // then, create all schema objects (tables, sequences, constraints, etc) in each schema createSequencesTablesConstraints( metadata, diff --git a/hibernate-core/src/main/java/org/hibernate/type/EnumType.java b/hibernate-core/src/main/java/org/hibernate/type/EnumType.java index 37d369e159..203ea79eea 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/EnumType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/EnumType.java @@ -11,7 +11,6 @@ import java.lang.annotation.Annotation; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; -import java.sql.Types; import java.util.Properties; import jakarta.persistence.Enumerated; import jakarta.persistence.MapKeyEnumerated; @@ -24,13 +23,7 @@ import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.internal.CoreLogging; import org.hibernate.internal.util.ReflectHelper; -import org.hibernate.internal.util.config.ConfigurationHelper; -import org.hibernate.type.descriptor.converter.internal.NamedEnumValueConverter; -import org.hibernate.type.descriptor.converter.internal.OrdinalEnumValueConverter; import org.hibernate.type.descriptor.converter.spi.BasicValueConverter; -import org.hibernate.type.descriptor.converter.spi.EnumValueConverter; -import org.hibernate.type.descriptor.ValueBinder; -import org.hibernate.type.descriptor.ValueExtractor; import org.hibernate.type.descriptor.java.EnumJavaType; import org.hibernate.type.descriptor.java.JavaType; import org.hibernate.type.descriptor.jdbc.JdbcType; @@ -43,6 +36,10 @@ import org.hibernate.usertype.LoggableUserType; import org.jboss.logging.Logger; +import static jakarta.persistence.EnumType.ORDINAL; +import static jakarta.persistence.EnumType.STRING; +import static org.hibernate.internal.util.config.ConfigurationHelper.getBoolean; + /** * Value type mapper for enumerations. * @@ -50,7 +47,7 @@ import org.jboss.logging.Logger; * @author Hardy Ferentschik * @author Steve Ebersole * - * @deprecated Use {@link ConvertedBasicType} instead + * @deprecated Use the built-in support for enums */ @Deprecated(since="6.2", forRemoval=true) public class EnumType> @@ -63,34 +60,14 @@ public class EnumType> private Class enumClass; - private EnumValueConverter enumValueConverter; private JdbcType jdbcType; - private ValueExtractor jdbcValueExtractor; - private ValueBinder jdbcValueBinder; + private EnumJavaType enumJavaType; private TypeConfiguration typeConfiguration; public EnumType() { } - @SuppressWarnings("unchecked") - public EnumType( - Class enumClass, - EnumValueConverter enumValueConverter, - TypeConfiguration typeConfiguration) { - this.enumClass = enumClass; - this.typeConfiguration = typeConfiguration; - - this.enumValueConverter = (EnumValueConverter) enumValueConverter; - this.jdbcType = typeConfiguration.getJdbcTypeRegistry().getDescriptor( enumValueConverter.getJdbcTypeCode() ); - this.jdbcValueExtractor = (ValueExtractor) jdbcType.getExtractor( enumValueConverter.getRelationalJavaType() ); - this.jdbcValueBinder = (ValueBinder) jdbcType.getBinder( enumValueConverter.getRelationalJavaType() ); - } - - public EnumValueConverter getEnumValueConverter() { - return enumValueConverter; - } - @Override public JdbcType getJdbcType(TypeConfiguration typeConfiguration) { return jdbcType; @@ -98,7 +75,7 @@ public class EnumType> @Override public BasicValueConverter getValueConverter() { - return enumValueConverter; + return null; } /** @@ -137,15 +114,49 @@ public class EnumType> // 2) we are not passed a ParameterType - generally this indicates a hbm.xml binding case. final ParameterType reader = (ParameterType) parameters.get( PARAMETER_TYPE ); - // the `reader != null` block handles annotations, while the `else` block handles hbm.xml - if ( reader != null ) { - configureUsingReader( reader ); + if ( parameters.containsKey( ENUM ) ) { + final String enumClassName = (String) parameters.get( ENUM ); + try { + enumClass = ReflectHelper.classForName( enumClassName, this.getClass() ).asSubclass( Enum.class ); + } + catch ( ClassNotFoundException exception ) { + throw new HibernateException("Enum class not found: " + enumClassName, exception); + } + } + else if ( reader != null ) { + enumClass = (Class) reader.getReturnedClass().asSubclass( Enum.class ); } else { - configureUsingParameters( parameters ); + throw new AssertionFailure( "No enum class" ); + } + + final JavaType descriptor = typeConfiguration.getJavaTypeRegistry().getDescriptor( enumClass ); + enumJavaType = (EnumJavaType) descriptor; + + if ( parameters.containsKey( TYPE ) ) { + int jdbcTypeCode = Integer.parseInt( (String) parameters.get( TYPE ) ); + jdbcType = typeConfiguration.getJdbcTypeRegistry().getDescriptor( jdbcTypeCode ); + } + else { + final LocalJdbcTypeIndicators indicators; + final Long columnLength = reader == null ? null : reader.getColumnLengths()[0]; + if ( parameters.containsKey (NAMED ) ) { + indicators = new LocalJdbcTypeIndicators( + // use ORDINAL as default for hbm.xml mappings + getBoolean( NAMED, parameters, false ) ? STRING : ORDINAL, + false, + columnLength + ); + } + else { + indicators = new LocalJdbcTypeIndicators( + getEnumType( reader ), + isNationalized( reader ), + columnLength + ); + } + jdbcType = descriptor.getRecommendedJdbcType( indicators ); } - jdbcValueExtractor = jdbcType.getExtractor( enumValueConverter.getRelationalJavaType() ); - jdbcValueBinder = jdbcType.getBinder( enumValueConverter.getRelationalJavaType() ); if ( LOG.isDebugEnabled() ) { LOG.debugf( @@ -156,74 +167,25 @@ public class EnumType> } } - @SuppressWarnings("unchecked") - private void configureUsingParameters(Properties parameters) { - final String enumClassName = (String) parameters.get( ENUM ); - try { - enumClass = ReflectHelper.classForName( enumClassName, this.getClass() ).asSubclass( Enum.class ); - } - catch ( ClassNotFoundException exception ) { - throw new HibernateException( "Enum class not found: " + enumClassName, exception ); - } - enumValueConverter = (EnumValueConverter) interpretParameters( parameters ); //this typecast is rubbish - jdbcType = typeConfiguration.getJdbcTypeRegistry().getDescriptor( enumValueConverter.getJdbcTypeCode() ); - } - - @SuppressWarnings({"rawtypes","unchecked"}) - private void configureUsingReader(ParameterType reader) { - enumClass = (Class) reader.getReturnedClass().asSubclass( Enum.class ); - final jakarta.persistence.EnumType enumType = getEnumType( reader ); - final JavaType descriptor = typeConfiguration.getJavaTypeRegistry().getDescriptor( enumClass ); - final EnumJavaType enumJavaType = (EnumJavaType) descriptor; - final LocalJdbcTypeIndicators indicators = new LocalJdbcTypeIndicators( enumType, reader ); - final JavaType relationalJavaType = resolveRelationalJavaType( indicators, enumJavaType ); - jdbcType = relationalJavaType.getRecommendedJdbcType( indicators ); - enumValueConverter = isOrdinal( enumType ) - ? new OrdinalEnumValueConverter( enumJavaType, jdbcType, relationalJavaType ) - : new NamedEnumValueConverter( enumJavaType, jdbcType, relationalJavaType ); - } - - private static boolean isOrdinal(jakarta.persistence.EnumType enumType) { - if ( enumType == null ) { - return true; - } - else { - switch ( enumType ) { - case ORDINAL: - return true; - case STRING: - return false; - default: - throw new AssertionFailure( "Unknown EnumType: " + enumType); - } - } - } - - private JavaType resolveRelationalJavaType( - LocalJdbcTypeIndicators indicators, - EnumJavaType enumJavaType) { - return enumJavaType.getRecommendedJdbcType( indicators ) - .getJdbcRecommendedJavaTypeMapping( null, null, typeConfiguration ); - } - private jakarta.persistence.EnumType getEnumType(ParameterType reader) { - if ( reader == null ) { - return null; - } - - if ( reader.isPrimaryKey() ) { - final MapKeyEnumerated enumAnn = getAnnotation( reader.getAnnotationsMethod(), MapKeyEnumerated.class ); + if ( reader != null ) { + if ( reader.isPrimaryKey() ) { + final MapKeyEnumerated enumAnn = getAnnotation( reader.getAnnotationsMethod(), MapKeyEnumerated.class ); + if ( enumAnn != null ) { + return enumAnn.value(); + } + } + final Enumerated enumAnn = getAnnotation( reader.getAnnotationsMethod(), Enumerated.class ); if ( enumAnn != null ) { return enumAnn.value(); } } + return ORDINAL; + } - final Enumerated enumAnn = getAnnotation( reader.getAnnotationsMethod(), Enumerated.class ); - if ( enumAnn != null ) { - return enumAnn.value(); - } - - return null; + private boolean isNationalized(ParameterType reader) { + return typeConfiguration.getCurrentBaseSqlTypeIndicators().isNationalized() + || getAnnotation( reader.getAnnotationsMethod(), Nationalized.class ) != null; } @SuppressWarnings("unchecked") @@ -236,128 +198,10 @@ public class EnumType> return null; } - private EnumValueConverter interpretParameters(Properties parameters) { - JavaType javaType = typeConfiguration.getJavaTypeRegistry().getDescriptor( enumClass ); - final EnumJavaType enumJavaType = (EnumJavaType) javaType; - - // this method should only be called for hbm.xml handling - assert parameters.get( PARAMETER_TYPE ) == null; - - final LocalJdbcTypeIndicators localIndicators = new LocalJdbcTypeIndicators( - // use ORDINAL as default for hbm.xml mappings - jakarta.persistence.EnumType.ORDINAL, - // Is there a reasonable value here? Limits the - // number of enums that can be stored: - // 1 = 10 - // 2 = 100 - // etc - -1L, - null - ); - - if ( parameters.containsKey( NAMED ) ) { - final boolean useNamed = ConfigurationHelper.getBoolean( NAMED, parameters ); - return getConverter( enumJavaType, localIndicators, useNamed ); - } - - if ( parameters.containsKey( TYPE ) ) { - final int type = Integer.decode( (String) parameters.get( TYPE ) ); - return getConverterForType( enumJavaType, localIndicators, type ); - } - final JavaType relationalJavaType = resolveRelationalJavaType( localIndicators, enumJavaType ); - // the fallback - return new OrdinalEnumValueConverter<>( - enumJavaType, - relationalJavaType.getRecommendedJdbcType( localIndicators ), - relationalJavaType - ); - } - - private JavaType getStringType() { - return typeConfiguration.getJavaTypeRegistry().getDescriptor(String.class); - } - - private EnumValueConverter getConverter( - EnumJavaType enumJavaType, - EnumType.LocalJdbcTypeIndicators localIndicators, - boolean useNamed) { - if (useNamed) { - return new NamedEnumValueConverter<>( - enumJavaType, - getStringType().getRecommendedJdbcType( localIndicators ), - getStringType() - ); - } - else { - final JavaType relationalJavaType = resolveRelationalJavaType( localIndicators, enumJavaType ); - return new OrdinalEnumValueConverter<>( - enumJavaType, - relationalJavaType.getRecommendedJdbcType( localIndicators ), - relationalJavaType - ); - } - } - - private EnumValueConverter getConverterForType( - EnumJavaType enumJavaType, - LocalJdbcTypeIndicators localIndicators, - int type) { - if ( isNumericType(type) ) { - final JavaType relationalJavaType = resolveRelationalJavaType( localIndicators, enumJavaType ); - return new OrdinalEnumValueConverter<>( - enumJavaType, - relationalJavaType.getRecommendedJdbcType( localIndicators ), - relationalJavaType - ); - } - else if ( isCharacterType(type) ) { - return new NamedEnumValueConverter<>( - enumJavaType, - getStringType().getRecommendedJdbcType( localIndicators ), - getStringType() - ); - } - else { - throw new HibernateException( - String.format( "Passed JDBC type code [%s] not recognized as numeric nor character", type ) - ); - } - } - - private boolean isCharacterType(int jdbcTypeCode) { - switch ( jdbcTypeCode ) { - case Types.CHAR: - case Types.LONGVARCHAR: - case Types.VARCHAR: { - return true; - } - default: { - return false; - } - } - } - - private boolean isNumericType(int jdbcTypeCode) { - switch ( jdbcTypeCode ) { - case Types.INTEGER: - case Types.NUMERIC: - case Types.SMALLINT: - case Types.TINYINT: - case Types.BIGINT: - case Types.DECIMAL: - case Types.DOUBLE: - case Types.FLOAT: { - return true; - } - default: - return false; - } - } - @Override public int getSqlType() { verifyConfigured(); - return enumValueConverter.getJdbcTypeCode(); + return jdbcType.getJdbcTypeCode(); } @Override @@ -378,19 +222,19 @@ public class EnumType> @Override public T nullSafeGet(ResultSet rs, int position, SharedSessionContractImplementor session, Object owner) throws SQLException { verifyConfigured(); - return enumValueConverter.toDomainValue( jdbcValueExtractor.extract( rs, position, session ) ); + return jdbcType.getExtractor( enumJavaType ).extract( rs, position, session ); } private void verifyConfigured() { - if ( enumValueConverter == null || jdbcValueBinder == null || jdbcValueExtractor == null ) { - throw new AssertionFailure( "EnumType (" + enumClass.getName() + ") not properly, fully configured" ); + if ( enumJavaType == null ) { + throw new AssertionFailure("EnumType (" + enumClass.getName() + ") not properly, fully configured"); } } @Override public void nullSafeSet(PreparedStatement st, T value, int index, SharedSessionContractImplementor session) throws HibernateException, SQLException { verifyConfigured(); - jdbcValueBinder.bind( st, enumValueConverter.toRelationalValue( value ), index, session ); + jdbcType.getBinder( enumJavaType ).bind( st, value, index, session ); } @Override @@ -405,12 +249,12 @@ public class EnumType> @Override public Serializable disassemble(T value) throws HibernateException { - return (Serializable) enumValueConverter.toRelationalValue( value ); + return value; } @Override public T assemble(Serializable cached, Object owner) throws HibernateException { - return enumValueConverter.toDomainValue( cached ); + return (T) cached; } @Override @@ -431,45 +275,43 @@ public class EnumType> @Override public String toSqlLiteral(T value) { verifyConfigured(); - return enumValueConverter.toSqlLiteral( value ); + return isOrdinal() + ? Integer.toString( value.ordinal() ) + : "'" + value.name() + "'"; } @Override public String toString(T value) { verifyConfigured(); - return enumValueConverter.getRelationalJavaType().toString( enumValueConverter.toRelationalValue( value ) ); + return enumJavaType.toName( value ); } @Override public T fromStringValue(CharSequence sequence) { verifyConfigured(); - return enumValueConverter.toDomainValue( enumValueConverter.getRelationalJavaType().fromString( sequence ) ); + return enumJavaType.fromName( sequence.toString() ); } @Override @SuppressWarnings("unchecked") public String toLoggableString(Object value, SessionFactoryImplementor factory) { verifyConfigured(); - return enumValueConverter.getDomainJavaType().toString( (T) value ); + return enumJavaType.toString( (T) value ); } public boolean isOrdinal() { verifyConfigured(); - return enumValueConverter instanceof OrdinalEnumValueConverter; + return jdbcType.isInteger(); } private class LocalJdbcTypeIndicators implements JdbcTypeIndicators { private final jakarta.persistence.EnumType enumType; + private final boolean nationalized; private final Long columnLength; - private final ParameterType reader; - private LocalJdbcTypeIndicators(jakarta.persistence.EnumType enumType, ParameterType reader) { - this( enumType, reader.getColumnLengths()[0], reader ); - } - - private LocalJdbcTypeIndicators(jakarta.persistence.EnumType enumType, Long columnLength, ParameterType reader) { + private LocalJdbcTypeIndicators(jakarta.persistence.EnumType enumType, boolean nationalized, Long columnLength) { this.enumType = enumType; + this.nationalized = nationalized; this.columnLength = columnLength; - this.reader = reader; } @Override @@ -479,32 +321,14 @@ public class EnumType> @Override public jakarta.persistence.EnumType getEnumeratedType() { - if ( enumType != null ) { - return enumType; - } - return typeConfiguration.getCurrentBaseSqlTypeIndicators().getEnumeratedType(); + return enumType != null ? enumType : typeConfiguration.getCurrentBaseSqlTypeIndicators().getEnumeratedType(); } @Override public boolean isNationalized() { - return isNationalized( reader ); + return nationalized; } - private boolean isNationalized(ParameterType reader) { - if ( typeConfiguration.getCurrentBaseSqlTypeIndicators().isNationalized() ) { - return true; - } - - if ( reader != null ) { - for ( Annotation annotation : reader.getAnnotationsMethod() ) { - if ( annotation instanceof Nationalized ) { - return true; - } - } - } - - return false; - } @Override public long getColumnLength() { diff --git a/hibernate-core/src/main/java/org/hibernate/type/internal/UserTypeSqlTypeAdapter.java b/hibernate-core/src/main/java/org/hibernate/type/internal/UserTypeSqlTypeAdapter.java index a9e95e8ceb..9b7aa47bd9 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/internal/UserTypeSqlTypeAdapter.java +++ b/hibernate-core/src/main/java/org/hibernate/type/internal/UserTypeSqlTypeAdapter.java @@ -18,7 +18,6 @@ import org.hibernate.type.descriptor.JdbcExtractingLogging; import org.hibernate.type.descriptor.ValueBinder; import org.hibernate.type.descriptor.ValueExtractor; import org.hibernate.type.descriptor.WrapperOptions; -import org.hibernate.type.descriptor.java.BasicJavaType; import org.hibernate.type.descriptor.java.JavaType; import org.hibernate.type.descriptor.jdbc.JdbcLiteralFormatter; import org.hibernate.type.descriptor.jdbc.JdbcType;