80
80
import org .hibernate .resource .transaction .spi .TransactionCoordinatorBuilder ;
81
81
import org .hibernate .stat .Statistics ;
82
82
import org .hibernate .type .format .FormatMapper ;
83
- import org .hibernate .type .format .jackson .JacksonIntegration ;
84
83
import org .hibernate .type .format .jaxb .JaxbXmlFormatMapper ;
85
84
86
85
import jakarta .persistence .criteria .Nulls ;
118
117
import static org .hibernate .type .format .jackson .JacksonIntegration .getJsonJacksonFormatMapperOrNull ;
119
118
import static org .hibernate .type .format .jackson .JacksonIntegration .getOsonJacksonFormatMapperOrNull ;
120
119
import static org .hibernate .type .format .jackson .JacksonIntegration .getXMLJacksonFormatMapperOrNull ;
120
+ import static org .hibernate .type .format .jackson .JacksonIntegration .isJacksonOsonExtensionAvailable ;
121
121
import static org .hibernate .type .format .jakartajson .JakartaJsonIntegration .getJakartaJsonBFormatMapperOrNull ;
122
122
123
123
/**
@@ -309,13 +309,13 @@ public SessionFactoryOptionsBuilder(StandardServiceRegistry serviceRegistry, Boo
309
309
settings .get ( AvailableSettings .JAKARTA_VALIDATION_FACTORY )
310
310
);
311
311
312
- jsonFormatMapper = determineJsonFormatMapper (
312
+ jsonFormatMapper = jsonFormatMapper (
313
313
settings .get ( AvailableSettings .JSON_FORMAT_MAPPER ),
314
314
!getBoolean ( ORACLE_OSON_DISABLED ,settings ),
315
315
strategySelector
316
316
);
317
317
318
- xmlFormatMapper = determineXmlFormatMapper (
318
+ xmlFormatMapper = xmlFormatMapper (
319
319
settings .get ( AvailableSettings .XML_FORMAT_MAPPER ),
320
320
strategySelector ,
321
321
xmlFormatMapperLegacyFormatEnabled =
@@ -620,17 +620,20 @@ private SqmMultiTableMutationStrategy resolveSqmMutationStrategy(
620
620
strategyName ,
621
621
(SqmMultiTableMutationStrategy ) null ,
622
622
strategyClass -> {
623
- Constructor <SqmMultiTableMutationStrategy > dialectConstructor = null ;
624
- Constructor <SqmMultiTableMutationStrategy > emptyConstructor = null ;
623
+ Constructor <? extends SqmMultiTableMutationStrategy > dialectConstructor = null ;
624
+ Constructor <? extends SqmMultiTableMutationStrategy > emptyConstructor = null ;
625
625
// todo (6.0) : formalize the allowed constructor parameterizations
626
- for ( Constructor <?> declaredConstructor : strategyClass .getDeclaredConstructors () ) {
627
- final Class <?>[] parameterTypes = declaredConstructor .getParameterTypes ();
626
+ for ( var declaredConstructor : strategyClass .getDeclaredConstructors () ) {
627
+ final var parameterTypes = declaredConstructor .getParameterTypes ();
628
+ final var constructor =
629
+ (Constructor <? extends SqmMultiTableMutationStrategy >)
630
+ declaredConstructor ;
628
631
if ( parameterTypes .length == 1 && parameterTypes [0 ] == Dialect .class ) {
629
- dialectConstructor = ( Constructor < SqmMultiTableMutationStrategy >) declaredConstructor ;
632
+ dialectConstructor = constructor ;
630
633
break ;
631
634
}
632
635
else if ( parameterTypes .length == 0 ) {
633
- emptyConstructor = ( Constructor < SqmMultiTableMutationStrategy >) declaredConstructor ;
636
+ emptyConstructor = constructor ;
634
637
}
635
638
}
636
639
@@ -646,11 +649,13 @@ else if ( emptyConstructor != null ) {
646
649
}
647
650
catch (Exception e ) {
648
651
throw new StrategySelectionException (
649
- String . format ( "Could not instantiate named strategy class [%s]" , strategyClass .getName () ) ,
652
+ "Could not instantiate named strategy class [" + strategyClass .getName () + "]" ,
650
653
e
651
654
);
652
655
}
653
- throw new IllegalArgumentException ( "Cannot instantiate the class [" + strategyClass .getName () + "] because it does not have a constructor that accepts a dialect or an empty constructor" );
656
+ throw new IllegalArgumentException ( "Cannot instantiate the class ["
657
+ + strategyClass .getName ()
658
+ + "] because it does not have a constructor that accepts a dialect or an empty constructor" );
654
659
}
655
660
);
656
661
}
@@ -669,17 +674,20 @@ private SqmMultiTableInsertStrategy resolveSqmInsertStrategy(
669
674
strategyName ,
670
675
(SqmMultiTableInsertStrategy ) null ,
671
676
strategyClass -> {
672
- Constructor <SqmMultiTableInsertStrategy > dialectConstructor = null ;
673
- Constructor <SqmMultiTableInsertStrategy > emptyConstructor = null ;
677
+ Constructor <? extends SqmMultiTableInsertStrategy > dialectConstructor = null ;
678
+ Constructor <? extends SqmMultiTableInsertStrategy > emptyConstructor = null ;
674
679
// todo (6.0) : formalize the allowed constructor parameterizations
675
- for ( Constructor <?> declaredConstructor : strategyClass .getDeclaredConstructors () ) {
676
- final Class <?>[] parameterTypes = declaredConstructor .getParameterTypes ();
680
+ for ( var declaredConstructor : strategyClass .getDeclaredConstructors () ) {
681
+ final var parameterTypes = declaredConstructor .getParameterTypes ();
682
+ final var constructor =
683
+ (Constructor <? extends SqmMultiTableInsertStrategy >)
684
+ declaredConstructor ;
677
685
if ( parameterTypes .length == 1 && parameterTypes [0 ] == Dialect .class ) {
678
- dialectConstructor = ( Constructor < SqmMultiTableInsertStrategy >) declaredConstructor ;
686
+ dialectConstructor = constructor ;
679
687
break ;
680
688
}
681
689
else if ( parameterTypes .length == 0 ) {
682
- emptyConstructor = ( Constructor < SqmMultiTableInsertStrategy >) declaredConstructor ;
690
+ emptyConstructor = constructor ;
683
691
}
684
692
}
685
693
@@ -695,11 +703,13 @@ else if ( emptyConstructor != null ) {
695
703
}
696
704
catch (Exception e ) {
697
705
throw new StrategySelectionException (
698
- String . format ( "Could not instantiate named strategy class [%s]" , strategyClass .getName () ) ,
706
+ "Could not instantiate named strategy class [" + strategyClass .getName () + "]" ,
699
707
e
700
708
);
701
709
}
702
- throw new IllegalArgumentException ( "Cannot instantiate the class [" + strategyClass .getName () + "] because it does not have a constructor that accepts a dialect or an empty constructor" );
710
+ throw new IllegalArgumentException ( "Cannot instantiate the class ["
711
+ + strategyClass .getName ()
712
+ + "] because it does not have a constructor that accepts a dialect or an empty constructor" );
703
713
}
704
714
);
705
715
}
@@ -708,23 +718,15 @@ private HqlTranslator resolveHqlTranslator(
708
718
String producerName ,
709
719
StandardServiceRegistry serviceRegistry ,
710
720
StrategySelector strategySelector ) {
711
- if ( isEmpty ( producerName ) ) {
712
- return null ;
713
- }
714
- else {
715
- //noinspection Convert2Lambda
716
- return strategySelector .resolveDefaultableStrategy (
717
- HqlTranslator .class ,
718
- producerName ,
719
- new Callable <>() {
720
- @ Override
721
- public HqlTranslator call () throws Exception {
722
- return (HqlTranslator ) serviceRegistry .requireService ( ClassLoaderService .class )
723
- .classForName ( producerName ).newInstance ();
724
- }
725
- }
726
- );
727
- }
721
+ return isEmpty ( producerName )
722
+ ? null
723
+ : strategySelector .<HqlTranslator >resolveDefaultableStrategy (
724
+ HqlTranslator .class ,
725
+ producerName ,
726
+ () -> (HqlTranslator )
727
+ serviceRegistry .requireService ( ClassLoaderService .class )
728
+ .classForName ( producerName ).newInstance ()
729
+ );
728
730
}
729
731
730
732
private SqmTranslatorFactory resolveSqmTranslator (
@@ -754,8 +756,7 @@ private static Interceptor determineInterceptor(
754
756
private static Supplier <? extends Interceptor > determineStatelessInterceptor (
755
757
Map <String ,Object > configurationSettings ,
756
758
StrategySelector strategySelector ) {
757
- Object setting = configurationSettings .get ( SESSION_SCOPED_INTERCEPTOR );
758
-
759
+ final Object setting = configurationSettings .get ( SESSION_SCOPED_INTERCEPTOR );
759
760
if ( setting == null ) {
760
761
return null ;
761
762
}
@@ -782,7 +783,7 @@ private static Supplier<? extends Interceptor> interceptorSupplier(Class<? exten
782
783
return clazz .newInstance ();
783
784
}
784
785
catch (InstantiationException | IllegalAccessException e ) {
785
- throw new HibernateException ( "Could not supply session-scoped SessionFactory Interceptor" , e );
786
+ throw new org . hibernate . InstantiationException ( "Could not instantiate session-scoped Interceptor" , clazz , e );
786
787
}
787
788
};
788
789
}
@@ -798,32 +799,41 @@ private PhysicalConnectionHandlingMode interpretConnectionHandlingMode(
798
799
.getDefaultConnectionHandlingMode ();
799
800
}
800
801
801
- private static FormatMapper determineJsonFormatMapper (Object setting , boolean osonExtensionEnabled , StrategySelector strategySelector ) {
802
- return strategySelector .resolveDefaultableStrategy (
803
- FormatMapper .class ,
802
+ private static FormatMapper jsonFormatMapper (Object setting , boolean osonExtensionEnabled , StrategySelector selector ) {
803
+ return formatMapper (
804
804
setting ,
805
- (Callable <FormatMapper >) () -> {
805
+ selector ,
806
+ () -> {
806
807
// Prefer the OSON Jackson FormatMapper by default if available
807
808
final FormatMapper jsonJacksonFormatMapper =
808
- ( osonExtensionEnabled && JacksonIntegration . isJacksonOsonExtensionAvailable () )
809
+ osonExtensionEnabled && isJacksonOsonExtensionAvailable ()
809
810
? getOsonJacksonFormatMapperOrNull ()
810
811
: getJsonJacksonFormatMapperOrNull ();
811
- return jsonJacksonFormatMapper != null ? jsonJacksonFormatMapper : getJakartaJsonBFormatMapperOrNull ();
812
+ return jsonJacksonFormatMapper != null
813
+ ? jsonJacksonFormatMapper
814
+ : getJakartaJsonBFormatMapperOrNull ();
812
815
}
813
816
);
814
817
}
815
818
816
- private static FormatMapper determineXmlFormatMapper (Object setting , StrategySelector strategySelector , boolean legacyFormat ) {
817
- return strategySelector .resolveDefaultableStrategy (
818
- FormatMapper .class ,
819
+ private static FormatMapper xmlFormatMapper (Object setting , StrategySelector selector , boolean legacyFormat ) {
820
+ return formatMapper (
819
821
setting ,
820
- (Callable <FormatMapper >) () -> {
821
- final FormatMapper jacksonFormatMapper = getXMLJacksonFormatMapperOrNull ( legacyFormat );
822
- return jacksonFormatMapper != null ? jacksonFormatMapper : new JaxbXmlFormatMapper ( legacyFormat );
822
+ selector ,
823
+ () -> {
824
+ final FormatMapper jacksonFormatMapper =
825
+ getXMLJacksonFormatMapperOrNull ( legacyFormat );
826
+ return jacksonFormatMapper != null
827
+ ? jacksonFormatMapper
828
+ : new JaxbXmlFormatMapper ( legacyFormat );
823
829
}
824
830
);
825
831
}
826
832
833
+ private static FormatMapper formatMapper (Object setting , StrategySelector selector , Callable <FormatMapper > defaultResolver ) {
834
+ return selector .resolveDefaultableStrategy ( FormatMapper .class , setting , defaultResolver );
835
+ }
836
+
827
837
828
838
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
829
839
// SessionFactoryOptionsState
@@ -1601,8 +1611,8 @@ public void disableJtaTransactionAccess() {
1601
1611
}
1602
1612
1603
1613
public SessionFactoryOptions buildOptions () {
1604
- if ( jpaCompliance instanceof MutableJpaCompliance ) {
1605
- jpaCompliance = mutableJpaCompliance () .immutableCopy ();
1614
+ if ( jpaCompliance instanceof MutableJpaCompliance mutableJpaCompliance ) {
1615
+ jpaCompliance = mutableJpaCompliance .immutableCopy ();
1606
1616
}
1607
1617
return this ;
1608
1618
}
@@ -1692,7 +1702,7 @@ private Map<String, Object> initializeDefaultSessionProperties(ConfigurationServ
1692
1702
LegacySpecHints .HINT_JAVAEE_QUERY_TIMEOUT
1693
1703
};
1694
1704
1695
- final Map < String , Object > configurationServiceSettings = configurationService .getSettings ();
1705
+ final var configurationServiceSettings = configurationService .getSettings ();
1696
1706
for ( String key : ENTITY_MANAGER_SPECIFIC_PROPERTIES ) {
1697
1707
if ( configurationServiceSettings .containsKey ( key ) ) {
1698
1708
settings .put ( key , configurationServiceSettings .get ( key ) );
0 commit comments