Ensure TypeContributor registered JdbcType has precedence over fallback and preferred types
This commit is contained in:
parent
37ec41d319
commit
c6ecdb78f4
|
@ -391,6 +391,11 @@ public class MetadataBuildingProcess {
|
||||||
// add Dialect contributed types
|
// add Dialect contributed types
|
||||||
final Dialect dialect = options.getServiceRegistry().getService( JdbcServices.class ).getDialect();
|
final Dialect dialect = options.getServiceRegistry().getService( JdbcServices.class ).getDialect();
|
||||||
dialect.contributeTypes( typeContributions, options.getServiceRegistry() );
|
dialect.contributeTypes( typeContributions, options.getServiceRegistry() );
|
||||||
|
// Capture the dialect configured JdbcTypes so that we can detect if a TypeContributor overwrote them,
|
||||||
|
// which has precedence over the fallback and preferred type registrations
|
||||||
|
final JdbcType dialectUuidDescriptor = jdbcTypeRegistry.findDescriptor( SqlTypes.UUID );
|
||||||
|
final JdbcType dialectArrayDescriptor = jdbcTypeRegistry.findDescriptor( SqlTypes.ARRAY );
|
||||||
|
final JdbcType dialectIntervalDescriptor = jdbcTypeRegistry.findDescriptor( SqlTypes.INTERVAL_SECOND );
|
||||||
|
|
||||||
// add TypeContributor contributed types.
|
// add TypeContributor contributed types.
|
||||||
for ( TypeContributor contributor : classLoaderService.loadJavaServices( TypeContributor.class ) ) {
|
for ( TypeContributor contributor : classLoaderService.loadJavaServices( TypeContributor.class ) ) {
|
||||||
|
@ -400,7 +405,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 ) {
|
||||||
adaptToPreferredSqlTypeCode( jdbcTypeRegistry, SqlTypes.UUID, preferredSqlTypeCodeForUuid );
|
adaptToPreferredSqlTypeCode(
|
||||||
|
jdbcTypeRegistry,
|
||||||
|
dialectUuidDescriptor,
|
||||||
|
SqlTypes.UUID,
|
||||||
|
preferredSqlTypeCodeForUuid
|
||||||
|
);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
addFallbackIfNecessary( jdbcTypeRegistry, SqlTypes.UUID, SqlTypes.BINARY );
|
addFallbackIfNecessary( jdbcTypeRegistry, SqlTypes.UUID, SqlTypes.BINARY );
|
||||||
|
@ -408,15 +418,25 @@ public class MetadataBuildingProcess {
|
||||||
|
|
||||||
final int preferredSqlTypeCodeForArray = getPreferredSqlTypeCodeForArray( serviceRegistry );
|
final int preferredSqlTypeCodeForArray = getPreferredSqlTypeCodeForArray( serviceRegistry );
|
||||||
if ( preferredSqlTypeCodeForArray == SqlTypes.ARRAY ) {
|
if ( preferredSqlTypeCodeForArray == SqlTypes.ARRAY ) {
|
||||||
adaptToPreferredSqlTypeCode( jdbcTypeRegistry, null, SqlTypes.ARRAY, SqlTypes.VARBINARY );
|
adaptToPreferredSqlTypeCode( jdbcTypeRegistry, dialectArrayDescriptor, SqlTypes.ARRAY, SqlTypes.VARBINARY );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
adaptToPreferredSqlTypeCode( jdbcTypeRegistry, SqlTypes.ARRAY, preferredSqlTypeCodeForArray );
|
adaptToPreferredSqlTypeCode(
|
||||||
|
jdbcTypeRegistry,
|
||||||
|
dialectArrayDescriptor,
|
||||||
|
SqlTypes.ARRAY,
|
||||||
|
preferredSqlTypeCodeForArray
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
final int preferredSqlTypeCodeForDuration = getPreferredSqlTypeCodeForDuration( serviceRegistry );
|
final int preferredSqlTypeCodeForDuration = getPreferredSqlTypeCodeForDuration( serviceRegistry );
|
||||||
if ( preferredSqlTypeCodeForDuration != SqlTypes.INTERVAL_SECOND ) {
|
if ( preferredSqlTypeCodeForDuration != SqlTypes.INTERVAL_SECOND ) {
|
||||||
adaptToPreferredSqlTypeCode( jdbcTypeRegistry, SqlTypes.INTERVAL_SECOND, preferredSqlTypeCodeForDuration );
|
adaptToPreferredSqlTypeCode(
|
||||||
|
jdbcTypeRegistry,
|
||||||
|
dialectIntervalDescriptor,
|
||||||
|
SqlTypes.INTERVAL_SECOND,
|
||||||
|
preferredSqlTypeCodeForDuration
|
||||||
|
);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
addFallbackIfNecessary( jdbcTypeRegistry, SqlTypes.INTERVAL_SECOND, SqlTypes.NUMERIC );
|
addFallbackIfNecessary( jdbcTypeRegistry, SqlTypes.INTERVAL_SECOND, SqlTypes.NUMERIC );
|
||||||
|
@ -471,18 +491,6 @@ public class MetadataBuildingProcess {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void adaptToPreferredSqlTypeCode(
|
|
||||||
JdbcTypeRegistry jdbcTypeRegistry,
|
|
||||||
int defaultSqlTypeCode,
|
|
||||||
int preferredSqlTypeCode) {
|
|
||||||
adaptToPreferredSqlTypeCode(
|
|
||||||
jdbcTypeRegistry,
|
|
||||||
jdbcTypeRegistry.findDescriptor( defaultSqlTypeCode ),
|
|
||||||
defaultSqlTypeCode,
|
|
||||||
preferredSqlTypeCode
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void adaptToPreferredSqlTypeCode(
|
private static void adaptToPreferredSqlTypeCode(
|
||||||
JdbcTypeRegistry jdbcTypeRegistry,
|
JdbcTypeRegistry jdbcTypeRegistry,
|
||||||
JdbcType dialectUuidDescriptor,
|
JdbcType dialectUuidDescriptor,
|
||||||
|
@ -494,6 +502,7 @@ public class MetadataBuildingProcess {
|
||||||
jdbcTypeRegistry.getDescriptor( preferredSqlTypeCode )
|
jdbcTypeRegistry.getDescriptor( preferredSqlTypeCode )
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
// else warning?
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void adaptToPreferredSqlTypeCodeForInstant(
|
private static void adaptToPreferredSqlTypeCodeForInstant(
|
||||||
|
|
Loading…
Reference in New Issue