Skip to content

Commit

Permalink
[#1517] Fix DefaultReactiveDeleteEventListener
Browse files Browse the repository at this point in the history
It was executing some operations in parallel because the stages were
created in ahead of time.
  • Loading branch information
DavideD committed Mar 29, 2023
1 parent 5277b33 commit 58e5bac
Showing 1 changed file with 49 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -339,59 +339,55 @@ protected CompletionStage<Void> deleteEntity(
persistenceContext.setEntryStatus( entityEntry, Status.DELETED );
final EntityKey key = session.generateEntityKey( entityEntry.getId(), persister );

CompletionStage<Void> beforeDelete = cascadeBeforeDelete( session, persister, entity, entityEntry, transientEntities );

CompletionStage<Void> nullifyAndAction = new ForeignKeys.Nullifier(
entity,
true,
false,
session,
persister
).nullifyTransientReferences( entityEntry.getDeletedState() )
.thenAccept( v -> {
new Nullability( session ).checkNullability(
entityEntry.getDeletedState(),
persister,
Nullability.NullabilityCheckType.DELETE
);
persistenceContext.registerNullifiableEntityKey( key );

ReactiveActionQueue actionQueue = actionQueue( session );

if ( isOrphanRemovalBeforeUpdates ) {
// TODO: The removeOrphan concept is a temporary "hack" for HHH-6484. This should be removed once action/task
// ordering is improved.
actionQueue.addAction(
new ReactiveOrphanRemovalAction(
entityEntry.getId(),
deletedState,
version,
entity,
persister,
isCascadeDeleteEnabled,
session
)
);
}
else {
// Ensures that containing deletions happen before sub-deletions
actionQueue.addAction(
new ReactiveEntityDeleteAction(
entityEntry.getId(),
deletedState,
version,
entity,
persister,
isCascadeDeleteEnabled,
session
)
);
}
} );

CompletionStage<Void> afterDelete = cascadeAfterDelete( session, persister, entity, transientEntities );

return beforeDelete.thenCompose( v -> nullifyAndAction ).thenCompose( v -> afterDelete );
return cascadeBeforeDelete( session, persister, entity, entityEntry, transientEntities )
.thenCompose( v -> new ForeignKeys.Nullifier(
entity,
true,
false,
session,
persister
).nullifyTransientReferences( entityEntry.getDeletedState() )
.thenAccept( vv -> {
new Nullability( session ).checkNullability(
entityEntry.getDeletedState(),
persister,
Nullability.NullabilityCheckType.DELETE
);
persistenceContext.registerNullifiableEntityKey( key );

ReactiveActionQueue actionQueue = actionQueue( session );

if ( isOrphanRemovalBeforeUpdates ) {
// TODO: The removeOrphan concept is a temporary "hack" for HHH-6484. This should be removed once action/task
// ordering is improved.
actionQueue.addAction(
new ReactiveOrphanRemovalAction(
entityEntry.getId(),
deletedState,
version,
entity,
persister,
isCascadeDeleteEnabled,
session
)
);
}
else {
// Ensures that containing deletions happen before sub-deletions
actionQueue.addAction(
new ReactiveEntityDeleteAction(
entityEntry.getId(),
deletedState,
version,
entity,
persister,
isCascadeDeleteEnabled,
session
)
);
}
} ) )
.thenCompose( v -> cascadeAfterDelete( session, persister, entity, transientEntities ) );
}

private ReactiveActionQueue actionQueue(EventSource session) {
Expand Down

0 comments on commit 58e5bac

Please sign in to comment.