7
7
import java .lang .annotation .Annotation ;
8
8
import java .lang .reflect .InvocationTargetException ;
9
9
import java .lang .reflect .Member ;
10
- import java .util .ArrayList ;
11
10
import java .util .HashMap ;
12
11
import java .util .List ;
13
12
import java .util .Locale ;
46
45
import org .hibernate .internal .util .StringHelper ;
47
46
import org .hibernate .internal .util .collections .CollectionHelper ;
48
47
import org .hibernate .mapping .GeneratorCreator ;
48
+ import org .hibernate .mapping .KeyValue ;
49
49
import org .hibernate .mapping .PersistentClass ;
50
50
import org .hibernate .mapping .SimpleValue ;
51
51
import org .hibernate .models .spi .AnnotationTarget ;
@@ -283,22 +283,6 @@ private static GenerationType interpretGenerationType(GeneratedValue generatedVa
283
283
return strategy == null ? AUTO : strategy ;
284
284
}
285
285
286
- /**
287
- * Collects definition objects for all generators defined using any of {@link TableGenerator},
288
- * {@link SequenceGenerator}, and {@link GenericGenerator} on the given annotated element.
289
- */
290
- public static List <IdentifierGeneratorDefinition > collectIdGeneratorDefinitions (
291
- AnnotationTarget annotatedElement ,
292
- MetadataBuildingContext context ) {
293
- final ArrayList <IdentifierGeneratorDefinition > definitions = new ArrayList <>();
294
- visitIdGeneratorDefinitions (
295
- annotatedElement ,
296
- definitions ::add ,
297
- context
298
- );
299
- return definitions ;
300
- }
301
-
302
286
public static void visitIdGeneratorDefinitions (
303
287
AnnotationTarget annotatedElement ,
304
288
Consumer <IdentifierGeneratorDefinition > consumer ,
@@ -693,7 +677,7 @@ public static void callConfigure(
693
677
Generator generator ,
694
678
Map <String , Object > configuration ,
695
679
SimpleValue identifierValue ) {
696
- if ( generator instanceof final Configurable configurable ) {
680
+ if ( generator instanceof Configurable configurable ) {
697
681
final Properties parameters = collectParameters (
698
682
identifierValue ,
699
683
creationContext .getDatabase ().getDialect (),
@@ -702,6 +686,12 @@ public static void callConfigure(
702
686
);
703
687
configurable .configure ( creationContext , parameters );
704
688
}
689
+ if ( generator instanceof ExportableProducer exportableProducer ) {
690
+ exportableProducer .registerExportables ( creationContext .getDatabase () );
691
+ }
692
+ if ( generator instanceof Configurable configurable ) {
693
+ configurable .initialize ( creationContext .getSqlStringGenerationContext () );
694
+ }
705
695
}
706
696
707
697
private static void checkIdGeneratorTiming (Class <? extends Annotation > annotationType , Generator generator ) {
@@ -726,19 +716,20 @@ private static void createIdGenerator(
726
716
// NOTE: `generatedValue` is never null here
727
717
final GeneratedValue generatedValue = castNonNull ( idMember .getDirectAnnotationUsage ( GeneratedValue .class ) );
728
718
719
+ final InFlightMetadataCollector metadataCollector = context .getMetadataCollector ();
729
720
if ( isGlobalGeneratorNameGlobal ( context ) ) {
730
721
// process and register any generators defined on the member.
731
722
// according to JPA these are also global.
732
- context . getMetadataCollector () .getGlobalRegistrations ().as ( GlobalRegistrar .class ).collectIdGenerators ( idMember );
733
- context . getMetadataCollector () .addSecondPass ( new StrictIdGeneratorResolverSecondPass (
723
+ metadataCollector .getGlobalRegistrations ().as ( GlobalRegistrar .class ).collectIdGenerators ( idMember );
724
+ metadataCollector .addSecondPass ( new StrictIdGeneratorResolverSecondPass (
734
725
persistentClass ,
735
726
idValue ,
736
727
idMember ,
737
728
context
738
729
) );
739
730
}
740
731
else {
741
- context . getMetadataCollector () .addSecondPass ( new IdGeneratorResolverSecondPass (
732
+ metadataCollector .addSecondPass ( new IdGeneratorResolverSecondPass (
742
733
persistentClass ,
743
734
idValue ,
744
735
idMember ,
@@ -750,7 +741,6 @@ private static void createIdGenerator(
750
741
751
742
public static void createGeneratorFrom (
752
743
IdentifierGeneratorDefinition defaultedGenerator ,
753
- MemberDetails idMember ,
754
744
SimpleValue idValue ,
755
745
Map <String , Object > configuration ,
756
746
MetadataBuildingContext context ) {
@@ -766,43 +756,29 @@ public static void createGeneratorFrom(
766
756
if ( identifierGenerator instanceof IdentityGenerator ) {
767
757
idValue .setColumnToIdentity ();
768
758
}
769
-
770
- if ( identifierGenerator instanceof ExportableProducer exportableProducer ) {
771
- exportableProducer .registerExportables ( creationContext .getDatabase () );
772
- }
773
-
774
759
return identifierGenerator ;
775
760
} );
776
761
}
777
762
778
763
779
764
public static void createGeneratorFrom (
780
765
IdentifierGeneratorDefinition defaultedGenerator ,
781
- MemberDetails idMember ,
782
766
SimpleValue idValue ,
783
- PersistentClass persistentClass ,
784
767
MetadataBuildingContext context ) {
785
768
createGeneratorFrom (
786
769
defaultedGenerator ,
787
- idMember ,
788
770
idValue ,
789
- buildConfigurationMap ( defaultedGenerator , idValue , persistentClass ),
771
+ buildConfigurationMap ( idValue ),
790
772
context
791
773
);
792
774
}
793
775
794
- public static Map <String , Object > buildConfigurationMap (
795
- IdentifierGeneratorDefinition defaultedGenerator ,
796
- SimpleValue idValue ,
797
- PersistentClass persistentClass ) {
776
+ private static Map <String , Object > buildConfigurationMap (KeyValue idValue ) {
798
777
final Map <String ,Object > configuration = new HashMap <>();
799
-
800
778
configuration .put ( PersistentIdentifierGenerator .TABLE , idValue .getTable ().getName () );
801
-
802
779
if ( idValue .getColumnSpan () == 1 ) {
803
- configuration .put ( PersistentIdentifierGenerator .PK , idValue .getColumns ().get ( 0 ).getName () );
780
+ configuration .put ( PersistentIdentifierGenerator .PK , idValue .getColumns ().get (0 ).getName () );
804
781
}
805
-
806
782
return configuration ;
807
783
}
808
784
@@ -941,15 +917,12 @@ static GeneratorCreator createValueGeneratorFromAnnotations(
941
917
final List <? extends Annotation > generatorAnnotations =
942
918
property .getMetaAnnotated ( ValueGenerationType .class ,
943
919
context .getMetadataCollector ().getSourceModelBuildingContext () );
944
- switch ( generatorAnnotations .size () ) {
945
- case 0 :
946
- return null ;
947
- case 1 :
948
- return generatorCreator ( property , generatorAnnotations .get (0 ), beanContainer ( context ) );
949
- default :
950
- throw new AnnotationException ( "Property '" + qualify ( holder .getPath (), propertyName )
951
- + "' has too many generator annotations: " + generatorAnnotations );
952
- }
920
+ return switch ( generatorAnnotations .size () ) {
921
+ case 0 -> null ;
922
+ case 1 -> generatorCreator ( property , generatorAnnotations .get (0 ), beanContainer ( context ) );
923
+ default -> throw new AnnotationException ( "Property '" + qualify ( holder .getPath (), propertyName )
924
+ + "' has too many generator annotations: " + generatorAnnotations );
925
+ };
953
926
}
954
927
955
928
public static void applyIfNotEmpty (String name , String value , BiConsumer <String ,String > consumer ) {
0 commit comments