Skip to content

Commit 072d3e2

Browse files
committed
miscellaneous code cleanups and refactoring
1 parent 3521857 commit 072d3e2

File tree

4 files changed

+155
-151
lines changed

4 files changed

+155
-151
lines changed

hibernate-core/src/main/java/org/hibernate/boot/internal/SessionFactoryOptionsBuilder.java

Lines changed: 48 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,6 @@
6868
import org.hibernate.resource.transaction.spi.TransactionCoordinatorBuilder;
6969
import org.hibernate.stat.Statistics;
7070
import org.hibernate.type.format.FormatMapper;
71-
import org.hibernate.type.format.jackson.JacksonIntegration;
72-
import org.hibernate.type.format.jakartajson.JakartaJsonIntegration;
7371
import org.hibernate.type.format.jaxb.JaxbXmlFormatMapper;
7472

7573
import jakarta.persistence.criteria.Nulls;
@@ -142,6 +140,9 @@
142140
import static org.hibernate.internal.util.config.ConfigurationHelper.getInt;
143141
import static org.hibernate.internal.util.config.ConfigurationHelper.getInteger;
144142
import static org.hibernate.internal.util.config.ConfigurationHelper.getString;
143+
import static org.hibernate.type.format.jackson.JacksonIntegration.getJsonJacksonFormatMapperOrNull;
144+
import static org.hibernate.type.format.jackson.JacksonIntegration.getXMLJacksonFormatMapperOrNull;
145+
import static org.hibernate.type.format.jakartajson.JakartaJsonIntegration.getJakartaJsonBFormatMapperOrNull;
145146

