HHH-16591 - Replace thrre methods adaptToPreferredSqlTypeCodeForXXX with single adaptToPreferredSqlTypeCode

This commit is contained in:
Cedomir Igaly 2023-05-31 09:53:09 +02:00 committed by Christian Beikov
parent 3f7e880f73
commit 93f1ed6e76
1 changed files with 30 additions and 53 deletions

View File

@ -14,6 +14,7 @@ import java.time.OffsetDateTime;
import java.time.OffsetTime; import java.time.OffsetTime;
import java.time.ZonedDateTime; import java.time.ZonedDateTime;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
@ -639,10 +640,12 @@ public class MetadataBuildingProcess {
// add fallback type descriptors // add fallback type descriptors
final int preferredSqlTypeCodeForUuid = getPreferredSqlTypeCodeForUuid( serviceRegistry ); final int preferredSqlTypeCodeForUuid = getPreferredSqlTypeCodeForUuid( serviceRegistry );
if ( preferredSqlTypeCodeForUuid != SqlTypes.UUID ) { if ( preferredSqlTypeCodeForUuid != SqlTypes.UUID ) {
adaptToPreferredSqlTypeCodeForUuid( adaptToPreferredSqlTypeCode(
typeConfiguration, typeConfiguration,
jdbcTypeRegistry, jdbcTypeRegistry,
preferredSqlTypeCodeForUuid preferredSqlTypeCodeForUuid,
UUID.class,
"uuid"
); );
} }
else { else {
@ -664,10 +667,12 @@ public class MetadataBuildingProcess {
final int preferredSqlTypeCodeForDuration = getPreferredSqlTypeCodeForDuration( serviceRegistry ); final int preferredSqlTypeCodeForDuration = getPreferredSqlTypeCodeForDuration( serviceRegistry );
if ( preferredSqlTypeCodeForDuration != SqlTypes.INTERVAL_SECOND ) { if ( preferredSqlTypeCodeForDuration != SqlTypes.INTERVAL_SECOND ) {
adaptToPreferredSqlTypeCodeForDuration( adaptToPreferredSqlTypeCode(
typeConfiguration, typeConfiguration,
jdbcTypeRegistry, jdbcTypeRegistry,
preferredSqlTypeCodeForDuration preferredSqlTypeCodeForDuration,
Duration.class,
"duration"
); );
} }
else { else {
@ -712,7 +717,14 @@ public class MetadataBuildingProcess {
} }
final int preferredSqlTypeCodeForInstant = getPreferredSqlTypeCodeForInstant( serviceRegistry ); final int preferredSqlTypeCodeForInstant = getPreferredSqlTypeCodeForInstant( serviceRegistry );
if ( preferredSqlTypeCodeForInstant != SqlTypes.TIMESTAMP_UTC ) { if ( preferredSqlTypeCodeForInstant != SqlTypes.TIMESTAMP_UTC ) {
adaptToPreferredSqlTypeCodeForInstant( typeConfiguration, jdbcTypeRegistry, preferredSqlTypeCodeForInstant ); adaptToPreferredSqlTypeCode(
typeConfiguration,
jdbcTypeRegistry,
preferredSqlTypeCodeForInstant,
Instant.class,
"instant",
"org.hibernate.type.InstantType"
);
} }
} }
@ -730,59 +742,24 @@ public class MetadataBuildingProcess {
// else warning? // else warning?
} }
private static void adaptToPreferredSqlTypeCodeForUuid( private static void adaptToPreferredSqlTypeCode(
TypeConfiguration typeConfiguration, TypeConfiguration typeConfiguration,
JdbcTypeRegistry jdbcTypeRegistry, JdbcTypeRegistry jdbcTypeRegistry,
int preferredSqlTypeCodeForUuid) { int preferredSqlTypeCode,
Class<?> javaType,
String name,
String... additionalKeys) {
final JavaTypeRegistry javaTypeRegistry = typeConfiguration.getJavaTypeRegistry(); final JavaTypeRegistry javaTypeRegistry = typeConfiguration.getJavaTypeRegistry();
final BasicTypeRegistry basicTypeRegistry = typeConfiguration.getBasicTypeRegistry(); final BasicTypeRegistry basicTypeRegistry = typeConfiguration.getBasicTypeRegistry();
final BasicType<?> uuidType = new NamedBasicTypeImpl<>( final BasicType<?> basicType = new NamedBasicTypeImpl<>(
javaTypeRegistry.getDescriptor( UUID.class ), javaTypeRegistry.getDescriptor( javaType ),
jdbcTypeRegistry.getDescriptor( preferredSqlTypeCodeForUuid ), jdbcTypeRegistry.getDescriptor( preferredSqlTypeCode ),
"uuid" name
);
basicTypeRegistry.register(
uuidType,
UUID.class.getSimpleName(),
UUID.class.getName()
);
}
private static void adaptToPreferredSqlTypeCodeForDuration(
TypeConfiguration typeConfiguration,
JdbcTypeRegistry jdbcTypeRegistry,
int preferredSqlTypeCodeForDuration) {
final JavaTypeRegistry javaTypeRegistry = typeConfiguration.getJavaTypeRegistry();
final BasicTypeRegistry basicTypeRegistry = typeConfiguration.getBasicTypeRegistry();
final BasicType<?> durationType = new NamedBasicTypeImpl<>(
javaTypeRegistry.getDescriptor( Duration.class ),
jdbcTypeRegistry.getDescriptor( preferredSqlTypeCodeForDuration ),
"duration"
);
basicTypeRegistry.register(
durationType,
Duration.class.getSimpleName(),
Duration.class.getName()
);
}
private static void adaptToPreferredSqlTypeCodeForInstant(
TypeConfiguration typeConfiguration,
JdbcTypeRegistry jdbcTypeRegistry,
int preferredSqlTypeCodeForInstant) {
final JavaTypeRegistry javaTypeRegistry = typeConfiguration.getJavaTypeRegistry();
final BasicTypeRegistry basicTypeRegistry = typeConfiguration.getBasicTypeRegistry();
final BasicType<?> instantType = new NamedBasicTypeImpl<>(
javaTypeRegistry.getDescriptor( Instant.class ),
jdbcTypeRegistry.getDescriptor( preferredSqlTypeCodeForInstant ),
"instant"
);
basicTypeRegistry.register(
instantType,
"org.hibernate.type.InstantType",
Instant.class.getSimpleName(),
Instant.class.getName()
); );
final String[] keys = Arrays.copyOf( additionalKeys, additionalKeys.length + 2 );
keys[additionalKeys.length] = javaType.getSimpleName();
keys[additionalKeys.length + 1] = javaType.getName();
basicTypeRegistry.register( basicType, keys );
} }
private static void adaptTimeTypesToDefaultTimeZoneStorage( private static void adaptTimeTypesToDefaultTimeZoneStorage(