Skip to content

Commit 77cc8a0

Browse files
committed
cleaner code by adding some static imports
1 parent 704011f commit 77cc8a0

File tree

2 files changed

+32
-33
lines changed

2 files changed

+32
-33
lines changed

hibernate-core/src/main/java/org/hibernate/boot/spi/MetadataBuildingContext.java

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,16 @@
77
import org.hibernate.Incubating;
88
import org.hibernate.boot.model.TypeDefinitionRegistry;
99
import org.hibernate.boot.model.naming.ObjectNameNormalizer;
10-
import org.hibernate.cfg.MappingSettings;
10+
import org.hibernate.boot.registry.StandardServiceRegistry;
1111
import org.hibernate.engine.config.spi.ConfigurationService;
1212
import org.hibernate.internal.util.config.ConfigurationHelper;
1313
import org.hibernate.service.ServiceRegistry;
1414

15+
import static org.hibernate.cfg.MappingSettings.JAVA_TIME_USE_DIRECT_JDBC;
16+
import static org.hibernate.cfg.MappingSettings.PREFER_LOCALE_LANGUAGE_TAG;
17+
import static org.hibernate.cfg.MappingSettings.PREFER_NATIVE_ENUM_TYPES;
18+
import static org.hibernate.internal.util.config.ConfigurationHelper.getBoolean;
19+
1520
/**
1621
* Describes the context in which the process of building {@link org.hibernate.boot.Metadata}
1722
* from {@link org.hibernate.boot.MetadataSources} occurs.
@@ -53,44 +58,48 @@ public interface MetadataBuildingContext {
5358
*/
5459
ObjectNameNormalizer getObjectNameNormalizer();
5560

61+
private StandardServiceRegistry getRegistry() {
62+
return getBootstrapContext().getServiceRegistry();
63+
}
64+
5665
@Incubating
5766
default int getPreferredSqlTypeCodeForBoolean() {
58-
return ConfigurationHelper.getPreferredSqlTypeCodeForBoolean( getBootstrapContext().getServiceRegistry() );
67+
return ConfigurationHelper.getPreferredSqlTypeCodeForBoolean( getRegistry() );
5968
}
6069

6170
@Incubating
6271
default int getPreferredSqlTypeCodeForDuration() {
63-
return ConfigurationHelper.getPreferredSqlTypeCodeForDuration( getBootstrapContext().getServiceRegistry() );
72+
return ConfigurationHelper.getPreferredSqlTypeCodeForDuration( getRegistry() );
6473
}
6574

6675
@Incubating
6776
default int getPreferredSqlTypeCodeForUuid() {
68-
return ConfigurationHelper.getPreferredSqlTypeCodeForUuid( getBootstrapContext().getServiceRegistry() );
77+
return ConfigurationHelper.getPreferredSqlTypeCodeForUuid( getRegistry() );
6978
}
7079

7180
@Incubating
7281
default int getPreferredSqlTypeCodeForInstant() {
73-
return ConfigurationHelper.getPreferredSqlTypeCodeForInstant( getBootstrapContext().getServiceRegistry() );
82+
return ConfigurationHelper.getPreferredSqlTypeCodeForInstant( getRegistry() );
7483
}
7584

7685
@Incubating
7786
default int getPreferredSqlTypeCodeForArray() {
78-
return ConfigurationHelper.getPreferredSqlTypeCodeForArray( getBootstrapContext().getServiceRegistry() );
87+
return ConfigurationHelper.getPreferredSqlTypeCodeForArray( getRegistry() );
7988
}
8089

8190
@Incubating
8291
default boolean isPreferJavaTimeJdbcTypesEnabled() {
83-
return isPreferJavaTimeJdbcTypesEnabled( getBootstrapContext().getServiceRegistry() );
92+
return isPreferJavaTimeJdbcTypesEnabled( getRegistry() );
8493
}
8594

8695
@Incubating
8796
default boolean isPreferNativeEnumTypesEnabled() {
88-
return isPreferNativeEnumTypesEnabled( getBootstrapContext().getServiceRegistry() );
97+
return isPreferNativeEnumTypesEnabled( getRegistry() );
8998
}
9099