146147
/**
147148
* In-flight state of {@link SessionFactoryOptions} during {@link org.hibernate.boot.SessionFactoryBuilder}
@@ -648,10 +649,7 @@ else if ( jdbcTimeZoneValue != null ) {
648649

649650
private boolean disallowBatchUpdates(Dialect dialect, ExtractedDatabaseMetaData meta) {
650651
final Boolean dialectAnswer = dialect.supportsBatchUpdates();
651-
if ( dialectAnswer != null ) {
652-
return !dialectAnswer;
653-
}
654-
return !meta.supportsBatchUpdates();
652+
return dialectAnswer != null ? !dialectAnswer : !meta.supportsBatchUpdates();
655653
}
656654

657655
@SuppressWarnings("unchecked")
@@ -759,19 +757,20 @@ private HqlTranslator resolveHqlTranslator(
759757
if ( isEmpty( producerName ) ) {
760758
return null;
761759
}
762-
763-
//noinspection Convert2Lambda
764-
return strategySelector.resolveDefaultableStrategy(
765-
HqlTranslator.class,
766-
producerName,
767-
new Callable<>() {
768-
@Override
769-
public HqlTranslator call() throws Exception {
770-
return (HqlTranslator) serviceRegistry.requireService( ClassLoaderService.class )
771-
.classForName( producerName ).newInstance();
760+
else {
761+
//noinspection Convert2Lambda
762+
return strategySelector.resolveDefaultableStrategy(
763+
HqlTranslator.class,
764+
producerName,
765+
new Callable<>() {
766+
@Override
767+
public HqlTranslator call() throws Exception {
768+
return (HqlTranslator) serviceRegistry.requireService( ClassLoaderService.class )
769+
.classForName( producerName ).newInstance();
770+
}
772771
}
773-
}
774-
);
772+
);
773+
}
775774
}
776775

777776
private SqmTranslatorFactory resolveSqmTranslator(
@@ -780,21 +779,20 @@ private SqmTranslatorFactory resolveSqmTranslator(
780779
if ( isEmpty( translatorImplFqn ) ) {
781780
return null;
782781
}
783-
784-
return strategySelector.resolveStrategy(
785-
SqmTranslatorFactory.class,
786-
translatorImplFqn
787-
);
782+
else {
783+
return strategySelector.resolveStrategy(
784+
SqmTranslatorFactory.class,
785+
translatorImplFqn
786+
);
787+
}
788788
}
789789

790790
private static Interceptor determineInterceptor(
791791
Map<String,Object> configurationSettings,
792792
StrategySelector strategySelector) {
793-
Object setting = configurationSettings.get( INTERCEPTOR );
794-
795793
return strategySelector.resolveStrategy(
796794
Interceptor.class,
797-
setting
795+
configurationSettings.get( INTERCEPTOR )
798796
);
799797
}
800798

@@ -811,8 +809,7 @@ else if ( setting instanceof Supplier ) {
811809
return (Supplier<? extends Interceptor>) setting;
812810
}
813811
else if ( setting instanceof Class ) {
814-
Class<? extends Interceptor> clazz = (Class<? extends Interceptor>) setting;
815-
return interceptorSupplier( clazz );
812+
return interceptorSupplier( (Class<? extends Interceptor>) setting );
816813
}
817814
else {
818815
return interceptorSupplier(
@@ -839,29 +836,21 @@ private static Supplier<? extends Interceptor> interceptorSupplier(Class<? exten
839836
private PhysicalConnectionHandlingMode interpretConnectionHandlingMode(
840837
Map<String,Object> configurationSettings,
841838
StandardServiceRegistry serviceRegistry) {
842-
final PhysicalConnectionHandlingMode specifiedHandlingMode = PhysicalConnectionHandlingMode.interpret(
843-
configurationSettings.get( CONNECTION_HANDLING )
844-
);
845-
846-
if ( specifiedHandlingMode != null ) {
847-
return specifiedHandlingMode;
848-
}
849-
850-
return serviceRegistry.requireService( TransactionCoordinatorBuilder.class ).getDefaultConnectionHandlingMode();
839+
final PhysicalConnectionHandlingMode specifiedHandlingMode =
840+
PhysicalConnectionHandlingMode.interpret( configurationSettings.get( CONNECTION_HANDLING ) );
841+
return specifiedHandlingMode != null
842+
? specifiedHandlingMode
843+
: serviceRegistry.requireService( TransactionCoordinatorBuilder.class )
844+
.getDefaultConnectionHandlingMode();
851845
}
852846

853847
private static FormatMapper determineJsonFormatMapper(Object setting, StrategySelector strategySelector) {
854848
return strategySelector.resolveDefaultableStrategy(
855849
FormatMapper.class,
856850
setting,
857851
(Callable<FormatMapper>) () -> {
858-
final FormatMapper jsonJacksonFormatMapper = JacksonIntegration.getJsonJacksonFormatMapperOrNull();
859-
if (jsonJacksonFormatMapper != null) {
860-
return jsonJacksonFormatMapper;
861-
}
862-
else {
863-
return JakartaJsonIntegration.getJakartaJsonBFormatMapperOrNull();
864-
}
852+
final FormatMapper jsonJacksonFormatMapper = getJsonJacksonFormatMapperOrNull();
853+
return jsonJacksonFormatMapper != null ? jsonJacksonFormatMapper : getJakartaJsonBFormatMapperOrNull();
865854
}
866855
);
867856
}
@@ -871,11 +860,8 @@ private static FormatMapper determineXmlFormatMapper(Object setting, StrategySel
871860
FormatMapper.class,
872861
setting,
873862
(Callable<FormatMapper>) () -> {
874-
final FormatMapper jacksonFormatMapper = JacksonIntegration.getXMLJacksonFormatMapperOrNull();
875-
if (jacksonFormatMapper != null) {
876-
return jacksonFormatMapper;
877-
}
878-
return new JaxbXmlFormatMapper();
863+
final FormatMapper jacksonFormatMapper = getXMLJacksonFormatMapperOrNull();
864+
return jacksonFormatMapper != null ? jacksonFormatMapper : new JaxbXmlFormatMapper();
879865
}
880866
);
881867
}
@@ -1393,21 +1379,22 @@ public void enableStatisticsSupport(boolean enabled) {
13931379
}
13941380

13951381
public void addSessionFactoryObservers(SessionFactoryObserver... observers) {
1396-
Collections.addAll( this.sessionFactoryObserverList, observers );
1382+
Collections.addAll( sessionFactoryObserverList, observers );
13971383
}
13981384

13991385
public void applyInterceptor(Interceptor interceptor) {
14001386
this.interceptor = interceptor;
14011387
}
14021388

14031389
public void applyStatelessInterceptor(Class<? extends Interceptor> statelessInterceptorClass) {
1404-
this.applyStatelessInterceptorSupplier(
1390+
applyStatelessInterceptorSupplier(
14051391
() -> {
14061392
try {
14071393
return statelessInterceptorClass.newInstance();
14081394
}
14091395
catch (InstantiationException | IllegalAccessException e) {
1410-
throw new HibernateException( String.format( "Could not supply stateless Interceptor of class %s", statelessInterceptorClass.getName()), e );
1396+
throw new HibernateException( "Could not supply stateless Interceptor of class '"
1397+
+ statelessInterceptorClass.getName() + "'", e );
14111398
}
14121399
}
14131400
);
@@ -1563,10 +1550,10 @@ public void enableCommentsSupport(boolean enabled) {
15631550
}
15641551

15651552
public void applySqlFunction(String registrationName, SqmFunctionDescriptor sqlFunction) {
1566-
if ( this.sqlFunctions == null ) {
1567-
this.sqlFunctions = new HashMap<>();
1553+
if ( sqlFunctions == null ) {
1554+
sqlFunctions = new HashMap<>();
15681555
}
1569-
this.sqlFunctions.put( registrationName, sqlFunction );
1556+
sqlFunctions.put( registrationName, sqlFunction );
15701557
}
15711558

15721559
public void allowOutOfTransactionUpdateOperations(boolean allow) {
@@ -1582,11 +1569,12 @@ public void enableJpaQueryCompliance(boolean enabled) {
15821569
}
15831570

15841571
private MutableJpaCompliance mutableJpaCompliance() {
1585-
if ( !(this.jpaCompliance instanceof MutableJpaCompliance) ) {
1572+
if ( jpaCompliance instanceof MutableJpaCompliance mutableJpaCompliance ) {
1573+
return mutableJpaCompliance;
1574+
}
1575+
else {
15861576
throw new IllegalStateException( "JpaCompliance is no longer mutable" );
15871577
}
1588-
1589-
return (MutableJpaCompliance) this.jpaCompliance;
15901578
}
15911579

15921580
public void enableJpaTransactionCompliance(boolean enabled) {
@@ -1627,10 +1615,9 @@ public void disableJtaTransactionAccess() {
16271615
}
16281616

16291617
public SessionFactoryOptions buildOptions() {
1630-
if ( this.jpaCompliance instanceof MutableJpaCompliance ) {
1631-
this.jpaCompliance = mutableJpaCompliance().immutableCopy();
1618+
if ( jpaCompliance instanceof MutableJpaCompliance ) {
1619+
jpaCompliance = mutableJpaCompliance().immutableCopy();
16321620
}
1633-
16341621
return this;
16351622
}
16361623
}

0 commit comments

Comments
 (0)