@@ -79,6 +79,7 @@ public class CurrentTimestampGeneration implements BeforeExecutionGenerator, OnE
79
79
public static final String CLOCK_SETTING_NAME = "hibernate.testing.clock" ;
80
80
81
81
private final EnumSet <EventType > eventTypes ;
82
+ private final boolean allowMutation ;
82
83
83
84
private final CurrentTimestampGeneratorDelegate delegate ;
84
85
private static final Map <Class <?>, BiFunction <@ Nullable Clock , Integer , CurrentTimestampGeneratorDelegate >> GENERATOR_PRODUCERS = new HashMap <>();
@@ -185,16 +186,19 @@ public class CurrentTimestampGeneration implements BeforeExecutionGenerator, OnE
185
186
public CurrentTimestampGeneration (CurrentTimestamp annotation , Member member , GeneratorCreationContext context ) {
186
187
delegate = getGeneratorDelegate ( annotation .source (), member , context );
187
188
eventTypes = fromArray ( annotation .event () );
189
+ allowMutation = annotation .allowMutation ();
188
190
}
189
191
190
192
public CurrentTimestampGeneration (CreationTimestamp annotation , Member member , GeneratorCreationContext context ) {
191
193
delegate = getGeneratorDelegate ( annotation .source (), member , context );
192
194
eventTypes = INSERT_ONLY ;
195
+ allowMutation = false ;
193
196
}
194
197
195
198
public CurrentTimestampGeneration (UpdateTimestamp annotation , Member member , GeneratorCreationContext context ) {
196
199
delegate = getGeneratorDelegate ( annotation .source (), member , context );
197
200
eventTypes = INSERT_AND_UPDATE ;
201
+ allowMutation = false ;
198
202
}
199
203
200
204
private static CurrentTimestampGeneratorDelegate getGeneratorDelegate (
@@ -216,24 +220,27 @@ static CurrentTimestampGeneratorDelegate getGeneratorDelegate(
216
220
context .getDatabase ().getDialect (),
217
221
basicValue .getMetadata ()
218
222
);
219
- final Clock baseClock = context .getServiceRegistry ()
220
- .requireService ( ConfigurationService .class )
221
- .getSetting ( CLOCK_SETTING_NAME , value -> (Clock ) value );
222
- final Key key = new Key ( propertyType , baseClock , size .getPrecision () == null ? 0 : size .getPrecision () );
223
- final CurrentTimestampGeneratorDelegate delegate = GENERATOR_DELEGATES .get ( key );
223
+ final Clock baseClock =
224
+ context .getServiceRegistry ().requireService ( ConfigurationService .class )
225
+ .getSetting ( CLOCK_SETTING_NAME , value -> (Clock ) value );
226
+ final Key key =
227
+ new Key ( propertyType , baseClock ,
228
+ size .getPrecision () == null ? 0 : size .getPrecision () );
229
+ final var delegate = GENERATOR_DELEGATES .get ( key );
224
230
if ( delegate != null ) {
225
231
return delegate ;
226
232
}
227
- final BiFunction <@ Nullable Clock , Integer , CurrentTimestampGeneratorDelegate > producer = GENERATOR_PRODUCERS .get ( key .clazz );
228
- if ( producer == null ) {
229
- return null ;
233
+ else {
234
+ final var producer = GENERATOR_PRODUCERS .get ( key .clazz );
235
+ if ( producer == null ) {
236
+ return null ;
237
+ }
238
+ else {
239
+ final var generatorDelegate = producer .apply ( key .clock , key .precision );
240
+ final var old = GENERATOR_DELEGATES .putIfAbsent ( key , generatorDelegate );
241
+ return old != null ? old : generatorDelegate ;
242
+ }
230
243
}
231
- final CurrentTimestampGeneratorDelegate generatorDelegate = producer .apply ( key .clock , key .precision );
232
- final CurrentTimestampGeneratorDelegate old = GENERATOR_DELEGATES .putIfAbsent (
233
- key ,
234
- generatorDelegate
235
- );
236
- return old != null ? old : generatorDelegate ;
237
244
case DB :
238
245
return null ;
239
246
default :
@@ -255,6 +262,11 @@ public EnumSet<EventType> getEventTypes() {
255
262
return eventTypes ;
256
263
}
257
264
265
+ @ Override
266
+ public boolean allowMutation () {
267
+ return allowMutation ;
268
+ }
269
+
258
270
@ Override
259
271
public Object generate (SharedSessionContractImplementor session , Object owner , Object currentValue , EventType eventType ) {
260
272
return delegate .generate ();
@@ -276,7 +288,8 @@ public String[] getReferencedColumnValues(Dialect dialect) {
276
288
}
277
289
278
290
interface CurrentTimestampGeneratorDelegate {
279
- // Left out the Generator params, they're not used anyway. Since this is purely internal, this can be changed if needed
291
+ // Left out the Generator params, they're not used anyway.
292
+ // Since this is purely internal, this can be changed if needed
280
293
Object generate ();
281
294
}
282
295
0 commit comments