|
|
|
@ -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<T extends Enum<T>>
|
|
|
|
@ -63,34 +60,14 @@ public class EnumType<T extends Enum<T>>
|
|
|
|
|
|
|
|
|
|
private Class<T> enumClass;
|
|
|
|
|
|
|
|
|
|
private EnumValueConverter<T, Object> enumValueConverter;
|
|
|
|
|
private JdbcType jdbcType;
|
|
|
|
|
private ValueExtractor<Object> jdbcValueExtractor;
|
|
|
|
|
private ValueBinder<Object> jdbcValueBinder;
|
|
|
|
|
private EnumJavaType<T> enumJavaType;
|
|
|
|
|
|
|
|
|
|
private TypeConfiguration typeConfiguration;
|
|
|
|
|
|
|
|
|
|
public EnumType() {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
|
public EnumType(
|
|
|
|
|
Class<T> enumClass,
|
|
|
|
|
EnumValueConverter<T,?> enumValueConverter,
|
|
|
|
|
TypeConfiguration typeConfiguration) {
|
|
|
|
|
this.enumClass = enumClass;
|
|
|
|
|
this.typeConfiguration = typeConfiguration;
|
|
|
|
|
|
|
|
|
|
this.enumValueConverter = (EnumValueConverter<T,Object>) enumValueConverter;
|
|
|
|
|
this.jdbcType = typeConfiguration.getJdbcTypeRegistry().getDescriptor( enumValueConverter.getJdbcTypeCode() );
|
|
|
|
|
this.jdbcValueExtractor = (ValueExtractor<Object>) jdbcType.getExtractor( enumValueConverter.getRelationalJavaType() );
|
|
|
|
|
this.jdbcValueBinder = (ValueBinder<Object>) jdbcType.getBinder( enumValueConverter.getRelationalJavaType() );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public EnumValueConverter<T, ?> getEnumValueConverter() {
|
|
|
|
|
return enumValueConverter;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public JdbcType getJdbcType(TypeConfiguration typeConfiguration) {
|
|
|
|
|
return jdbcType;
|
|
|
|
@ -98,7 +75,7 @@ public class EnumType<T extends Enum<T>>
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public BasicValueConverter<T, Object> getValueConverter() {
|
|
|
|
|
return enumValueConverter;
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -137,15 +114,49 @@ public class EnumType<T extends Enum<T>>
|
|
|
|
|
// 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<T>) reader.getReturnedClass().asSubclass( Enum.class );
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
configureUsingParameters( parameters );
|
|
|
|
|
throw new AssertionFailure( "No enum class" );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
final JavaType<T> descriptor = typeConfiguration.getJavaTypeRegistry().getDescriptor( enumClass );
|
|
|
|
|
enumJavaType = (EnumJavaType<T>) 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<T extends Enum<T>>
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@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<T,Object>) interpretParameters( parameters ); //this typecast is rubbish
|
|
|
|
|
jdbcType = typeConfiguration.getJdbcTypeRegistry().getDescriptor( enumValueConverter.getJdbcTypeCode() );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@SuppressWarnings({"rawtypes","unchecked"})
|
|
|
|
|
private void configureUsingReader(ParameterType reader) {
|
|
|
|
|
enumClass = (Class<T>) reader.getReturnedClass().asSubclass( Enum.class );
|
|
|
|
|
final jakarta.persistence.EnumType enumType = getEnumType( reader );
|
|
|
|
|
final JavaType<T> descriptor = typeConfiguration.getJavaTypeRegistry().getDescriptor( enumClass );
|
|
|
|
|
final EnumJavaType<T> enumJavaType = (EnumJavaType<T>) 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<? extends Number> 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<T extends Enum<T>>
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private EnumValueConverter<T,?> interpretParameters(Properties parameters) {
|
|
|
|
|
JavaType<T> javaType = typeConfiguration.getJavaTypeRegistry().getDescriptor( enumClass );
|
|
|
|
|
final EnumJavaType<T> enumJavaType = (EnumJavaType<T>) 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<? extends Number> relationalJavaType = resolveRelationalJavaType( localIndicators, enumJavaType );
|
|
|
|
|
// the fallback
|
|
|
|
|
return new OrdinalEnumValueConverter<>(
|
|
|
|
|
enumJavaType,
|
|
|
|
|
relationalJavaType.getRecommendedJdbcType( localIndicators ),
|
|
|
|
|
relationalJavaType
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private JavaType<String> getStringType() {
|
|
|
|
|
return typeConfiguration.getJavaTypeRegistry().getDescriptor(String.class);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private EnumValueConverter<T,?> getConverter(
|
|
|
|
|
EnumJavaType<T> enumJavaType,
|
|
|
|
|
EnumType<T>.LocalJdbcTypeIndicators localIndicators,
|
|
|
|
|
boolean useNamed) {
|
|
|
|
|
if (useNamed) {
|
|
|
|
|
return new NamedEnumValueConverter<>(
|
|
|
|
|
enumJavaType,
|
|
|
|
|
getStringType().getRecommendedJdbcType( localIndicators ),
|
|
|
|
|
getStringType()
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
final JavaType<? extends Number> relationalJavaType = resolveRelationalJavaType( localIndicators, enumJavaType );
|
|
|
|
|
return new OrdinalEnumValueConverter<>(
|
|
|
|
|
enumJavaType,
|
|
|
|
|
relationalJavaType.getRecommendedJdbcType( localIndicators ),
|
|
|
|
|
relationalJavaType
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private EnumValueConverter<T,?> getConverterForType(
|
|
|
|
|
EnumJavaType<T> enumJavaType,
|
|
|
|
|
LocalJdbcTypeIndicators localIndicators,
|
|
|
|
|
int type) {
|
|
|
|
|
if ( isNumericType(type) ) {
|
|
|
|
|
final JavaType<? extends Number> 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<T extends Enum<T>>
|
|
|
|
|
@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<T extends Enum<T>>
|
|
|
|
|
|
|
|
|
|
@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<T extends Enum<T>>
|
|
|
|
|
@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<T extends Enum<T>>
|
|
|
|
|
|
|
|
|
|
@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() {
|
|
|
|
|