91100
@Incubating
92101
default boolean isPreferLocaleLanguageTagEnabled() {
93-
return isPreferLocaleLanguageTagEnabled( getBootstrapContext().getServiceRegistry() );
102+
return isPreferLocaleLanguageTagEnabled( getRegistry() );
94103
}
95104

96105
static boolean isPreferJavaTimeJdbcTypesEnabled(ServiceRegistry serviceRegistry) {
@@ -106,29 +115,16 @@ static boolean isPreferLocaleLanguageTagEnabled(ServiceRegistry serviceRegistry)
106115
}
107116

108117
static boolean isPreferJavaTimeJdbcTypesEnabled(ConfigurationService configurationService) {
109-
return ConfigurationHelper.getBoolean(
110-
MappingSettings.JAVA_TIME_USE_DIRECT_JDBC,
111-
configurationService.getSettings(),
112-
// todo : true would be better eventually so maybe just rip off that band aid
113-
false
114-
);
118+
return getBoolean( JAVA_TIME_USE_DIRECT_JDBC, configurationService.getSettings() );
115119
}
116120

117121
static boolean isPreferNativeEnumTypesEnabled(ConfigurationService configurationService) {
118-
return ConfigurationHelper.getBoolean(
119-
MappingSettings.PREFER_NATIVE_ENUM_TYPES,
120-
configurationService.getSettings(),
121-
// todo: switch to true with HHH-17905
122-
false
123-
);
122+
//TODO: HHH-17905 proposes to switch this default to true
123+
return getBoolean( PREFER_NATIVE_ENUM_TYPES, configurationService.getSettings() );
124124
}
125125

126126
static boolean isPreferLocaleLanguageTagEnabled(ConfigurationService configurationService) {
127-
return ConfigurationHelper.getBoolean(
128-
MappingSettings.PREFER_LOCALE_LANGUAGE_TAG,
129-
configurationService.getSettings(),
130-
false
131-
);
127+
return getBoolean( PREFER_LOCALE_LANGUAGE_TAG, configurationService.getSettings() );
132128
}
133129

134130
TypeDefinitionRegistry getTypeDefinitionRegistry();

hibernate-core/src/main/java/org/hibernate/type/descriptor/java/LocaleJavaType.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99

1010
import org.hibernate.type.descriptor.WrapperOptions;
1111

12+
import static java.lang.Character.isLetter;
13+
import static java.lang.Character.toLowerCase;
14+
1215
/**
1316
* Descriptor for {@link Locale} handling.
1417
*
@@ -48,13 +51,13 @@ public Locale fromString(CharSequence sequence) {
4851
return null;
4952
}
5053

51-
String string = sequence.toString();
54+
final String string = sequence.toString();
5255
if ( string.isEmpty() ) {
5356
return Locale.ROOT;
5457
}
5558

5659
final char[] chars = string.toCharArray();
57-
final Locale.Builder builder = new Locale.Builder();
60+
final var builder = new Locale.Builder();
5861
State state = State.LANGUAGE;
5962
int position = 0;
6063

@@ -148,17 +151,17 @@ State parseNext(char[] chars, int start, int length, Locale.Builder builder) {
148151

149152
private boolean isScript(char[] chars, int start, int length) {
150153
return length == 4
151-
&& Character.isLetter( chars[start] )
152-
&& Character.isLetter( chars[start + 1] )
153-
&& Character.isLetter( chars[start + 2] )
154-
&& Character.isLetter( chars[start + 3] );
154+
&& isLetter( chars[start] )
155+
&& isLetter( chars[start + 1] )
156+
&& isLetter( chars[start + 2] )
157+
&& isLetter( chars[start + 3] );
155158
}
156159

157160
private void handleExtension(char[] chars, int start, int length, Locale.Builder builder) {
158161
if ( length < 3 || chars[start + 1] != '-' ) {
159162
throw new IllegalArgumentException( "Invalid extension: " + new String( chars, start, length ) );
160163
}
161-
if ( Character.toLowerCase( chars[start] ) == 'u' ) {
164+
if ( toLowerCase( chars[start] ) == 'u' ) {
162165
// After a Unicode extension, there could come a private use extension which we need to detect
163166
int unicodeStart = start + 2;
164167
int unicodeLength = length - 2;

0 commit comments

Comments
 (0)