Skip to content

Commit e0980a5

Browse files
committed
remove obsolete and deprecated methods from an internal utility class
no need to wait for H8 to remove these
1 parent f5d87c5 commit e0980a5

File tree

1 file changed

+44
-191
lines changed

1 file changed

+44
-191
lines changed

hibernate-core/src/main/java/org/hibernate/internal/util/config/ConfigurationHelper.java

Lines changed: 44 additions & 191 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,25 @@
88
import java.util.Locale;
99
import java.util.Map;
1010
import java.util.Properties;
11-
import java.util.StringTokenizer;
1211
import java.util.function.Supplier;
1312

1413
import org.checkerframework.checker.nullness.qual.NonNull;
1514
import org.hibernate.Incubating;
16-
import org.hibernate.cfg.MappingSettings;
1715
import org.hibernate.dialect.Dialect;
1816
import org.hibernate.engine.config.spi.ConfigurationService;
1917
import org.hibernate.engine.jdbc.spi.JdbcServices;
20-
import org.hibernate.internal.util.StringHelper;
21-
import org.hibernate.internal.util.collections.ArrayHelper;
2218
import org.hibernate.service.ServiceRegistry;
2319
import org.hibernate.type.SqlTypes;
2420
import org.hibernate.type.descriptor.JdbcTypeNameMapper;
2521

22+
import static org.hibernate.cfg.MappingSettings.PREFERRED_ARRAY_JDBC_TYPE;
23+
import static org.hibernate.cfg.MappingSettings.PREFERRED_BOOLEAN_JDBC_TYPE;
24+
import static org.hibernate.cfg.MappingSettings.PREFERRED_DURATION_JDBC_TYPE;
25+
import static org.hibernate.cfg.MappingSettings.PREFERRED_INSTANT_JDBC_TYPE;
26+
import static org.hibernate.cfg.MappingSettings.PREFERRED_UUID_JDBC_TYPE;
2627
import static org.hibernate.internal.log.IncubationLogger.INCUBATION_LOGGER;
28+
import static org.hibernate.internal.util.StringHelper.isBlank;
29+
import static org.hibernate.internal.util.StringHelper.isNotEmpty;
2730

