Skip to content

Commit

Permalink
HHH-16982 Avoid unnecessary registerReloadedEntity calls
Browse files Browse the repository at this point in the history
  • Loading branch information
beikov authored and Sanne committed Jul 25, 2023
1 parent 0c7c68f commit 34628e7
Show file tree
Hide file tree
Showing 14 changed files with 63 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ public Callback getCallback() {
return delegate.getCallback();
}

@Override
public boolean hasCallbackActions() {
return delegate.hasCallbackActions();
}

@Override
public SharedSessionContractImplementor getSession() {
return delegate.getSession();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,11 @@ public Callback getCallback() {
return callback;
}

@Override
public boolean hasCallbackActions() {
return callback != null && callback.hasAfterLoadActions();
}

protected void resetCallback() {
callback = null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ public interface DomainQueryExecutionContext {
*/
Callback getCallback();

default boolean hasCallbackActions() {
final Callback callback = getCallback();
return callback != null && callback.hasAfterLoadActions();
}

/**
* The underlying session
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,11 @@ public SessionFactoryImplementor getSessionFactory() {
return getSession().getFactory();
}

@Override
public boolean hasCallbackActions() {
return callback != null && callback.hasAfterLoadActions();
}

@Override
public QueryParameterBindings getQueryParameterBindings() {
return parameterBindings;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ public Callback getCallback() {
return sqmExecutionContext.getCallback();
}

@Override
public boolean hasCallbackActions() {
return sqmExecutionContext.hasCallbackActions();
}

@Override
public boolean hasQueryExecutionToBeAddedToStatistics() {
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,9 @@ public void invokeAfterLoadActions(Object entity, EntityMappingType entityMappin
afterLoadActions.get( i ).afterLoad( entity, entityMappingType, session );
}
}

@Override
public boolean hasAfterLoadActions() {
return !afterLoadActions.isEmpty();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,9 @@ public void registerAfterLoadAction(AfterLoadAction afterLoadAction) {
public void invokeAfterLoadActions(Object entity, EntityMappingType entityMappingType, SharedSessionContractImplementor session) {
// don't do anything
}

@Override
public boolean hasAfterLoadActions() {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -793,5 +793,10 @@ public Callback getCallback() {
return context.getCallback();
}

@Override
public boolean hasCallbackActions() {
return context.hasCallbackActions();
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ default boolean isScrollResult(){

Callback getCallback();

default boolean hasCallbackActions() {
final Callback callback = getCallback();
return callback != null && callback.hasAfterLoadActions();
}

String getQueryIdentifier(String sql);

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ public Callback getCallback() {
return processingState.getCallback();
}

@Override
public boolean hasCallbackActions() {
return processingState.hasCallbackActions();
}

@Override
public CollectionKey getCollectionKey() {
return processingState.getCollectionKey();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,7 @@ protected void registerLoadingEntity(RowProcessingState rowProcessingState, Obje
}

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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,11 @@ public Callback getCallback() {
return executionContext.getCallback();
}

@Override
public boolean hasCallbackActions() {
return executionContext.hasCallbackActions();
}

@Override
public CollectionKey getCollectionKey() {
return executionContext.getCollectionKey();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ public void registerAfterLoadAction(AfterLoadAction afterLoadAction) {
public void invokeAfterLoadActions(Object entity, EntityMappingType entityMappingType, SharedSessionContractImplementor session) {
}

@Override
public boolean hasAfterLoadActions() {
return false;
}

protected SqmSelectStatement<?> interpretSelect(String hql) {
return interpretSelect( hql, sessionFactory() );
}
Expand Down

0 comments on commit 34628e7

Please sign in to comment.