HHH-16982 Avoid unnecessary registerReloadedEntity calls

This commit is contained in:
Christian Beikov 2023-07-24 12:52:21 +02:00 committed by Sanne Grinovero
parent 0c7c68fe5a
commit 34628e71da
14 changed files with 63 additions and 1 deletions

View File

@ -37,6 +37,11 @@ public class DelegatingDomainQueryExecutionContext implements DomainQueryExecuti
return delegate.getCallback();
}
@Override
public boolean hasCallbackActions() {
return delegate.hasCallbackActions();
}
@Override
public SharedSessionContractImplementor getSession() {
return delegate.getSession();

View File

@ -535,6 +535,11 @@ public abstract class AbstractSelectionQuery<R>
return callback;
}
@Override
public boolean hasCallbackActions() {
return callback != null && callback.hasAfterLoadActions();
}
protected void resetCallback() {
callback = null;
}

View File

@ -29,6 +29,11 @@ public interface DomainQueryExecutionContext {
*/
Callback getCallback();
default boolean hasCallbackActions() {
final Callback callback = getCallback();
return callback != null && callback.hasAfterLoadActions();
}
/**
* The underlying session
*/

View File

@ -436,6 +436,11 @@ public class NativeQueryImpl<R>
return getSession().getFactory();
}
@Override
public boolean hasCallbackActions() {
return callback != null && callback.hasAfterLoadActions();
}
@Override
public QueryParameterBindings getQueryParameterBindings() {
return parameterBindings;

View File

@ -65,6 +65,11 @@ public class SqmJdbcExecutionContextAdapter extends BaseExecutionContext {
return sqmExecutionContext.getCallback();
}
@Override
public boolean hasCallbackActions() {
return sqmExecutionContext.hasCallbackActions();
}
@Override
public boolean hasQueryExecutionToBeAddedToStatistics() {
return true;

View File

@ -37,4 +37,9 @@ public class CallbackImpl implements Callback {
afterLoadActions.get( i ).afterLoad( entity, entityMappingType, session );
}
}
@Override
public boolean hasAfterLoadActions() {
return !afterLoadActions.isEmpty();
}
}

View File

@ -29,4 +29,9 @@ public class CallbackNoOp implements Callback {
public void invokeAfterLoadActions(Object entity, EntityMappingType entityMappingType, SharedSessionContractImplementor session) {
// don't do anything
}
@Override
public boolean hasAfterLoadActions() {
return false;
}
}

View File

@ -793,5 +793,10 @@ public class JdbcSelectExecutorStandardImpl implements JdbcSelectExecutor {
return context.getCallback();
}
@Override
public boolean hasCallbackActions() {
return context.hasCallbackActions();
}
}
}

View File

@ -36,4 +36,6 @@ public interface Callback {
default void invokeAfterLoadActions(SharedSessionContractImplementor session, Object entity, org.hibernate.persister.entity.Loadable persister) {
invokeAfterLoadActions( entity, persister, session );
}
boolean hasAfterLoadActions();
}

View File

@ -36,6 +36,11 @@ public interface ExecutionContext {
Callback getCallback();
default boolean hasCallbackActions() {
final Callback callback = getCallback();
return callback != null && callback.hasAfterLoadActions();
}
String getQueryIdentifier(String sql);
/**

View File

@ -104,6 +104,11 @@ public class NestedRowProcessingState extends BaseExecutionContext implements Ro
return processingState.getCallback();
}
@Override
public boolean hasCallbackActions() {
return processingState.hasCallbackActions();
}
@Override
public CollectionKey getCollectionKey() {
return processingState.getCollectionKey();

View File

@ -716,7 +716,7 @@ public abstract class AbstractEntityInitializer extends AbstractFetchParentAcces
}
protected void registerReloadedEntity(RowProcessingState rowProcessingState, Object instance) {
if ( rowProcessingState.getCallback() != null ) {
if ( rowProcessingState.hasCallbackActions() ) {
// This is only needed for follow-on locking, so skip registering the entity if there is no callback
rowProcessingState.getJdbcValuesSourceProcessingState()
.registerReloadedEntity(

View File

@ -153,6 +153,11 @@ public class RowProcessingStateStandardImpl extends BaseExecutionContext impleme
return executionContext.getCallback();
}
@Override
public boolean hasCallbackActions() {
return executionContext.hasCallbackActions();
}
@Override
public CollectionKey getCollectionKey() {
return executionContext.getCollectionKey();

View File

@ -55,6 +55,11 @@ public abstract class BaseSqmUnitTest
public void invokeAfterLoadActions(Object entity, EntityMappingType entityMappingType, SharedSessionContractImplementor session) {
}
@Override
public boolean hasAfterLoadActions() {
return false;
}
protected SqmSelectStatement<?> interpretSelect(String hql) {
return interpretSelect( hql, sessionFactory() );
}