some cleanups after HHH-15509

This commit is contained in:
Gavin King 2022-09-26 20:46:56 +02:00
parent 49a2b20d76
commit fcd7a45a75
3 changed files with 29 additions and 24 deletions

View File

@ -73,9 +73,7 @@ public abstract class EntityAction
@Override @Override
public AfterTransactionCompletionProcess getAfterTransactionCompletionProcess() { public AfterTransactionCompletionProcess getAfterTransactionCompletionProcess() {
return needsAfterTransactionCompletion() return needsAfterTransactionCompletion() ? this : null;
? this
: null;
} }
protected abstract boolean hasPostCommitEventListeners(); protected abstract boolean hasPostCommitEventListeners();

View File

@ -84,9 +84,9 @@ public class EntityDeleteAction extends EntityAction {
final EntityPersister persister, final EntityPersister persister,
final SessionImplementor session) { final SessionImplementor session) {
super( session, id, null, persister ); super( session, id, null, persister );
this.version = null; version = null;
this.isCascadeDeleteEnabled = false; isCascadeDeleteEnabled = false;
this.state = null; state = null;
} }
public Object getVersion() { public Object getVersion() {
@ -113,24 +113,20 @@ public class EntityDeleteAction extends EntityAction {
this.lock = lock; this.lock = lock;
} }
private boolean isInstanceLoaded() {
// A null instance signals that we're deleting an unloaded proxy.
return getInstance() != null;
}
@Override @Override
public void execute() throws HibernateException { public void execute() throws HibernateException {
final Object id = getId(); final Object id = getId();
final Object version = getCurrentVersion();
final EntityPersister persister = getPersister(); final EntityPersister persister = getPersister();
final SharedSessionContractImplementor session = getSession(); final SharedSessionContractImplementor session = getSession();
final Object instance = getInstance(); final Object instance = getInstance();
final boolean veto = preDelete(); final boolean veto = isInstanceLoaded() && preDelete();
Object version = this.version;
if ( persister.isVersionPropertyGenerated()
// null instance signals that we're deleting an unloaded proxy, no need for a version
&& instance != null ) {
// we need to grab the version value from the entity, otherwise
// we have issues with generated-version entities that may have
// multiple actions queued during the same flush
version = persister.getVersion( instance );
}
final Object ck; final Object ck;
if ( persister.canWriteToCache() ) { if ( persister.canWriteToCache() ) {
@ -146,12 +142,12 @@ public class EntityDeleteAction extends EntityAction {
persister.delete( id, version, instance, session ); persister.delete( id, version, instance, session );
} }
if ( instance == null ) { if ( isInstanceLoaded() ) {
// null instance signals that we're deleting an unloaded proxy postDeleteLoaded( id, persister, session, instance, ck );
postDeleteUnloaded( id, persister, session, ck );
} }
else { else {
postDeleteLoaded( id, persister, session, instance, ck ); // we're deleting an unloaded proxy
postDeleteUnloaded( id, persister, session, ck );
} }
final StatisticsImplementor statistics = getSession().getFactory().getStatistics(); final StatisticsImplementor statistics = getSession().getFactory().getStatistics();
@ -160,6 +156,17 @@ public class EntityDeleteAction extends EntityAction {
} }
} }
private Object getCurrentVersion() {
return getPersister().isVersionPropertyGenerated()
// skip if we're deleting an unloaded proxy, no need for the version
&& isInstanceLoaded()
// we need to grab the version value from the entity, otherwise
// we have issues with generated-version entities that may have
// multiple actions queued during the same flush
? getPersister().getVersion( getInstance() )
: version;
}
private void postDeleteLoaded( private void postDeleteLoaded(
Object id, Object id,
EntityPersister persister, EntityPersister persister,
@ -202,12 +209,12 @@ public class EntityDeleteAction extends EntityAction {
} }
protected boolean preDelete() { protected boolean preDelete() {
boolean veto = false;
final EventListenerGroup<PreDeleteEventListener> listenerGroup = getFastSessionServices().eventListenerGroup_PRE_DELETE; final EventListenerGroup<PreDeleteEventListener> listenerGroup = getFastSessionServices().eventListenerGroup_PRE_DELETE;
if ( listenerGroup.isEmpty() ) { if ( listenerGroup.isEmpty() ) {
return veto; return false;
} }
final PreDeleteEvent event = new PreDeleteEvent( getInstance(), getId(), state, getPersister(), eventSource() ); final PreDeleteEvent event = new PreDeleteEvent( getInstance(), getId(), state, getPersister(), eventSource() );
boolean veto = false;
for ( PreDeleteEventListener listener : listenerGroup.listeners() ) { for ( PreDeleteEventListener listener : listenerGroup.listeners() ) {
veto |= listener.onPreDelete( event ); veto |= listener.onPreDelete( event );
} }

View File

@ -52,7 +52,7 @@ public class EntityIdentityInsertAction extends AbstractEntityInsertAction {
SharedSessionContractImplementor session, SharedSessionContractImplementor session,
boolean isDelayed) { boolean isDelayed) {
super( super(
( isDelayed ? generateDelayedPostInsertIdentifier() : null ), isDelayed ? generateDelayedPostInsertIdentifier() : null,
state, state,
instance, instance,
isVersionIncrementDisabled, isVersionIncrementDisabled,