87
87
88
88
import jakarta .persistence .AttributeConverter ;
89
89
90
+ import static java .util .Comparator .comparingInt ;
90
91
import static org .hibernate .internal .util .config .ConfigurationHelper .getPreferredSqlTypeCodeForArray ;
91
92
import static org .hibernate .internal .util .config .ConfigurationHelper .getPreferredSqlTypeCodeForDuration ;
92
93
import static org .hibernate .internal .util .config .ConfigurationHelper .getPreferredSqlTypeCodeForInstant ;
95
96
/**
96
97
* Represents the process of transforming a {@link MetadataSources}
97
98
* reference into a {@link org.hibernate.boot.Metadata} reference. Allows for 2 different process paradigms:<ul>
98
- * <li>
99
- * Single step : as defined by the {@link #build} method; internally leverages the 2-step paradigm
100
- * </li>
101
- * <li>
102
- * Two step : a first step coordinates resource scanning and some other preparation work; a second step
103
- * builds the {@link org.hibernate.boot.Metadata}. A hugely important distinction in the need for the
104
- * steps is that the first phase should strive to not load user entity/component classes so that we can still
105
- * perform enhancement on them later. This approach caters to the 2-phase bootstrap we use in regards
106
- * to WildFly Hibernate-JPA integration. The first step is defined by {@link #prepare} which returns
107
- * a {@link ManagedResources} instance. The second step is defined by calling
108
- * {@link #complete}
109
- * </li>
99
+ * <li>
100
+ * Single step : as defined by the {@link #build} method; internally leverages the 2-step paradigm
101
+ * </li>
102
+ * <li>
103
+ * Two step : a first step coordinates resource scanning and some other preparation work; a second step
104
+ * builds the {@link org.hibernate.boot.Metadata}. A hugely important distinction in the need for the
105
+ * steps is that the first phase should strive to not load user entity/component classes so that we can still
106
+ * perform enhancement on them later. This approach caters to the 2-phase bootstrap we use in regards
107
+ * to WildFly Hibernate-JPA integration. The first step is defined by {@link #prepare} which returns
108
+ * a {@link ManagedResources} instance. The second step is defined by calling
109
+ * {@link #complete}
110
+ * </li>
110
111
* </ul>
111
112
*
112
113
* @author Steve Ebersole
@@ -199,7 +200,7 @@ public static MetadataImplementor complete(
199
200
200
201
final MetadataSourceProcessor processor = new MetadataSourceProcessor () {
201
202
private final MetadataSourceProcessor hbmProcessor =
202
- options .isXmlMappingEnabled ()
203
+ options .isXmlMappingEnabled ()
203
204
? new HbmMetadataSourceProcessorImpl ( managedResources , rootMetadataBuildingContext )
204
205
: new NoOpMetadataSourceProcessorImpl ();
205
206
@@ -338,8 +339,19 @@ public void finishUp() {
338
339
339
340
processor .finishUp ();
340
341
341
- processAdditionalMappingContributions ( metadataCollector , options , classLoaderService , rootMetadataBuildingContext );
342
- processAdditionalJaxbMappingProducer ( metadataCollector , options , jandexView , classLoaderService , rootMetadataBuildingContext );
342
+ processAdditionalMappingContributions (
343
+ metadataCollector ,
344
+ options ,
345
+ classLoaderService ,
346
+ rootMetadataBuildingContext
347
+ );
348
+ processAdditionalJaxbMappingProducer (
349
+ metadataCollector ,
350
+ options ,
351
+ jandexView ,
352
+ classLoaderService ,
353
+ rootMetadataBuildingContext
354
+ );
343
355
344
356
applyExtraQueryImports ( managedResources , metadataCollector );
345
357
@@ -379,7 +391,8 @@ public boolean transformHbmMappings() {
379
391
rootMetadataBuildingContext
380
392
);
381
393
382
- final Collection <AdditionalMappingContributor > additionalMappingContributors = classLoaderService .loadJavaServices ( AdditionalMappingContributor .class );
394
+ final Collection <AdditionalMappingContributor > additionalMappingContributors = classLoaderService .loadJavaServices (
395
+ AdditionalMappingContributor .class );
383
396
additionalMappingContributors .forEach ( (contributor ) -> {
384
397
contributions .setCurrentContributor ( contributor .getContributorName () );
385
398
try {
@@ -450,7 +463,7 @@ public void contributeBinding(InputStream xmlStream) {
450
463
451
464
@ Override
452
465
public void contributeBinding (JaxbEntityMappings mappingJaxbBinding ) {
453
- if ( ! options .isXmlMappingEnabled () ) {
466
+ if ( !options .isXmlMappingEnabled () ) {
454
467
return ;
455
468
}
456
469
@@ -462,7 +475,7 @@ public void contributeBinding(JaxbEntityMappings mappingJaxbBinding) {
462
475
463
476
@ Override
464
477
public void contributeBinding (JaxbHbmHibernateMapping hbmJaxbBinding ) {
465
- if ( ! options .isXmlMappingEnabled () ) {
478
+ if ( !options .isXmlMappingEnabled () ) {
466
479
return ;
467
480
}
468
481
@@ -527,7 +540,8 @@ private static void processAdditionalJaxbMappingProducer(
527
540
ClassLoaderService classLoaderService ,
528
541
MetadataBuildingContextRootImpl rootMetadataBuildingContext ) {
529
542
if ( options .isXmlMappingEnabled () ) {
530
- final Iterable <AdditionalJaxbMappingProducer > producers = classLoaderService .loadJavaServices ( AdditionalJaxbMappingProducer .class );
543
+ final Iterable <AdditionalJaxbMappingProducer > producers = classLoaderService .loadJavaServices (
544
+ AdditionalJaxbMappingProducer .class );
531
545
if ( producers != null ) {
532
546
final EntityHierarchyBuilder hierarchyBuilder = new EntityHierarchyBuilder ();
533
547
final MappingBinder mappingBinder = new MappingBinder (
@@ -597,7 +611,7 @@ private static void handleTypes(
597
611
MetadataBuildingOptions options ,
598
612
InFlightMetadataCollector metadataCollector ) {
599
613
final ClassLoaderService classLoaderService =
600
- options .getServiceRegistry ().requireService (ClassLoaderService .class );
614
+ options .getServiceRegistry ().requireService ( ClassLoaderService .class );
601
615
602
616
final TypeConfiguration typeConfiguration = bootstrapContext .getTypeConfiguration ();
603
617
final StandardServiceRegistry serviceRegistry = bootstrapContext .getServiceRegistry ();
@@ -631,7 +645,7 @@ public void contributeType(CompositeUserType<?> type) {
631
645
basicTypeRegistry .addTypeReferenceRegistrationKey (
632
646
StandardBasicTypes .BINARY_WRAPPER .getName (),
633
647
Byte [].class .getName (), "Byte[]"
634
- );
648
+ );
635
649
}
636
650
637
651
// add Dialect contributed types
@@ -642,7 +656,7 @@ public void contributeType(CompositeUserType<?> type) {
642
656
final JdbcType dialectArrayDescriptor = jdbcTypeRegistry .findDescriptor ( SqlTypes .ARRAY );
643
657
644
658
// add TypeContributor contributed types.
645
- for ( TypeContributor contributor : classLoaderService . loadJavaServices ( TypeContributor . class ) ) {
659
+ for ( TypeContributor contributor : sortedTypeContributors ( classLoaderService ) ) {
646
660
contributor .contribute ( typeContributions , options .getServiceRegistry () );
647
661
}
648
662
@@ -749,6 +763,17 @@ public void contributeType(CompositeUserType<?> type) {
749
763
}
750
764
}
751
765
766
+ private static List <TypeContributor > sortedTypeContributors (
767
+ ClassLoaderService classLoaderService ) {
768
+ Collection <TypeContributor > typeContributors = classLoaderService .loadJavaServices ( TypeContributor .class );
769
+ List <TypeContributor > contributors = new ArrayList <>( typeContributors );
770
+ contributors .sort (
771
+ comparingInt ( TypeContributor ::ordinal )
772
+ .thenComparing ( a -> a .getClass ().getCanonicalName () )
773
+ );
774
+ return contributors ;
775
+ }
776
+
752
777
private static void adaptToPreferredSqlTypeCode (
753
778
JdbcTypeRegistry jdbcTypeRegistry ,
754
779
JdbcType dialectUuidDescriptor ,
@@ -830,7 +855,9 @@ private static void adaptTimestampTypesToDefaultTimeZoneStorage(
830
855
);
831
856
}
832
857
833
- private static JdbcType getTimeWithTimeZoneOverride (MetadataBuildingOptions options , JdbcTypeRegistry jdbcTypeRegistry ) {
858
+ private static JdbcType getTimeWithTimeZoneOverride (
859
+ MetadataBuildingOptions options ,
860
+ JdbcTypeRegistry jdbcTypeRegistry ) {
834
861
switch ( options .getDefaultTimeZoneStorage () ) {
835
862
case NORMALIZE :
836
863
// For NORMALIZE, we replace the standard types that use TIME_WITH_TIMEZONE to use TIME
@@ -843,7 +870,9 @@ private static JdbcType getTimeWithTimeZoneOverride(MetadataBuildingOptions opti
843
870
}
844
871
}
845
872
846
- private static JdbcType getTimestampWithTimeZoneOverride (MetadataBuildingOptions options , JdbcTypeRegistry jdbcTypeRegistry ) {
873
+ private static JdbcType getTimestampWithTimeZoneOverride (
874
+ MetadataBuildingOptions options ,
875
+ JdbcTypeRegistry jdbcTypeRegistry ) {
847
876
switch ( options .getDefaultTimeZoneStorage () ) {
848
877
case NORMALIZE :
849
878
// For NORMALIZE, we replace the standard types that use TIMESTAMP_WITH_TIMEZONE to use TIMESTAMP
0 commit comments