HHH-14622 Improved iteration of PreLoadEventListener
This commit is contained in:
parent
ccc5eb1305
commit
e6688f8ebc
|
@ -105,29 +105,6 @@ public final class TwoPhaseLoad {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated This method will be removed. Use {@link #initializeEntity(Object, boolean, SharedSessionContractImplementor, PreLoadEvent, Iterable)} instead.
|
|
||||||
*
|
|
||||||
* @param entity The entity being loaded
|
|
||||||
* @param readOnly Is the entity being loaded as read-only
|
|
||||||
* @param session The Session
|
|
||||||
* @param preLoadEvent The (re-used) pre-load event
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public static void initializeEntity(
|
|
||||||
final Object entity,
|
|
||||||
final boolean readOnly,
|
|
||||||
final SharedSessionContractImplementor session,
|
|
||||||
final PreLoadEvent preLoadEvent) {
|
|
||||||
final EventListenerGroup<PreLoadEventListener> listenerGroup = session
|
|
||||||
.getFactory()
|
|
||||||
.getServiceRegistry()
|
|
||||||
.getService( EventListenerRegistry.class )
|
|
||||||
.getEventListenerGroup( EventType.PRE_LOAD );
|
|
||||||
final Iterable<PreLoadEventListener> listeners = listenerGroup.listeners();
|
|
||||||
initializeEntity( entity, readOnly, session, preLoadEvent, listeners, EntityResolver.DEFAULT );
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Perform the second step of 2-phase load. Fully initialize the entity
|
* Perform the second step of 2-phase load. Fully initialize the entity
|
||||||
* instance.
|
* instance.
|
||||||
|
@ -140,15 +117,13 @@ public final class TwoPhaseLoad {
|
||||||
* @param readOnly Is the entity being loaded as read-only
|
* @param readOnly Is the entity being loaded as read-only
|
||||||
* @param session The Session
|
* @param session The Session
|
||||||
* @param preLoadEvent The (re-used) pre-load event
|
* @param preLoadEvent The (re-used) pre-load event
|
||||||
* @param preLoadEventListeners the pre-load event listeners
|
|
||||||
*/
|
*/
|
||||||
public static void initializeEntity(
|
public static void initializeEntity(
|
||||||
final Object entity,
|
final Object entity,
|
||||||
final boolean readOnly,
|
final boolean readOnly,
|
||||||
final SharedSessionContractImplementor session,
|
final SharedSessionContractImplementor session,
|
||||||
final PreLoadEvent preLoadEvent,
|
final PreLoadEvent preLoadEvent) {
|
||||||
final Iterable<PreLoadEventListener> preLoadEventListeners) {
|
initializeEntity( entity, readOnly, session, preLoadEvent, EntityResolver.DEFAULT );
|
||||||
initializeEntity( entity, readOnly, session, preLoadEvent, preLoadEventListeners, EntityResolver.DEFAULT );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -163,7 +138,6 @@ public final class TwoPhaseLoad {
|
||||||
* @param readOnly Is the entity being loaded as read-only
|
* @param readOnly Is the entity being loaded as read-only
|
||||||
* @param session The Session
|
* @param session The Session
|
||||||
* @param preLoadEvent The (re-used) pre-load event
|
* @param preLoadEvent The (re-used) pre-load event
|
||||||
* @param preLoadEventListeners the pre-load event listeners
|
|
||||||
* @param entityResolver the resolver used for to-one entity associations
|
* @param entityResolver the resolver used for to-one entity associations
|
||||||
* (not used when an entity is a bytecode-enhanced lazy entity)
|
* (not used when an entity is a bytecode-enhanced lazy entity)
|
||||||
*/
|
*/
|
||||||
|
@ -172,7 +146,6 @@ public final class TwoPhaseLoad {
|
||||||
final boolean readOnly,
|
final boolean readOnly,
|
||||||
final SharedSessionContractImplementor session,
|
final SharedSessionContractImplementor session,
|
||||||
final PreLoadEvent preLoadEvent,
|
final PreLoadEvent preLoadEvent,
|
||||||
final Iterable<PreLoadEventListener> preLoadEventListeners,
|
|
||||||
final EntityResolver entityResolver) {
|
final EntityResolver entityResolver) {
|
||||||
final PersistenceContext persistenceContext = session.getPersistenceContextInternal();
|
final PersistenceContext persistenceContext = session.getPersistenceContextInternal();
|
||||||
final EntityEntry entityEntry = persistenceContext.getEntry( entity );
|
final EntityEntry entityEntry = persistenceContext.getEntry( entity );
|
||||||
|
@ -180,7 +153,7 @@ public final class TwoPhaseLoad {
|
||||||
throw new AssertionFailure( "possible non-threadsafe access to the session" );
|
throw new AssertionFailure( "possible non-threadsafe access to the session" );
|
||||||
}
|
}
|
||||||
initializeEntityEntryLoadedState( entity, entityEntry, session, entityResolver );
|
initializeEntityEntryLoadedState( entity, entityEntry, session, entityResolver );
|
||||||
initializeEntityFromEntityEntryLoadedState( entity, entityEntry, readOnly, session, preLoadEvent, preLoadEventListeners );
|
initializeEntityFromEntityEntryLoadedState( entity, entityEntry, readOnly, session, preLoadEvent );
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void initializeEntityEntryLoadedState(
|
public static void initializeEntityEntryLoadedState(
|
||||||
|
@ -261,8 +234,7 @@ public final class TwoPhaseLoad {
|
||||||
final EntityEntry entityEntry,
|
final EntityEntry entityEntry,
|
||||||
final boolean readOnly,
|
final boolean readOnly,
|
||||||
final SharedSessionContractImplementor session,
|
final SharedSessionContractImplementor session,
|
||||||
final PreLoadEvent preLoadEvent,
|
final PreLoadEvent preLoadEvent) throws HibernateException {
|
||||||
final Iterable<PreLoadEventListener> preLoadEventListeners) throws HibernateException {
|
|
||||||
|
|
||||||
final PersistenceContext persistenceContext = session.getPersistenceContextInternal();
|
final PersistenceContext persistenceContext = session.getPersistenceContextInternal();
|
||||||
final EntityPersister persister = entityEntry.getPersister();
|
final EntityPersister persister = entityEntry.getPersister();
|
||||||
|
@ -274,9 +246,8 @@ public final class TwoPhaseLoad {
|
||||||
//Must occur after resolving identifiers!
|
//Must occur after resolving identifiers!
|
||||||
if ( session.isEventSource() ) {
|
if ( session.isEventSource() ) {
|
||||||
preLoadEvent.setEntity( entity ).setState( hydratedState ).setId( id ).setPersister( persister );
|
preLoadEvent.setEntity( entity ).setState( hydratedState ).setId( id ).setPersister( persister );
|
||||||
for ( PreLoadEventListener listener : preLoadEventListeners ) {
|
session.getFactory().getFastSessionServices()
|
||||||
listener.onPreLoad( preLoadEvent );
|
.eventListenerGroup_PRE_LOAD.fireEventOnEachListener( preLoadEvent, PreLoadEventListener::onPreLoad );
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
persister.setPropertyValues( entity, hydratedState );
|
persister.setPropertyValues( entity, hydratedState );
|
||||||
|
@ -589,7 +560,7 @@ public final class TwoPhaseLoad {
|
||||||
/**
|
/**
|
||||||
* Implementations determine how a to-one associations is resolved.
|
* Implementations determine how a to-one associations is resolved.
|
||||||
*
|
*
|
||||||
* @see #initializeEntity(Object, boolean, SharedSessionContractImplementor, PreLoadEvent, Iterable, EntityResolver)
|
* @see #initializeEntity(Object, boolean, SharedSessionContractImplementor, PreLoadEvent, EntityResolver)
|
||||||
*/
|
*/
|
||||||
public interface EntityResolver {
|
public interface EntityResolver {
|
||||||
|
|
||||||
|
|
|
@ -1184,14 +1184,8 @@ public abstract class Loader {
|
||||||
LOG.tracev( "Total objects hydrated: {0}", hydratedObjectsSize );
|
LOG.tracev( "Total objects hydrated: {0}", hydratedObjectsSize );
|
||||||
|
|
||||||
if ( hydratedObjectsSize != 0 ) {
|
if ( hydratedObjectsSize != 0 ) {
|
||||||
final Iterable<PreLoadEventListener> listeners = session
|
|
||||||
.getFactory()
|
|
||||||
.getFastSessionServices()
|
|
||||||
.eventListenerGroup_PRE_LOAD
|
|
||||||
.listeners();
|
|
||||||
|
|
||||||
for ( Object hydratedObject : hydratedObjects ) {
|
for ( Object hydratedObject : hydratedObjects ) {
|
||||||
TwoPhaseLoad.initializeEntity( hydratedObject, readOnly, session, pre, listeners );
|
TwoPhaseLoad.initializeEntity( hydratedObject, readOnly, session, pre );
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -237,19 +237,13 @@ public abstract class AbstractRowReader implements RowReader {
|
||||||
}
|
}
|
||||||
|
|
||||||
final SharedSessionContractImplementor session = context.getSession();
|
final SharedSessionContractImplementor session = context.getSession();
|
||||||
final Iterable<PreLoadEventListener> listeners = session
|
|
||||||
.getFactory()
|
|
||||||
.getFastSessionServices()
|
|
||||||
.eventListenerGroup_PRE_LOAD
|
|
||||||
.listeners();
|
|
||||||
|
|
||||||
for ( HydratedEntityRegistration registration : hydratedEntityRegistrations ) {
|
for ( HydratedEntityRegistration registration : hydratedEntityRegistrations ) {
|
||||||
TwoPhaseLoad.initializeEntity(
|
TwoPhaseLoad.initializeEntity(
|
||||||
registration.getInstance(),
|
registration.getInstance(),
|
||||||
context.isReadOnly(),
|
context.isReadOnly(),
|
||||||
session,
|
session,
|
||||||
preLoadEvent,
|
preLoadEvent
|
||||||
listeners
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue