77import  java .lang .annotation .Annotation ;
88import  java .lang .reflect .InvocationTargetException ;
99import  java .lang .reflect .Member ;
10- import  java .util .ArrayList ;
1110import  java .util .HashMap ;
1211import  java .util .List ;
1312import  java .util .Locale ;
4645import  org .hibernate .internal .util .StringHelper ;
4746import  org .hibernate .internal .util .collections .CollectionHelper ;
4847import  org .hibernate .mapping .GeneratorCreator ;
48+ import  org .hibernate .mapping .KeyValue ;
4949import  org .hibernate .mapping .PersistentClass ;
5050import  org .hibernate .mapping .SimpleValue ;
5151import  org .hibernate .models .spi .AnnotationTarget ;
@@ -283,22 +283,6 @@ private static GenerationType interpretGenerationType(GeneratedValue generatedVa
283283		return  strategy  == null  ? AUTO  : strategy ;
284284	}
285285
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- 
302286	public  static  void  visitIdGeneratorDefinitions (
303287			AnnotationTarget  annotatedElement ,
304288			Consumer <IdentifierGeneratorDefinition > consumer ,
@@ -693,7 +677,7 @@ public static void callConfigure(
693677			Generator  generator ,
694678			Map <String , Object > configuration ,
695679			SimpleValue  identifierValue ) {
696- 		if  ( generator  instanceof  final   Configurable  configurable  ) {
680+ 		if  ( generator  instanceof  Configurable  configurable  ) {
697681			final  Properties  parameters  = collectParameters (
698682					identifierValue ,
699683					creationContext .getDatabase ().getDialect (),
@@ -702,6 +686,12 @@ public static void callConfigure(
702686			);
703687			configurable .configure ( creationContext , parameters  );
704688		}
689+ 		if  ( generator  instanceof  ExportableProducer  exportableProducer  ) {
690+ 			exportableProducer .registerExportables ( creationContext .getDatabase () );
691+ 		}
692+ 		if  ( generator  instanceof  Configurable  configurable  ) {
693+ 			configurable .initialize ( creationContext .getSqlStringGenerationContext () );
694+ 		}
705695	}
706696
707697	private  static  void  checkIdGeneratorTiming (Class <? extends  Annotation > annotationType , Generator  generator ) {
@@ -726,19 +716,20 @@ private static void createIdGenerator(
726716		// NOTE: `generatedValue` is never null here 
727717		final  GeneratedValue  generatedValue  = castNonNull ( idMember .getDirectAnnotationUsage ( GeneratedValue .class  ) );
728718
719+ 		final  InFlightMetadataCollector  metadataCollector  = context .getMetadataCollector ();
729720		if  ( isGlobalGeneratorNameGlobal ( context  ) ) {
730721			// process and register any generators defined on the member. 
731722			// 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 (
734725					persistentClass ,
735726					idValue ,
736727					idMember ,
737728					context 
738729			) );
739730		}
740731		else  {
741- 			context . getMetadataCollector () .addSecondPass ( new  IdGeneratorResolverSecondPass (
732+ 			metadataCollector .addSecondPass ( new  IdGeneratorResolverSecondPass (
742733					persistentClass ,
743734					idValue ,
744735					idMember ,
@@ -750,7 +741,6 @@ private static void createIdGenerator(
750741
751742	public  static  void  createGeneratorFrom (
752743			IdentifierGeneratorDefinition  defaultedGenerator ,
753- 			MemberDetails  idMember ,
754744			SimpleValue  idValue ,
755745			Map <String , Object > configuration ,
756746			MetadataBuildingContext  context ) {
@@ -766,43 +756,29 @@ public static void createGeneratorFrom(
766756			if  ( identifierGenerator  instanceof  IdentityGenerator ) {
767757				idValue .setColumnToIdentity ();
768758			}
769- 
770- 			if  ( identifierGenerator  instanceof  ExportableProducer  exportableProducer  ) {
771- 				exportableProducer .registerExportables ( creationContext .getDatabase () );
772- 			}
773- 
774759			return  identifierGenerator ;
775760		} );
776761	}
777762
778763
779764	public  static  void  createGeneratorFrom (
780765			IdentifierGeneratorDefinition  defaultedGenerator ,
781- 			MemberDetails  idMember ,
782766			SimpleValue  idValue ,
783- 			PersistentClass  persistentClass ,
784767			MetadataBuildingContext  context ) {
785768		createGeneratorFrom (
786769				defaultedGenerator ,
787- 				idMember ,
788770				idValue ,
789- 				buildConfigurationMap ( defaultedGenerator ,  idValue ,  persistentClass  ),
771+ 				buildConfigurationMap ( idValue  ),
790772				context 
791773		);
792774	}
793775
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 ) {
798777		final  Map <String ,Object > configuration  = new  HashMap <>();
799- 
800778		configuration .put ( PersistentIdentifierGenerator .TABLE , idValue .getTable ().getName () );
801- 
802779		if  ( idValue .getColumnSpan () == 1  ) {
803- 			configuration .put ( PersistentIdentifierGenerator .PK , idValue .getColumns ().get (  0 ).getName () );
780+ 			configuration .put ( PersistentIdentifierGenerator .PK , idValue .getColumns ().get (0 ).getName () );
804781		}
805- 
806782		return  configuration ;
807783	}
808784
@@ -941,15 +917,12 @@ static GeneratorCreator createValueGeneratorFromAnnotations(
941917		final  List <? extends  Annotation > generatorAnnotations  =
942918				property .getMetaAnnotated ( ValueGenerationType .class ,
943919						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+ 		};
953926	}
954927
955928	public  static  void  applyIfNotEmpty (String  name , String  value , BiConsumer <String ,String > consumer ) {
0 commit comments