@@ -241,16 +241,8 @@ public CompletionStage<Void> addAction(ReactiveEntityInsertAction action) {
241241 return addInsertAction ( action );
242242 }
243243
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 )
254246 .thenCompose ( v -> insert .reactiveFindNonNullableTransientEntities () )
255247 .thenCompose ( nonNullables -> {
256248 if ( nonNullables == null ) {
@@ -270,40 +262,51 @@ private CompletionStage<Void> addInsertAction( ReactiveEntityInsertAction insert
270262 } );
271263 }
272264
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+
273278 private CompletionStage <Void > addResolvedEntityInsertAction (ReactiveEntityInsertAction insert ) {
274- CompletionStage <Void > ret ;
275279 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 -> {
279283 LOG .debug ( "Executing identity-insert immediately" );
280284 return execute ( insert );
281- } );
285+ } )
286+ .thenCompose ( v -> postResolvedEntityInsertAction ( insert ) );
282287 }
283288 else {
284289 LOG .trace ( "Adding resolved non-early insert action." );
285290 OrderedActions .EntityInsertAction .ensureInitialized ( this );
286291 this .insertions .add ( new ReactiveEntityInsertActionHolder ( insert ) );
287- ret = voidFuture ( );
292+ return postResolvedEntityInsertAction ( insert );
288293 }
294+ }
289295
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 (
298301 unresolvedInsertions .resolveDependentActions ( insert .getInstance (), session .getSharedContract () ),
299302 resolvedAction -> addResolvedEntityInsertAction ( (ReactiveEntityRegularInsertAction ) resolvedAction )
300- ) ) ;
303+ );
301304 }
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 );
307310 }
308311
309312 private static String [] convertTimestampSpaces (Serializable [] spaces ) {
0 commit comments