55package org .hibernate .internal .util .config ;
66
77import java .util .HashMap ;
8- import java .util .Iterator ;
98import java .util .Locale ;
109import java .util .Map ;
1110import java .util .Properties ;
1413
1514import org .checkerframework .checker .nullness .qual .NonNull ;
1615import org .hibernate .Incubating ;
17- import org .hibernate .boot .registry .StandardServiceRegistry ;
18- import org .hibernate .cfg .AvailableSettings ;
16+ import org .hibernate .cfg .MappingSettings ;
1917import org .hibernate .dialect .Dialect ;
2018import org .hibernate .engine .config .spi .ConfigurationService ;
2119import org .hibernate .engine .jdbc .spi .JdbcServices ;
@@ -186,10 +184,10 @@ public static int getInt(String name, Map<?,?> values, int defaultValue) {
186184 if ( value == null ) {
187185 return defaultValue ;
188186 }
189- if (value instanceof Integer integer ) {
187+ else if (value instanceof Integer integer ) {
190188 return integer ;
191189 }
192- if (value instanceof String string ) {
190+ else if (value instanceof String string ) {
193191 return Integer .parseInt (string );
194192 }
195193 throw new ConfigurationException (
@@ -344,6 +342,10 @@ public static String extractPropertyValue(String propertyName, Map<?,?> properti
344342 return value ;
345343 }
346344
345+ /**
346+ * @deprecated No longer used
347+ */
348+ @ Deprecated (since = "7.2" , forRemoval = true )
347349 public static String extractValue (
348350 String name ,
349351 Map <?,?> values ,
@@ -374,10 +376,10 @@ public static String extractValue(
374376 @ SuppressWarnings ("rawtypes" )
375377 @ Deprecated (since = "7" , forRemoval = true )
376378 public static Map toMap (String propertyName , String delim , Properties properties ) {
377- Map <String ,String > map = new HashMap <>();
378- String value = extractPropertyValue ( propertyName , properties );
379+ final Map <String ,String > map = new HashMap <>();
380+ final String value = extractPropertyValue ( propertyName , properties );
379381 if ( value != null ) {
380- StringTokenizer tokens = new StringTokenizer ( value , delim );
382+ final var tokens = new StringTokenizer ( value , delim );
381383 while ( tokens .hasMoreTokens () ) {
382384 map .put ( tokens .nextToken (), tokens .hasMoreElements () ? tokens .nextToken () : "" );
383385 }
@@ -403,10 +405,10 @@ public static Map toMap(String propertyName, String delim, Properties properties
403405 @ SuppressWarnings ("rawtypes" )
404406 @ Deprecated (since = "7" , forRemoval = true )
405407 public static Map toMap (String propertyName , String delim , Map <?,?> properties ) {
406- Map <String ,String > map = new HashMap <>();
407- String value = extractPropertyValue ( propertyName , properties );
408+ final Map <String ,String > map = new HashMap <>();
409+ final String value = extractPropertyValue ( propertyName , properties );
408410 if ( value != null ) {
409- StringTokenizer tokens = new StringTokenizer ( value , delim );
411+ final var tokens = new StringTokenizer ( value , delim );
410412 while ( tokens .hasMoreTokens () ) {
411413 map .put ( tokens .nextToken (), tokens .hasMoreElements () ? tokens .nextToken () : "" );
412414 }
@@ -440,12 +442,9 @@ public static String[] toStringArray(String propertyName, String delim, Properti
440442 */
441443 public static String [] toStringArray (String stringForm , String delim ) {
442444 // todo : move to StringHelper?
443- if ( stringForm != null ) {
444- return StringHelper .split ( delim , stringForm );
445- }
446- else {
447- return ArrayHelper .EMPTY_STRING_ARRAY ;
448- }
445+ return stringForm != null
446+ ? StringHelper .split ( delim , stringForm )
447+ : ArrayHelper .EMPTY_STRING_ARRAY ;
449448 }
450449
451450 /**
@@ -454,13 +453,12 @@ public static String[] toStringArray(String stringForm, String delim) {
454453 * @param configurationValues The configuration map.
455454 */
456455 public static void resolvePlaceHolders (Map <?,Object > configurationValues ) {
457- final Iterator <? extends Map . Entry <?, Object >> itr = configurationValues .entrySet ().iterator ();
456+ final var itr = configurationValues .entrySet ().iterator ();
458457 while ( itr .hasNext () ) {
459- final Map .Entry <?,Object > entry = itr .next ();
460- final Object value = entry .getValue ();
461- if ( value instanceof String string ) {
458+ final var entry = itr .next ();
459+ if ( entry .getValue () instanceof String string ) {
462460 final String resolved = resolvePlaceHolder ( string );
463- if ( !value .equals ( resolved ) ) {
461+ if ( !string .equals ( resolved ) ) {
464462 if ( resolved == null ) {
465463 itr .remove ();
466464 }
@@ -482,8 +480,8 @@ public static String resolvePlaceHolder(String property) {
482480 if ( !property .contains ( PLACEHOLDER_START ) ) {
483481 return property ;
484482 }
485- StringBuilder buff = new StringBuilder ();
486- char [] chars = property .toCharArray ();
483+ final var result = new StringBuilder ();
484+ final char [] chars = property .toCharArray ();
487485 for ( int pos = 0 ; pos < chars .length ; pos ++ ) {
488486 if ( chars [pos ] == '$' ) {
489487 // peek ahead
@@ -500,18 +498,17 @@ public static String resolvePlaceHolder(String property) {
500498 }
501499 }
502500 final String systemProperty = extractFromSystem ( systemPropertyName );
503- buff .append ( systemProperty == null ? "" : systemProperty );
501+ result .append ( systemProperty == null ? "" : systemProperty );
504502 pos = x + 1 ;
505503 // make sure spinning forward did not put us past the end of the buffer...
506504 if ( pos >= chars .length ) {
507505 break ;
508506 }
509507 }
510508 }
511- buff .append ( chars [pos ] );
509+ result .append ( chars [pos ] );
512510 }
513- final String result = buff .toString ();
514- return result .isEmpty () ? null : result ;
511+ return result .isEmpty () ? null : result .toString ();
515512 }
516513
517514 private static String extractFromSystem (String systemPropertyName ) {
@@ -523,96 +520,65 @@ private static String extractFromSystem(String systemPropertyName) {
523520 }
524521 }
525522
526- @ Incubating
527- public static synchronized int getPreferredSqlTypeCodeForBoolean (StandardServiceRegistry serviceRegistry ) {
528- final Integer typeCode = serviceRegistry .requireService ( ConfigurationService .class ).getSetting (
529- AvailableSettings .PREFERRED_BOOLEAN_JDBC_TYPE ,
530- TypeCodeConverter .INSTANCE
531- );
523+ private static Integer getConfiguredTypeCode (ServiceRegistry serviceRegistry , String setting ) {
524+ final Integer typeCode =
525+ serviceRegistry .requireService ( ConfigurationService .class )
526+ .getSetting ( setting , TypeCodeConverter .INSTANCE );
532527 if ( typeCode != null ) {
533- INCUBATION_LOGGER .incubatingSetting ( AvailableSettings .PREFERRED_BOOLEAN_JDBC_TYPE );
534- return typeCode ;
528+ INCUBATION_LOGGER .incubatingSetting ( setting );
535529 }
530+ return typeCode ;
531+ }
536532
537- // default to the Dialect answer
538- return serviceRegistry .requireService ( JdbcServices .class )
539- .getJdbcEnvironment ()
540- .getDialect ()
541- .getPreferredSqlTypeCodeForBoolean ();
533+ @ Incubating
534+ public static synchronized int getPreferredSqlTypeCodeForBoolean (ServiceRegistry serviceRegistry ) {
535+ final Integer typeCode =
536+ getConfiguredTypeCode ( serviceRegistry , MappingSettings .PREFERRED_BOOLEAN_JDBC_TYPE );
537+ return typeCode != null
538+ ? typeCode
539+ : serviceRegistry .requireService ( JdbcServices .class )
540+ .getDialect ().getPreferredSqlTypeCodeForBoolean ();
542541 }
543542
544543 @ Incubating
545544 public static synchronized int getPreferredSqlTypeCodeForBoolean (ServiceRegistry serviceRegistry , Dialect dialect ) {
546- final Integer typeCode = serviceRegistry .requireService ( ConfigurationService .class ).getSetting (
547- AvailableSettings .PREFERRED_BOOLEAN_JDBC_TYPE ,
548- TypeCodeConverter .INSTANCE
549- );
550- if ( typeCode != null ) {
551- INCUBATION_LOGGER .incubatingSetting ( AvailableSettings .PREFERRED_BOOLEAN_JDBC_TYPE );
552- return typeCode ;
553- }
554-
555- // default to the Dialect answer
556- return dialect .getPreferredSqlTypeCodeForBoolean ();
545+ final Integer typeCode =
546+ getConfiguredTypeCode ( serviceRegistry , MappingSettings .PREFERRED_BOOLEAN_JDBC_TYPE );
547+ return typeCode != null ? typeCode : dialect .getPreferredSqlTypeCodeForBoolean ();
557548 }
558549
559550 @ Incubating
560- public static synchronized int getPreferredSqlTypeCodeForDuration (StandardServiceRegistry serviceRegistry ) {
561- final Integer explicitSetting = serviceRegistry .requireService ( ConfigurationService .class ).getSetting (
562- AvailableSettings .PREFERRED_DURATION_JDBC_TYPE ,
563- TypeCodeConverter .INSTANCE
564- );
565- if ( explicitSetting != null ) {
566- INCUBATION_LOGGER .incubatingSetting ( AvailableSettings .PREFERRED_DURATION_JDBC_TYPE );
567- return explicitSetting ;
568- }
551+ public static synchronized int getPreferredSqlTypeCodeForDuration (ServiceRegistry serviceRegistry ) {
552+ final Integer explicitSetting =
553+ getConfiguredTypeCode ( serviceRegistry , MappingSettings .PREFERRED_DURATION_JDBC_TYPE );
554+ return explicitSetting != null ? explicitSetting : SqlTypes .DURATION ;
569555
570- return SqlTypes .DURATION ;
571556 }
572557
573558 @ Incubating
574- public static synchronized int getPreferredSqlTypeCodeForUuid (StandardServiceRegistry serviceRegistry ) {
575- final Integer explicitSetting = serviceRegistry .requireService ( ConfigurationService .class ).getSetting (
576- AvailableSettings .PREFERRED_UUID_JDBC_TYPE ,
577- TypeCodeConverter .INSTANCE
578- );
579- if ( explicitSetting != null ) {
580- INCUBATION_LOGGER .incubatingSetting ( AvailableSettings .PREFERRED_UUID_JDBC_TYPE );
581- return explicitSetting ;
582- }
559+ public static synchronized int getPreferredSqlTypeCodeForUuid (ServiceRegistry serviceRegistry ) {
560+ final Integer explicitSetting =
561+ getConfiguredTypeCode ( serviceRegistry , MappingSettings .PREFERRED_UUID_JDBC_TYPE );
562+ return explicitSetting != null ? explicitSetting : SqlTypes .UUID ;
583563
584- return SqlTypes .UUID ;
585564 }
586565
587566 @ Incubating
588- public static synchronized int getPreferredSqlTypeCodeForInstant (StandardServiceRegistry serviceRegistry ) {
589- final Integer explicitSetting = serviceRegistry .requireService ( ConfigurationService .class ).getSetting (
590- AvailableSettings .PREFERRED_INSTANT_JDBC_TYPE ,
591- TypeCodeConverter .INSTANCE
592- );
593- if ( explicitSetting != null ) {
594- INCUBATION_LOGGER .incubatingSetting ( AvailableSettings .PREFERRED_INSTANT_JDBC_TYPE );
595- return explicitSetting ;
596- }
567+ public static synchronized int getPreferredSqlTypeCodeForInstant (ServiceRegistry serviceRegistry ) {
568+ final Integer explicitSetting =
569+ getConfiguredTypeCode ( serviceRegistry , MappingSettings .PREFERRED_INSTANT_JDBC_TYPE );
570+ return explicitSetting != null ? explicitSetting : SqlTypes .TIMESTAMP_UTC ;
597571
598- return SqlTypes .TIMESTAMP_UTC ;
599572 }
600573
601574 @ Incubating
602- public static synchronized int getPreferredSqlTypeCodeForArray (StandardServiceRegistry serviceRegistry ) {
603- final Integer explicitSetting = serviceRegistry .requireService ( ConfigurationService .class ).getSetting (
604- AvailableSettings .PREFERRED_ARRAY_JDBC_TYPE ,
605- TypeCodeConverter .INSTANCE
606- );
607- if ( explicitSetting != null ) {
608- INCUBATION_LOGGER .incubatingSetting ( AvailableSettings .PREFERRED_ARRAY_JDBC_TYPE );
609- return explicitSetting ;
610- }
611- // default to the Dialect answer
612- return serviceRegistry .requireService ( JdbcServices .class )
613- .getJdbcEnvironment ()
614- .getDialect ()
615- .getPreferredSqlTypeCodeForArray ();
575+ public static synchronized int getPreferredSqlTypeCodeForArray (ServiceRegistry serviceRegistry ) {
576+ final Integer explicitSetting =
577+ getConfiguredTypeCode ( serviceRegistry , MappingSettings .PREFERRED_ARRAY_JDBC_TYPE );
578+ return explicitSetting != null
579+ ? explicitSetting
580+ : serviceRegistry .requireService ( JdbcServices .class )
581+ .getDialect ().getPreferredSqlTypeCodeForArray ();
616582 }
617583
618584 public static void setIfNotEmpty (String value , String settingName , Map <String , String > configuration ) {
0 commit comments