HHH-16046 EventListener iterations should avoid using EventListenerGroup#listeners when possible

This commit is contained in:
Sanne Grinovero 2023-01-13 14:35:25 +00:00 committed by Sanne Grinovero
parent a1d43adad4
commit 48df4e15aa
3 changed files with 11 additions and 15 deletions

View File

@ -144,13 +144,11 @@ public class StandardCacheEntryImpl implements CacheEntry {
.setId( id )
.setPersister( persister );
final EventListenerGroup<PreLoadEventListener> listenerGroup = session
session
.getFactory()
.getFastSessionServices()
.eventListenerGroup_PRE_LOAD;
for ( PreLoadEventListener listener : listenerGroup.listeners() ) {
listener.onPreLoad( preLoadEvent );
}
.eventListenerGroup_PRE_LOAD
.fireEventOnEachListener( preLoadEvent, PreLoadEventListener::onPreLoad );
persister.setPropertyValues( instance, state );

View File

@ -974,12 +974,10 @@ public abstract class AbstractEntityInitializer extends AbstractFetchParentAcces
.setId( entityKey.getIdentifier() )
.setPersister( concreteDescriptor );
final EventListenerGroup<PreLoadEventListener> listenerGroup = session.getFactory()
session.getFactory()
.getFastSessionServices()
.eventListenerGroup_PRE_LOAD;
for ( PreLoadEventListener listener : listenerGroup.listeners() ) {
listener.onPreLoad( preLoadEvent );
}
.eventListenerGroup_PRE_LOAD
.fireEventOnEachListener( preLoadEvent, PreLoadEventListener::onPreLoad );
}
}

View File

@ -33,13 +33,13 @@ public class EventListenerDuplicationStrategyTest {
public void testListenersIterator() {
listenerGroup.addDuplicationStrategy( ReplaceOriginalStrategy.INSTANCE );
listenerGroup.appendListener( new OriginalListener( tracker ) );
listenerGroup.listeners().forEach( listener -> listener.onClear( event ) );
listenerGroup.fireEventOnEachListener( event, ClearEventListener::onClear );
assertThat( tracker.callers ).containsExactly( OriginalListener.class );
tracker.reset();
listenerGroup.appendListener( new ExpectedListener( tracker ) );
listenerGroup.listeners().forEach( listener -> listener.onClear( event ) );
listenerGroup.fireEventOnEachListener( event, ClearEventListener::onClear );
assertThat( tracker.callers ).containsExactly( ExpectedListener.class );
}
@ -79,7 +79,7 @@ public class EventListenerDuplicationStrategyTest {
listenerGroup.appendListener( new OriginalListener( tracker ) );
listenerGroup.appendListener( new ExpectedListener( tracker ) );
listenerGroup.appendListener( new ExtraListener( tracker ) );
listenerGroup.listeners().forEach( listener -> listener.onClear( event ) );
listenerGroup.fireEventOnEachListener( event, ClearEventListener::onClear );
assertThat( tracker.callers ).containsExactly(
OriginalListener.class,
@ -122,7 +122,7 @@ public class EventListenerDuplicationStrategyTest {
listenerGroup.appendListener( new OriginalListener( tracker ) );
listenerGroup.appendListener( new ExpectedListener( tracker ) );
listenerGroup.appendListener( new ExtraListener( tracker ) );
listenerGroup.listeners().forEach( listener -> listener.onClear( event ) );
listenerGroup.fireEventOnEachListener( event, ClearEventListener::onClear );
assertThat( tracker.callers ).containsExactly( ExpectedListener.class, ExtraListener.class );
}
@ -155,7 +155,7 @@ public class EventListenerDuplicationStrategyTest {
listenerGroup.appendListener( new OriginalListener( tracker ) );
listenerGroup.appendListener( new ExpectedListener( tracker ) );
listenerGroup.appendListener( new ExtraListener( tracker ) );
listenerGroup.listeners().forEach( listener -> listener.onClear( event ) );
listenerGroup.fireEventOnEachListener( event, ClearEventListener::onClear );
assertThat( tracker.callers ).containsExactly( OriginalListener.class, ExtraListener.class );
}