mirror of
https://github.com/hibernate/hibernate-orm
synced 2025-02-10 05:04:52 +00:00
HHH-16602 Dedicated action queue priority for orphan collection removals
This commit is contained in:
parent
e14f73c945
commit
e8f9676137
@ -154,4 +154,7 @@ private PostCollectionRemoveEvent newPostCollectionRemoveEvent() {
|
||||
);
|
||||
}
|
||||
|
||||
public Object getAffectedOwner() {
|
||||
return affectedOwner;
|
||||
}
|
||||
}
|
||||
|
@ -94,6 +94,7 @@ public class ActionQueue {
|
||||
private ExecutableList<CollectionUpdateAction> collectionUpdates;
|
||||
private ExecutableList<QueuedOperationCollectionAction> collectionQueuedOps;
|
||||
private ExecutableList<CollectionRemoveAction> collectionRemovals;
|
||||
private ExecutableList<CollectionRemoveAction> orphanCollectionRemovals;
|
||||
|
||||
// TODO: The removeOrphan concept is a temporary "hack" for HHH-6484. This should be removed once action/task
|
||||
// ordering is improved.
|
||||
@ -110,15 +111,15 @@ public class ActionQueue {
|
||||
|
||||
//The order of these operations is very important
|
||||
private enum OrderedActions {
|
||||
CollectionRemoveAction {
|
||||
OrphanCollectionRemoveAction {
|
||||
@Override
|
||||
public ExecutableList<?> getActions(ActionQueue instance) {
|
||||
return instance.collectionRemovals;
|
||||
return instance.orphanCollectionRemovals;
|
||||
}
|
||||
@Override
|
||||
public void ensureInitialized(ActionQueue instance) {
|
||||
if ( instance.collectionRemovals == null ) {
|
||||
instance.collectionRemovals = new ExecutableList<>( instance.isOrderUpdatesEnabled() );
|
||||
if ( instance.orphanCollectionRemovals == null ) {
|
||||
instance.orphanCollectionRemovals = new ExecutableList<>( instance.isOrderUpdatesEnabled() );
|
||||
}
|
||||
}
|
||||
},
|
||||
@ -173,6 +174,18 @@ public void ensureInitialized(ActionQueue instance) {
|
||||
}
|
||||
}
|
||||
},
|
||||
CollectionRemoveAction {
|
||||
@Override
|
||||
public ExecutableList<?> getActions(ActionQueue instance) {
|
||||
return instance.collectionRemovals;
|
||||
}
|
||||
@Override
|
||||
public void ensureInitialized(ActionQueue instance) {
|
||||
if ( instance.collectionRemovals == null ) {
|
||||
instance.collectionRemovals = new ExecutableList<>( instance.isOrderUpdatesEnabled() );
|
||||
}
|
||||
}
|
||||
},
|
||||
CollectionUpdateAction {
|
||||
@Override
|
||||
public ExecutableList<?> getActions(ActionQueue instance) {
|
||||
@ -355,6 +368,20 @@ public void addAction(final CollectionRecreateAction action) {
|
||||
* @param action The action representing the removal of a collection
|
||||
*/
|
||||
public void addAction(final CollectionRemoveAction action) {
|
||||
if ( orphanRemovals != null && action.getAffectedOwner() != null && session.getPersistenceContextInternal()
|
||||
.getEntry( action.getAffectedOwner() )
|
||||
.getStatus()
|
||||
.isDeletedOrGone() ) {
|
||||
// We need to check if this collection's owner is an orphan being removed,
|
||||
// which case we should remove the collection first to avoid constraint violations
|
||||
for ( OrphanRemovalAction orphanRemoval : orphanRemovals ) {
|
||||
if ( orphanRemoval.getInstance() == action.getAffectedOwner() ) {
|
||||
OrderedActions.OrphanCollectionRemoveAction.ensureInitialized( this );
|
||||
this.orphanCollectionRemovals.add( action );
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
OrderedActions.CollectionRemoveAction.ensureInitialized( this );
|
||||
this.collectionRemovals.add( action );
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user