77import java .util .ArrayList ;
88import java .util .List ;
99import java .util .Locale ;
10- import java .util .concurrent .Callable ;
1110
1211import org .hibernate .AnnotationException ;
1312import org .hibernate .HibernateException ;
7271import org .hibernate .internal .CoreLogging ;
7372import org .hibernate .internal .CoreMessageLogger ;
7473import org .hibernate .internal .log .DeprecationLogger ;
75- import org .hibernate .internal .util .NullnessHelper ;
76- import org .hibernate .internal .util .collections .CollectionHelper ;
7774import org .hibernate .metamodel .CollectionClassification ;
7875import org .hibernate .query .sqm .function .SqmFunctionDescriptor ;
7976import org .hibernate .query .sqm .function .SqmFunctionRegistry ;
8077import org .hibernate .service .ServiceRegistry ;
81- import org .hibernate .service .spi .ServiceException ;
8278import org .hibernate .type .BasicType ;
8379import org .hibernate .type .SqlTypes ;
8480import org .hibernate .type .WrapperArrayHandling ;
9591import static org .hibernate .cfg .AvailableSettings .WRAPPER_ARRAY_HANDLING ;
9692import static org .hibernate .cfg .MappingSettings .XML_FORMAT_MAPPER_LEGACY_FORMAT ;
9793import static org .hibernate .engine .config .spi .StandardConverters .BOOLEAN ;
94+ import static org .hibernate .internal .util .NullnessHelper .coalesceSuppliedValues ;
9895import static org .hibernate .internal .util .StringHelper .nullIfEmpty ;
96+ import static org .hibernate .internal .util .collections .CollectionHelper .isNotEmpty ;
9997
10098/**
10199 * @author Steve Ebersole
@@ -115,16 +113,15 @@ public static StandardServiceRegistry getStandardServiceRegistry(ServiceRegistry
115113 if ( serviceRegistry == null ) {
116114 throw new HibernateException ( "ServiceRegistry passed to MetadataBuilder cannot be null" );
117115 }
118-
119- if ( serviceRegistry instanceof StandardServiceRegistry ) {
120- return (StandardServiceRegistry ) serviceRegistry ;
116+ else if ( serviceRegistry instanceof StandardServiceRegistry standardServiceRegistry ) {
117+ return standardServiceRegistry ;
121118 }
122- else if ( serviceRegistry instanceof BootstrapServiceRegistry ) {
119+ else if ( serviceRegistry instanceof BootstrapServiceRegistry bootstrapServiceRegistry ) {
123120 log .debug (
124121 "ServiceRegistry passed to MetadataBuilder was a BootstrapServiceRegistry; this likely won't end well " +
125122 "if attempt is made to build SessionFactory"
126123 );
127- return new StandardServiceRegistryBuilder ( ( BootstrapServiceRegistry ) serviceRegistry ).build ();
124+ return new StandardServiceRegistryBuilder ( bootstrapServiceRegistry ).build ();
128125 }
129126 else {
130127 throw new HibernateException (
@@ -443,8 +440,9 @@ public MetadataImplementor build() {
443440
444441 final MetadataImplementor bootModel = MetadataBuildingProcess .build ( sources , bootstrapContext , options );
445442
446- if ( CollectionHelper .isNotEmpty ( sources .getHbmXmlBindings () ) ) {
447- final ConfigurationService configurationService = bootstrapContext .getServiceRegistry ().getService ( ConfigurationService .class );
443+ if ( isNotEmpty ( sources .getHbmXmlBindings () ) ) {
444+ final ConfigurationService configurationService =
445+ bootstrapContext .getServiceRegistry ().getService ( ConfigurationService .class );
448446 final boolean transformHbm = configurationService != null
449447 && configurationService .getSetting ( MappingSettings .TRANSFORM_HBM_XML , BOOLEAN ,false );
450448
@@ -750,19 +748,14 @@ else if ( value instanceof AccessType accessType ) {
750748 null
751749 ) );
752750
753- implicitNamingStrategy = strategySelector .resolveDefaultableStrategy (
751+ implicitNamingStrategy = strategySelector .< ImplicitNamingStrategy > resolveDefaultableStrategy (
754752 ImplicitNamingStrategy .class ,
755753 configService .getSettings ().get ( AvailableSettings .IMPLICIT_NAMING_STRATEGY ),
756- new Callable <>() {
757- @ Override
758- public ImplicitNamingStrategy call () {
759- return strategySelector .resolveDefaultableStrategy (
760- ImplicitNamingStrategy .class ,
761- "default" ,
762- ImplicitNamingStrategyJpaCompliantImpl .INSTANCE
763- );
764- }
765- }
754+ () -> strategySelector .resolveDefaultableStrategy (
755+ ImplicitNamingStrategy .class ,
756+ "default" ,
757+ ImplicitNamingStrategyJpaCompliantImpl .INSTANCE
758+ )
766759 );
767760
768761 physicalNamingStrategy = strategySelector .resolveDefaultableStrategy (
@@ -771,19 +764,14 @@ public ImplicitNamingStrategy call() {
771764 PhysicalNamingStrategyStandardImpl .INSTANCE
772765 );
773766
774- columnOrderingStrategy = strategySelector .resolveDefaultableStrategy (
767+ columnOrderingStrategy = strategySelector .< ColumnOrderingStrategy > resolveDefaultableStrategy (
775768 ColumnOrderingStrategy .class ,
776769 configService .getSettings ().get ( AvailableSettings .COLUMN_ORDERING_STRATEGY ),
777- new Callable <>() {
778- @ Override
779- public ColumnOrderingStrategy call () {
780- return strategySelector .resolveDefaultableStrategy (
781- ColumnOrderingStrategy .class ,
782- "default" ,
783- ColumnOrderingStrategyStandard .INSTANCE
784- );
785- }
786- }
770+ () -> strategySelector .resolveDefaultableStrategy (
771+ ColumnOrderingStrategy .class ,
772+ "default" ,
773+ ColumnOrderingStrategyStandard .INSTANCE
774+ )
787775 );
788776
789777 useNationalizedCharacterData = configService .getSetting (
@@ -822,14 +810,7 @@ public TimeZoneStorageStrategy getDefaultTimeZoneStorage() {
822810
823811 @ Override
824812 public TimeZoneSupport getTimeZoneSupport () {
825- try {
826- return serviceRegistry .requireService ( JdbcServices .class )
827- .getDialect ()
828- .getTimeZoneSupport ();
829- }
830- catch ( ServiceException se ) {
831- return TimeZoneSupport .NONE ;
832- }
813+ return getTypeConfiguration ().getCurrentBaseSqlTypeIndicators ().getDialect ().getTimeZoneSupport ();
833814 }
834815
835816 private TimeZoneStorageStrategy toTimeZoneStorageStrategy (TimeZoneSupport timeZoneSupport ) {
@@ -844,20 +825,16 @@ private TimeZoneStorageStrategy toTimeZoneStorageStrategy(TimeZoneSupport timeZo
844825 case NORMALIZE -> TimeZoneStorageStrategy .NORMALIZE ;
845826 case NORMALIZE_UTC -> TimeZoneStorageStrategy .NORMALIZE_UTC ;
846827 case AUTO -> switch (timeZoneSupport ) {
847- case NATIVE ->
848- // if the db has native support for timezones, we use that, not a column
849- TimeZoneStorageStrategy .NATIVE ;
850- case NORMALIZE , NONE ->
851- // otherwise we use a separate column
852- TimeZoneStorageStrategy .COLUMN ;
828+ // if the db has native support for timezones, we use that, not a column
829+ case NATIVE -> TimeZoneStorageStrategy .NATIVE ;
830+ // otherwise we use a separate column
831+ case NORMALIZE , NONE -> TimeZoneStorageStrategy .COLUMN ;
853832 };
854833 case DEFAULT -> switch (timeZoneSupport ) {
855- case NATIVE ->
856- // if the db has native support for timezones, we use that, and don't normalize
857- TimeZoneStorageStrategy .NATIVE ;
858- case NORMALIZE , NONE ->
859- // otherwise we normalize things to UTC
860- TimeZoneStorageStrategy .NORMALIZE_UTC ;
834+ // if the db has native support for timezones, we use that, and don't normalize
835+ case NATIVE -> TimeZoneStorageStrategy .NATIVE ;
836+ // otherwise we normalize things to UTC
837+ case NORMALIZE , NONE -> TimeZoneStorageStrategy .NORMALIZE_UTC ;
861838 };
862839 };
863840 }
@@ -979,9 +956,7 @@ public void apply(JpaOrmXmlPersistenceUnitDefaults jpaOrmXmlPersistenceUnitDefau
979956 }
980957
981958 if ( mappingDefaults .getImplicitSchemaName () == null ) {
982- mappingDefaults .implicitSchemaName = nullIfEmpty (
983- jpaOrmXmlPersistenceUnitDefaults .getDefaultSchemaName ()
984- );
959+ mappingDefaults .implicitSchemaName = nullIfEmpty ( jpaOrmXmlPersistenceUnitDefaults .getDefaultSchemaName () );
985960 }
986961 }
987962
@@ -1017,27 +992,28 @@ private static TimeZoneStorageType resolveTimeZoneStorageStrategy(
1017992 private static WrapperArrayHandling resolveWrapperArrayHandling (
1018993 ConfigurationService configService ,
1019994 StandardServiceRegistry serviceRegistry ) {
1020- final WrapperArrayHandling setting = NullnessHelper . coalesceSuppliedValues (
995+ final WrapperArrayHandling setting = coalesceSuppliedValues (
1021996 () -> configService .getSetting (
1022997 WRAPPER_ARRAY_HANDLING ,
1023998 WrapperArrayHandling ::interpretExternalSettingLeniently
1024999 ),
10251000 () -> resolveFallbackWrapperArrayHandling ( configService )
10261001 );
10271002
1028- if ( setting == WrapperArrayHandling .PICK ) {
1029- final Dialect dialect = serviceRegistry .requireService ( JdbcServices .class ).getDialect ();
1030- if ( dialect .supportsStandardArrays ()
1031- && ( dialect .getPreferredSqlTypeCodeForArray () == SqlTypes .ARRAY
1032- || dialect .getPreferredSqlTypeCodeForArray () == SqlTypes .SQLXML ) ) {
1033- return WrapperArrayHandling .ALLOW ;
1034- }
1035- else {
1036- return WrapperArrayHandling .LEGACY ;
1037- }
1038- }
1003+ final Dialect dialect = serviceRegistry .requireService ( JdbcServices .class ).getDialect ();
1004+ return setting == WrapperArrayHandling .PICK ? pickWrapperArrayHandling ( dialect ) : setting ;
10391005
1040- return setting ;
1006+ }
1007+
1008+ private static WrapperArrayHandling pickWrapperArrayHandling (Dialect dialect ) {
1009+ if ( dialect .supportsStandardArrays ()
1010+ && ( dialect .getPreferredSqlTypeCodeForArray () == SqlTypes .ARRAY
1011+ || dialect .getPreferredSqlTypeCodeForArray () == SqlTypes .SQLXML ) ) {
1012+ return WrapperArrayHandling .ALLOW ;
1013+ }
1014+ else {
1015+ return WrapperArrayHandling .LEGACY ;
1016+ }
10411017 }
10421018
10431019 private static WrapperArrayHandling resolveFallbackWrapperArrayHandling (
0 commit comments