@@ -241,16 +241,8 @@ public CompletionStage<Void> addAction(ReactiveEntityInsertAction action) {
241
241
return addInsertAction ( action );
242
242
}
243
243
244
- private CompletionStage <Void > addInsertAction ( ReactiveEntityInsertAction insert ) {
245
- CompletionStage <Void > ret = voidFuture ();
246
- if ( insert .isEarlyInsert () ) {
247
- // For early inserts, must execute inserts before finding non-nullable transient entities.
248
- // TODO: find out why this is necessary
249
- LOG .tracev ( "Executing inserts before finding non-nullable transient entities for early insert: [{0}]" , insert );
250
- ret = ret .thenCompose ( v -> executeInserts () );
251
- }
252
-
253
- return ret
244
+ private CompletionStage <Void > addInsertAction (ReactiveEntityInsertAction insert ) {
245
+ return executeEarlyInsertsIfRequired ( insert )
254
246
.thenCompose ( v -> insert .reactiveFindNonNullableTransientEntities () )
255
247
.thenCompose ( nonNullables -> {
256
248
if ( nonNullables == null ) {
@@ -270,40 +262,51 @@ private CompletionStage<Void> addInsertAction( ReactiveEntityInsertAction insert
270
262
} );
271
263
}
272
264
265
+ private CompletionStage <Void > executeEarlyInsertsIfRequired (ReactiveEntityInsertAction insert ) {
266
+ if ( insert .isEarlyInsert () ) {
267
+ // For early inserts, must execute inserts before finding non-nullable transient entities.
268
+ // TODO: find out why this is necessary
269
+ LOG .tracev (
270
+ "Executing inserts before finding non-nullable transient entities for early insert: [{0}]" ,
271
+ insert
272
+ );
273
+ return executeInserts ();
274
+ }
275
+ return voidFuture ();
276
+ }
277
+
273
278
private CompletionStage <Void > addResolvedEntityInsertAction (ReactiveEntityInsertAction insert ) {
274
- CompletionStage <Void > ret ;
275
279
if ( insert .isEarlyInsert () ) {
276
- LOG . trace ( "Executing insertions before resolved early-insert" );
277
- ret = executeInserts ()
278
- .thenCompose ( v -> {
280
+ // For early inserts, must execute inserts before finding non-nullable transient entities.
281
+ LOG . tracev ( "Executing inserts before finding non-nullable transient entities for early insert: [{0}]" , insert );
282
+ return executeInserts () .thenCompose ( v -> {
279
283
LOG .debug ( "Executing identity-insert immediately" );
280
284
return execute ( insert );
281
- } );
285
+ } )
286
+ .thenCompose ( v -> postResolvedEntityInsertAction ( insert ) );
282
287
}
283
288
else {
284
289
LOG .trace ( "Adding resolved non-early insert action." );
285
290
OrderedActions .EntityInsertAction .ensureInitialized ( this );
286
291
this .insertions .add ( new ReactiveEntityInsertActionHolder ( insert ) );
287
- ret = voidFuture ( );
292
+ return postResolvedEntityInsertAction ( insert );
288
293
}
294
+ }
289
295
290
- return ret .thenCompose ( v -> {
291
- if ( !insert .isVeto () ) {
292
- CompletionStage <Void > comp = insert .reactiveMakeEntityManaged ();
293
- if ( unresolvedInsertions == null ) {
294
- return comp ;
295
- }
296
- else {
297
- return comp .thenCompose ( vv -> loop (
296
+ private CompletionStage <Void > postResolvedEntityInsertAction (ReactiveEntityInsertAction insert ) {
297
+ if ( !insert .isVeto () ) {
298
+ return insert .reactiveMakeEntityManaged ().thenCompose ( v -> {
299
+ if ( unresolvedInsertions != null ) {
300
+ return loop (
298
301
unresolvedInsertions .resolveDependentActions ( insert .getInstance (), session .getSharedContract () ),
299
302
resolvedAction -> addResolvedEntityInsertAction ( (ReactiveEntityRegularInsertAction ) resolvedAction )
300
- ) ) ;
303
+ );
301
304
}
302
- }
303
- else {
304
- throw new ReactiveEntityActionVetoException ( "The ReactiveEntityInsertAction was vetoed." , insert );
305
- }
306
- } );
305
+ return voidFuture ();
306
+ } );
307
+ }
308
+
309
+ throw new ReactiveEntityActionVetoException ( "The ReactiveEntityInsertAction was vetoed." , insert );
307
310
}
308
311
309
312
private static String [] convertTimestampSpaces (Serializable [] spaces ) {
0 commit comments