|
8 | 8 |
|
9 | 9 | import java.util.Set;
|
10 | 10 |
|
11 |
| -import org.hibernate.AssertionFailure; |
12 | 11 | import org.hibernate.boot.model.process.internal.EnumeratedValueConverter;
|
13 | 12 | import org.hibernate.dialect.Dialect;
|
14 | 13 | import org.hibernate.internal.util.collections.CollectionHelper;
|
@@ -47,38 +46,37 @@ public EnumJavaType(Class<T> type) {
|
47 | 46 | public JdbcType getRecommendedJdbcType(JdbcTypeIndicators context) {
|
48 | 47 | final JdbcTypeRegistry jdbcTypeRegistry = context.getTypeConfiguration().getJdbcTypeRegistry();
|
49 | 48 | 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 ) { |
53 | 56 | case ORDINAL:
|
54 |
| - if ( preferNativeEnumTypesEnabled && jdbcTypeRegistry.hasRegisteredDescriptor( ORDINAL_ENUM ) ) { |
55 |
| - sqlType = ORDINAL_ENUM; |
| 57 | + if ( preferNativeEnumTypes && jdbcTypeRegistry.hasRegisteredDescriptor( ORDINAL_ENUM ) ) { |
| 58 | + yield ORDINAL_ENUM; |
56 | 59 | }
|
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; |
59 | 62 | }
|
60 | 63 | else {
|
61 |
| - sqlType = hasManyValues() ? SMALLINT : TINYINT; |
| 64 | + yield hasManyValues() ? SMALLINT : TINYINT; |
62 | 65 | }
|
63 |
| - break; |
64 | 66 | case STRING:
|
65 | 67 | if ( jdbcTypeRegistry.hasRegisteredDescriptor( ENUM ) ) {
|
66 |
| - sqlType = ENUM; |
| 68 | + yield ENUM; |
67 | 69 | }
|
68 |
| - else if ( preferNativeEnumTypesEnabled && jdbcTypeRegistry.hasRegisteredDescriptor( NAMED_ENUM ) ) { |
69 |
| - sqlType = NAMED_ENUM; |
| 70 | + else if ( preferNativeEnumTypes && jdbcTypeRegistry.hasRegisteredDescriptor( NAMED_ENUM ) ) { |
| 71 | + yield NAMED_ENUM; |
70 | 72 | }
|
71 | 73 | else if ( context.getColumnLength() == 1 ) {
|
72 |
| - sqlType = context.isNationalized() ? NCHAR : CHAR; |
| 74 | + yield context.isNationalized() ? NCHAR : CHAR; |
73 | 75 | }
|
74 | 76 | else {
|
75 |
| - sqlType = context.isNationalized() ? NVARCHAR : VARCHAR; |
| 77 | + yield context.isNationalized() ? NVARCHAR : VARCHAR; |
76 | 78 | }
|
77 |
| - break; |
78 |
| - default: |
79 |
| - throw new AssertionFailure("unknown EnumType"); |
80 |
| - } |
81 |
| - return jdbcTypeRegistry.getDescriptor( sqlType ); |
| 79 | + }; |
82 | 80 | }
|
83 | 81 |
|
84 | 82 | public boolean hasManyValues() {
|
|
0 commit comments