2831
/**
2932
* Collection of helper methods for dealing with configuration settings.
@@ -243,60 +246,35 @@ else if (value instanceof String string) {
243246
}
244247

245248
/**
246-
* Make a clone of the configuration values.
249+
* Replace a property value with a starred version
247250
*
248-
* @param configurationValues The config values to clone
249-
*
250-
* @return The clone
251-
*
252-
* @deprecated No longer used
253-
*/
254-
@SuppressWarnings("rawtypes")
255-
@Deprecated(since = "7", forRemoval = true)
256-
public static Map clone(Map<?,?> configurationValues) {
257-
if ( configurationValues == null ) {
258-
return null;
259-
}
260-
else if ( configurationValues instanceof Properties properties ) {
261-
// If a Properties object, leverage its clone() impl
262-
return (Properties) properties.clone();
263-
}
264-
else {
265-
// Otherwise make a manual copy
266-
return new HashMap<>( configurationValues );
267-
}
268-
}
269-
270-
/**
271-
* Replace a property by a starred version
272-
*
273-
* @param props properties to check
251+
* @param properties properties to check
274252
* @param key property to mask
275253
*
276254
* @return cloned and masked properties
277255
*/
278-
public static Properties maskOut(Properties props, String key) {
279-
final var clone = (Properties) props.clone();
256+
public static Properties maskOut(Properties properties, String key) {
257+
final var clone = (Properties) properties.clone();
280258
if ( clone.get( key ) != null ) {
281259
clone.setProperty( key, "****" );
282260
}
283261
return clone;
284262
}
285263

286264
/**
287-
* Replace properties by starred version
265+
* Replace property values with starred versions
288266
*
289-
* @param props properties to check
267+
* @param properties properties to check
290268
* @param keys properties to mask
291269
*
292270
* @return cloned and masked properties
293271
*/
294-
public static Properties maskOut(Properties props, String... keys) {
295-
Properties result = props;
272+
public static Properties maskOut(Properties properties, String... keys) {
273+
Properties result = properties;
296274
for ( String key : keys ) {
297-
if ( props.get( key ) != null ) {
298-
if ( result == props ) {
299-
result = (Properties) props.clone();
275+
if ( properties.get( key ) != null ) {
276+
if ( result == properties ) {
277+
result = (Properties) properties.clone();
300278
}
301279
result.setProperty( key, "****" );
302280
}
@@ -307,17 +285,17 @@ public static Properties maskOut(Properties props, String... keys) {
307285
/**
308286
* Replace properties by starred version
309287
*
310-
* @param props properties to check
288+
* @param properties properties to check
311289
* @param keys properties to mask
312290
*
313291
* @return cloned and masked properties
314292
*/
315-
public static Map<String, Object> maskOut(Map<String, Object> props, String... keys) {
316-
Map<String,Object> result = props;
293+
public static Map<String, Object> maskOut(Map<String, Object> properties, String... keys) {
294+
Map<String,Object> result = properties;
317295
for ( String key : keys ) {
318-
if ( props.containsKey( key ) ) {
319-
if ( result == props ) {
320-
result = new HashMap<>( props );
296+
if ( properties.containsKey( key ) ) {
297+
if ( result == properties ) {
298+
result = new HashMap<>( properties );
321299
}
322300
result.put( key, "****" );
323301
}
@@ -335,15 +313,9 @@ public static Map<String, Object> maskOut(Map<String, Object> props, String... k
335313
* @return The property value; may be null.
336314
*/
337315
public static String extractPropertyValue(String propertyName, Properties properties) {
338-
String value = properties.getProperty( propertyName );
339-
if ( value == null ) {
340-
return null;
341-
}
342-
value = value.trim();
343-
if ( value.isEmpty() ) {
344-
return null;
345-
}
346-
return value;
316+
final String value = properties.getProperty( propertyName );
317+
return isBlank( value ) ? null : value.trim();
318+
347319
}
348320
/**
349321
* Extract a property value by name from the given properties object.
@@ -355,120 +327,8 @@ public static String extractPropertyValue(String propertyName, Properties proper
355327
* @return The property value; may be null.
356328
*/
357329
public static String extractPropertyValue(String propertyName, Map<?,?> properties) {
358-
String value = (String) properties.get( propertyName );
359-
if ( value == null ) {
360-
return null;
361-
}
362-
value = value.trim();
363-
if ( value.isEmpty() ) {
364-
return null;
365-
}
366-
return value;
367-
}
368-
369-
/**
370-
* @deprecated No longer used
371-
*/
372-
@Deprecated(since = "7.2", forRemoval = true)
373-
public static String extractValue(
374-
String name,
375-
Map<?,?> values,
376-
Supplier<String> fallbackValueFactory) {
377-
final String value = extractPropertyValue( name, values );
378-
if ( value != null ) {
379-
return value;
380-
}
381-
382-
return fallbackValueFactory.get();
383-
}
384-
385-
/**
386-
* Constructs a map from a property value.
387-
* <p>
388-
* The exact behavior here is largely dependant upon what is passed in as
389-
* the delimiter.
390-
*
391-
* @see #extractPropertyValue(String, Properties)
392-
*
393-
* @param propertyName The name of the property for which to retrieve value
394-
* @param delim The string defining tokens used as both entry and key/value delimiters.
395-
* @param properties The properties object
396-
* @return The resulting map; never null, though perhaps empty.
397-
*
398-
* @deprecated No longer used
399-
*/
400-
@SuppressWarnings("rawtypes")
401-
@Deprecated(since = "7", forRemoval = true)
402-
public static Map toMap(String propertyName, String delim, Properties properties) {
403-
final Map<String,String> map = new HashMap<>();
404-
final String value = extractPropertyValue( propertyName, properties );
405-
if ( value != null ) {
406-
final var tokens = new StringTokenizer( value, delim );
407-
while ( tokens.hasMoreTokens() ) {
408-
map.put( tokens.nextToken(), tokens.hasMoreElements() ? tokens.nextToken() : "" );
409-
}
410-
}
411-
return map;
412-
}
413-
414-
/**
415-
* Constructs a map from a property value.
416-
* <p>
417-
* The exact behavior here is largely dependant upon what is passed in as
418-
* the delimiter.
419-
*
420-
* @see #extractPropertyValue(String, Properties)
421-
*
422-
* @param propertyName The name of the property for which to retrieve value
423-
* @param delim The string defining tokens used as both entry and key/value delimiters.
424-
* @param properties The properties object
425-
* @return The resulting map; never null, though perhaps empty.
426-
*
427-
* @deprecated No longer used
428-
*/
429-
@SuppressWarnings("rawtypes")
430-
@Deprecated(since = "7", forRemoval = true)
431-
public static Map toMap(String propertyName, String delim, Map<?,?> properties) {
432-
final Map<String,String> map = new HashMap<>();
433-
final String value = extractPropertyValue( propertyName, properties );
434-
if ( value != null ) {
435-
final var tokens = new StringTokenizer( value, delim );
436-
while ( tokens.hasMoreTokens() ) {
437-
map.put( tokens.nextToken(), tokens.hasMoreElements() ? tokens.nextToken() : "" );
438-
}
439-
}
440-
return map;
441-
}
442-
443-
/**
444-
* Get a property value as a string array.
445-
*
446-
* @see #extractPropertyValue(String, Properties)
447-
* @see #toStringArray(String, String)
448-
*
449-
* @param propertyName The name of the property for which to retrieve value
450-
* @param delim The delimiter used to separate individual array elements.
451-
* @param properties The properties object
452-
* @return The array; never null, though may be empty.
453-
*/
454-
public static String[] toStringArray(String propertyName, String delim, Properties properties) {
455-
return toStringArray( extractPropertyValue( propertyName, properties ), delim );
456-
}
457-
458-
/**
459-
* Convert a string to an array of strings. The assumption is that
460-
* the individual array elements are delimited in the source stringForm
461-
* param by the delim param.
462-
*
463-
* @param stringForm The string form of the string array.
464-
* @param delim The delimiter used to separate individual array elements.
465-
* @return The array; never null, though may be empty.
466-
*/
467-
public static String[] toStringArray(String stringForm, String delim) {
468-
// todo : move to StringHelper?
469-
return stringForm != null
470-
? StringHelper.split( delim, stringForm )
471-
: ArrayHelper.EMPTY_STRING_ARRAY;
330+
final String value = (String) properties.get( propertyName );
331+
return isBlank( value ) ? null : value.trim();
472332
}
473333

474334
/**
@@ -477,14 +337,14 @@ public static String[] toStringArray(String stringForm, String delim) {
477337
* @param configurationValues The configuration map.
478338
*/
479339
public static void resolvePlaceHolders(Map<?,Object> configurationValues) {
480-
final var itr = configurationValues.entrySet().iterator();
481-
while ( itr.hasNext() ) {
482-
final var entry = itr.next();
340+
final var entries = configurationValues.entrySet().iterator();
341+
while ( entries.hasNext() ) {
342+
final var entry = entries.next();
483343
if ( entry.getValue() instanceof String string ) {
484344
final String resolved = resolvePlaceHolder( string );
485345
if ( !string.equals( resolved ) ) {
486346
if ( resolved == null ) {
487-
itr.remove();
347+
entries.remove();
488348
}
489349
else {
490350
entry.setValue( resolved );
@@ -511,17 +371,17 @@ public static String resolvePlaceHolder(String property) {
511371
// peek ahead
512372
if ( chars[pos+1] == '{' ) {
513373
// we have a placeholder, spin forward till we find the end
514-
String systemPropertyName = "";
374+
final var systemPropertyName = new StringBuilder();
515375
int x = pos + 2;
516-
for ( ; x < chars.length && chars[x] != '}'; x++ ) {
517-
systemPropertyName += chars[x];
376+
for ( ; x < chars.length && chars[x] != '}'; x++ ) {
377+
systemPropertyName.append( chars[x] );
518378
// if we reach the end of the string w/o finding the
519379
// matching end, that is an exception
520380
if ( x == chars.length - 1 ) {
521381
throw new IllegalArgumentException( "unmatched placeholder start [" + property + "]" );
522382
}
523383
}
524-
final String systemProperty = extractFromSystem( systemPropertyName );
384+
final String systemProperty = extractFromSystem( systemPropertyName.toString() );
525385
result.append( systemProperty == null ? "" : systemProperty );
526386
pos = x + 1;
527387
// make sure spinning forward did not put us past the end of the buffer...
@@ -557,7 +417,7 @@ private static Integer getConfiguredTypeCode(ServiceRegistry serviceRegistry, St
557417
@Incubating
558418
public static synchronized int getPreferredSqlTypeCodeForBoolean(ServiceRegistry serviceRegistry) {
559419
final Integer typeCode =
560-
getConfiguredTypeCode( serviceRegistry, MappingSettings.PREFERRED_BOOLEAN_JDBC_TYPE );
420+
getConfiguredTypeCode( serviceRegistry, PREFERRED_BOOLEAN_JDBC_TYPE );
561421
return typeCode != null
562422
? typeCode
563423
: serviceRegistry.requireService( JdbcServices.class )
@@ -567,53 +427,46 @@ public static synchronized int getPreferredSqlTypeCodeForBoolean(ServiceRegistry
567427
@Incubating
568428
public static synchronized int getPreferredSqlTypeCodeForBoolean(ServiceRegistry serviceRegistry, Dialect dialect) {
569429
final Integer typeCode =
570-
getConfiguredTypeCode( serviceRegistry, MappingSettings.PREFERRED_BOOLEAN_JDBC_TYPE );
430+
getConfiguredTypeCode( serviceRegistry, PREFERRED_BOOLEAN_JDBC_TYPE );
571431
return typeCode != null ? typeCode : dialect.getPreferredSqlTypeCodeForBoolean();
572432
}
573433

574434
@Incubating
575435
public static synchronized int getPreferredSqlTypeCodeForDuration(ServiceRegistry serviceRegistry) {
576436
final Integer explicitSetting =
577-
getConfiguredTypeCode( serviceRegistry, MappingSettings.PREFERRED_DURATION_JDBC_TYPE );
437+
getConfiguredTypeCode( serviceRegistry, PREFERRED_DURATION_JDBC_TYPE );
578438
return explicitSetting != null ? explicitSetting : SqlTypes.DURATION;
579439

580440
}
581441

582442
@Incubating
583443
public static synchronized int getPreferredSqlTypeCodeForUuid(ServiceRegistry serviceRegistry) {
584444
final Integer explicitSetting =
585-
getConfiguredTypeCode( serviceRegistry, MappingSettings.PREFERRED_UUID_JDBC_TYPE );
445+
getConfiguredTypeCode( serviceRegistry, PREFERRED_UUID_JDBC_TYPE );
586446
return explicitSetting != null ? explicitSetting : SqlTypes.UUID;
587447

588448
}
589449

590450
@Incubating
591451
public static synchronized int getPreferredSqlTypeCodeForInstant(ServiceRegistry serviceRegistry) {
592452
final Integer explicitSetting =
593-
getConfiguredTypeCode( serviceRegistry, MappingSettings.PREFERRED_INSTANT_JDBC_TYPE );
453+
getConfiguredTypeCode( serviceRegistry, PREFERRED_INSTANT_JDBC_TYPE );
594454
return explicitSetting != null ? explicitSetting : SqlTypes.TIMESTAMP_UTC;
595455

596456
}
597457

598458
@Incubating
599459
public static synchronized int getPreferredSqlTypeCodeForArray(ServiceRegistry serviceRegistry) {
600460
final Integer explicitSetting =
601-
getConfiguredTypeCode( serviceRegistry, MappingSettings.PREFERRED_ARRAY_JDBC_TYPE );
461+
getConfiguredTypeCode( serviceRegistry, PREFERRED_ARRAY_JDBC_TYPE );
602462
return explicitSetting != null
603463
? explicitSetting
604464
: serviceRegistry.requireService( JdbcServices.class )
605465
.getDialect().getPreferredSqlTypeCodeForArray();
606466
}
607467

608468
public static void setIfNotEmpty(String value, String settingName, Map<String, String> configuration) {
609-
if ( StringHelper.isNotEmpty( value ) ) {
610-
configuration.put( settingName, value );
611-
}
612-
}
613-
614-
@Deprecated(since = "7", forRemoval = true)
615-
public static void setIfNotNull(Object value, String settingName, Map<String, Object> configuration) {
616-
if ( value != null ) {
469+
if ( isNotEmpty( value ) ) {
617470
configuration.put( settingName, value );
618471
}
619472
}

0 commit comments

Comments
 (0)