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 committed Jul 24, 2023
1 parent 7915ad6 commit b9e5d3a
Show file tree
Hide file tree
Showing 14 changed files with 63 additions and 2 deletions.
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 @@ -621,6 +621,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 @@ -433,6 +433,11 @@ public Callback getCallback() {
return callback;
}

@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 @@ -798,6 +798,11 @@ public Callback getCallback() {
return context.getCallback();
}

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

@Override
public Set<String> getEnabledFetchProfiles() {
return null;
Expand Down
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 @@ -105,6 +105,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 @@ -60,7 +60,6 @@
import org.hibernate.sql.results.jdbc.spi.JdbcValuesSourceProcessingState;
import org.hibernate.sql.results.jdbc.spi.RowProcessingState;
import org.hibernate.stat.spi.StatisticsImplementor;
import org.hibernate.type.AssociationType;
import org.hibernate.type.Type;

import static org.hibernate.bytecode.enhance.spi.LazyPropertyInitializer.UNFETCHED_PROPERTY;
Expand Down Expand Up @@ -717,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 b9e5d3a

Please sign in to comment.