Skip to content

Commit 20cd322

Browse files
committed
extract a method in EnumJavaType
1 parent c57a90e commit 20cd322

File tree

1 file changed

+18
-20
lines changed

1 file changed

+18
-20
lines changed

hibernate-core/src/main/java/org/hibernate/type/descriptor/java/EnumJavaType.java

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
import java.util.Set;
1010

11-
import org.hibernate.AssertionFailure;
1211
import org.hibernate.boot.model.process.internal.EnumeratedValueConverter;
1312
import org.hibernate.dialect.Dialect;
1413
import org.hibernate.internal.util.collections.CollectionHelper;
@@ -47,38 +46,37 @@ public EnumJavaType(Class<T> type) {
4746
public JdbcType getRecommendedJdbcType(JdbcTypeIndicators context) {
4847
final JdbcTypeRegistry jdbcTypeRegistry = context.getTypeConfiguration().getJdbcTypeRegistry();
4948
final EnumType type = context.getEnumeratedType();
50-
final boolean preferNativeEnumTypesEnabled = context.isPreferNativeEnumTypesEnabled();
51-
int sqlType;
52-
switch ( type == null ? ORDINAL : type ) {
49+
final int sqlType = getSqlType( context, type, jdbcTypeRegistry );
50+
return jdbcTypeRegistry.getDescriptor( sqlType );
51+
}
52+
53+
private int getSqlType(JdbcTypeIndicators context, EnumType type, JdbcTypeRegistry jdbcTypeRegistry) {
54+
final boolean preferNativeEnumTypes = context.isPreferNativeEnumTypesEnabled();
55+
return switch ( type == null ? ORDINAL : type ) {
5356
case ORDINAL:
54-
if ( preferNativeEnumTypesEnabled && jdbcTypeRegistry.hasRegisteredDescriptor( ORDINAL_ENUM ) ) {
55-
sqlType = ORDINAL_ENUM;
57+
if ( preferNativeEnumTypes && jdbcTypeRegistry.hasRegisteredDescriptor( ORDINAL_ENUM ) ) {
58+
yield ORDINAL_ENUM;
5659
}
57-
else if ( preferNativeEnumTypesEnabled && jdbcTypeRegistry.hasRegisteredDescriptor( NAMED_ORDINAL_ENUM ) ) {
58-
sqlType = NAMED_ORDINAL_ENUM;
60+
else if ( preferNativeEnumTypes && jdbcTypeRegistry.hasRegisteredDescriptor( NAMED_ORDINAL_ENUM ) ) {
61+
yield NAMED_ORDINAL_ENUM;
5962
}
6063
else {
61-
sqlType = hasManyValues() ? SMALLINT : TINYINT;
64+
yield hasManyValues() ? SMALLINT : TINYINT;
6265
}
63-
break;
6466
case STRING:
6567
if ( jdbcTypeRegistry.hasRegisteredDescriptor( ENUM ) ) {
66-
sqlType = ENUM;
68+
yield ENUM;
6769
}
68-
else if ( preferNativeEnumTypesEnabled && jdbcTypeRegistry.hasRegisteredDescriptor( NAMED_ENUM ) ) {
69-
sqlType = NAMED_ENUM;
70+
else if ( preferNativeEnumTypes && jdbcTypeRegistry.hasRegisteredDescriptor( NAMED_ENUM ) ) {
71+
yield NAMED_ENUM;
7072
}
7173
else if ( context.getColumnLength() == 1 ) {
72-
sqlType = context.isNationalized() ? NCHAR : CHAR;
74+
yield context.isNationalized() ? NCHAR : CHAR;
7375
}
7476
else {
75-
sqlType = context.isNationalized() ? NVARCHAR : VARCHAR;
77+
yield context.isNationalized() ? NVARCHAR : VARCHAR;
7678
}
77-
break;
78-
default:
79-
throw new AssertionFailure("unknown EnumType");
80-
}
81-
return jdbcTypeRegistry.getDescriptor( sqlType );
79+
};
8280
}
8381

8482
public boolean hasManyValues() {

0 commit comments

Comments
 (0)