10
10
11
11
import org .hibernate .generator .Generator ;
12
12
import org .hibernate .generator .GeneratorCreationContext ;
13
+ import org .hibernate .id .CompositeNestedGeneratedValueGenerator ;
13
14
import org .hibernate .id .Configurable ;
14
15
import org .hibernate .id .IdentifierGenerator ;
15
16
import org .hibernate .id .SelectGenerator ;
18
19
import org .hibernate .id .enhanced .SequenceStyleGenerator ;
19
20
import org .hibernate .id .enhanced .TableGenerator ;
20
21
import org .hibernate .id .enhanced .TableStructure ;
22
+ import org .hibernate .mapping .Component ;
21
23
import org .hibernate .mapping .GeneratorCreator ;
22
24
import org .hibernate .mapping .PersistentClass ;
23
25
import org .hibernate .mapping .SimpleValue ;
24
26
import org .hibernate .metamodel .spi .RuntimeModelCreationContext ;
25
27
import org .hibernate .persister .entity .EntityPersister ;
26
28
import org .hibernate .reactive .id .ReactiveIdentifierGenerator ;
27
29
import org .hibernate .reactive .id .impl .EmulatedSequenceReactiveIdentifierGenerator ;
30
+ import org .hibernate .reactive .id .impl .ReactiveCompositeNestedGeneratedValueGenerator ;
28
31
import org .hibernate .reactive .id .impl .ReactiveGeneratorWrapper ;
29
32
import org .hibernate .reactive .id .impl .ReactiveSequenceIdentifierGenerator ;
30
33
import org .hibernate .reactive .id .impl .TableReactiveIdentifierGenerator ;
@@ -67,12 +70,9 @@ private static Generator buildIdGenerator(
67
70
return existing ;
68
71
}
69
72
else {
70
- SimpleValue identifier = (SimpleValue ) persistentClass .getIdentifier ();
71
- GeneratorCreator customIdGeneratorCreator = identifier .getCustomIdGeneratorCreator ();
72
- identifier .setCustomIdGeneratorCreator ( context -> {
73
- Generator generator = customIdGeneratorCreator .createGenerator ( context );
74
- return augmentWithReactiveGenerator ( generator , context , creationContext );
75
- } );
73
+ final SimpleValue identifier = (SimpleValue ) persistentClass .getIdentifier ();
74
+ setCustomIdGenerator ( persistentClass , creationContext , identifier );
75
+
76
76
final Generator idgenerator = identifier
77
77
// returns the cached Generator if it was already created
78
78
.createGenerator (
@@ -86,12 +86,35 @@ private static Generator buildIdGenerator(
86
86
}
87
87
}
88
88
89
+ private static void setCustomIdGenerator (
90
+ PersistentClass persistentClass ,
91
+ RuntimeModelCreationContext creationContext ,
92
+ SimpleValue identifier ) {
93
+ final GeneratorCreator customIdGeneratorCreator = identifier .getCustomIdGeneratorCreator ();
94
+ if ( identifier instanceof Component component ) {
95
+ final Generator componentIdentifierGenerator = component .createGenerator (
96
+ creationContext .getDialect (),
97
+ persistentClass .getRootClass (),
98
+ persistentClass .getIdentifierProperty (),
99
+ creationContext .getGeneratorSettings ()
100
+ );
101
+ identifier .setCustomIdGeneratorCreator ( context ->
102
+ augmentWithReactiveGenerator ( componentIdentifierGenerator , context , creationContext )
103
+ );
104
+ }
105
+ else {
106
+ identifier .setCustomIdGeneratorCreator ( context ->
107
+ augmentWithReactiveGenerator ( customIdGeneratorCreator .createGenerator ( context ), context , creationContext )
108
+ );
109
+ }
110
+ }
111
+
89
112
public static Generator augmentWithReactiveGenerator (
90
113
Generator generator ,
91
114
GeneratorCreationContext creationContext ,
92
115
RuntimeModelCreationContext runtimeModelCreationContext ) {
93
- if ( generator instanceof SequenceStyleGenerator ) {
94
- final DatabaseStructure structure = ( ( SequenceStyleGenerator ) generator ) .getDatabaseStructure ();
116
+ if ( generator instanceof SequenceStyleGenerator sequenceStyleGenerator ) {
117
+ final DatabaseStructure structure = sequenceStyleGenerator .getDatabaseStructure ();
95
118
if ( structure instanceof TableStructure ) {
96
119
return initialize ( (IdentifierGenerator ) generator , new EmulatedSequenceReactiveIdentifierGenerator ( (TableStructure ) structure , runtimeModelCreationContext ), creationContext );
97
120
}
@@ -100,16 +123,28 @@ public static Generator augmentWithReactiveGenerator(
100
123
}
101
124
throw LOG .unknownStructureType ();
102
125
}
103
- if ( generator instanceof TableGenerator ) {
126
+ if ( generator instanceof TableGenerator tableGenerator ) {
104
127
return initialize (
105
128
(IdentifierGenerator ) generator ,
106
- new TableReactiveIdentifierGenerator ( ( TableGenerator ) generator , runtimeModelCreationContext ),
129
+ new TableReactiveIdentifierGenerator ( tableGenerator , runtimeModelCreationContext ),
107
130
creationContext
108
131
);
109
132
}
110
133
if ( generator instanceof SelectGenerator ) {
111
134
throw LOG .selectGeneratorIsNotSupportedInHibernateReactive ();
112
135
}
136
+ if ( generator instanceof CompositeNestedGeneratedValueGenerator compositeNestedGeneratedValueGenerator ) {
137
+ final ReactiveCompositeNestedGeneratedValueGenerator reactiveCompositeNestedGeneratedValueGenerator = new ReactiveCompositeNestedGeneratedValueGenerator (
138
+ compositeNestedGeneratedValueGenerator ,
139
+ creationContext ,
140
+ runtimeModelCreationContext
141
+ );
142
+ return initialize (
143
+ (IdentifierGenerator ) generator ,
144
+ reactiveCompositeNestedGeneratedValueGenerator ,
145
+ creationContext
146
+ );
147
+ }
113
148
//nothing to do
114
149
return generator ;
115
150
}
0 commit comments