HHH-14029 Generally improve handling of all post-load events
This commit is contained in:
parent
b08ae4cd14
commit
2d7022ecec
|
@ -35,6 +35,7 @@ import org.hibernate.event.spi.PreLoadEventListener;
|
||||||
import org.hibernate.graph.spi.AttributeNodeImplementor;
|
import org.hibernate.graph.spi.AttributeNodeImplementor;
|
||||||
import org.hibernate.graph.spi.GraphImplementor;
|
import org.hibernate.graph.spi.GraphImplementor;
|
||||||
import org.hibernate.internal.CoreMessageLogger;
|
import org.hibernate.internal.CoreMessageLogger;
|
||||||
|
import org.hibernate.internal.FastSessionServices;
|
||||||
import org.hibernate.persister.entity.EntityPersister;
|
import org.hibernate.persister.entity.EntityPersister;
|
||||||
import org.hibernate.pretty.MessageHelper;
|
import org.hibernate.pretty.MessageHelper;
|
||||||
import org.hibernate.property.access.internal.PropertyAccessStrategyBackRefImpl;
|
import org.hibernate.property.access.internal.PropertyAccessStrategyBackRefImpl;
|
||||||
|
@ -488,6 +489,20 @@ public final class TwoPhaseLoad {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method will be removed.
|
||||||
|
* @deprecated Use {@link #postLoad(Object, SharedSessionContractImplementor, PostLoadEvent)}
|
||||||
|
* instead.
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public static void postLoad(
|
||||||
|
final Object entity,
|
||||||
|
final SharedSessionContractImplementor session,
|
||||||
|
final PostLoadEvent postLoadEvent,
|
||||||
|
final Iterable<PostLoadEventListener> postLoadEventListeners) {
|
||||||
|
postLoad( entity, session, postLoadEvent );
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* PostLoad cannot occur during initializeEntity, as that call occurs *before*
|
* PostLoad cannot occur during initializeEntity, as that call occurs *before*
|
||||||
* the Set collections are added to the persistence context by Loader.
|
* the Set collections are added to the persistence context by Loader.
|
||||||
|
@ -503,40 +518,15 @@ public final class TwoPhaseLoad {
|
||||||
public static void postLoad(
|
public static void postLoad(
|
||||||
final Object entity,
|
final Object entity,
|
||||||
final SharedSessionContractImplementor session,
|
final SharedSessionContractImplementor session,
|
||||||
final PostLoadEvent postLoadEvent,
|
final PostLoadEvent postLoadEvent) {
|
||||||
final Iterable<PostLoadEventListener> postLoadEventListeners) {
|
|
||||||
|
|
||||||
if ( session.isEventSource() ) {
|
if ( session.isEventSource() ) {
|
||||||
final PersistenceContext persistenceContext
|
final EntityEntry entityEntry = session.getPersistenceContextInternal().getEntry( entity );
|
||||||
= session.getPersistenceContextInternal();
|
|
||||||
final EntityEntry entityEntry = persistenceContext.getEntry( entity );
|
|
||||||
|
|
||||||
postLoadEvent.setEntity( entity ).setId( entityEntry.getId() ).setPersister( entityEntry.getPersister() );
|
postLoadEvent.setEntity( entity ).setId( entityEntry.getId() ).setPersister( entityEntry.getPersister() );
|
||||||
|
|
||||||
for ( PostLoadEventListener listener : postLoadEventListeners ) {
|
session.getFactory().getFastSessionServices().firePostLoadEvent( postLoadEvent );
|
||||||
listener.onPostLoad( postLoadEvent );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This method will be removed.
|
|
||||||
* @deprecated Use {@link #postLoad(Object, SharedSessionContractImplementor, PostLoadEvent, Iterable)}
|
|
||||||
* instead.
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public static void postLoad(
|
|
||||||
final Object entity,
|
|
||||||
final SharedSessionContractImplementor session,
|
|
||||||
final PostLoadEvent postLoadEvent) {
|
|
||||||
|
|
||||||
final EventListenerGroup<PostLoadEventListener> listenerGroup = session.getFactory()
|
|
||||||
.getServiceRegistry()
|
|
||||||
.getService( EventListenerRegistry.class )
|
|
||||||
.getEventListenerGroup( EventType.POST_LOAD );
|
|
||||||
|
|
||||||
postLoad( entity, session, postLoadEvent, listenerGroup.listeners() );
|
|
||||||
}
|
|
||||||
|
|
||||||
private static boolean useMinimalPuts(SharedSessionContractImplementor session, EntityEntry entityEntry) {
|
private static boolean useMinimalPuts(SharedSessionContractImplementor session, EntityEntry entityEntry) {
|
||||||
if ( session.getFactory().getSessionFactoryOptions().isMinimalPutsEnabled() ) {
|
if ( session.getFactory().getSessionFactoryOptions().isMinimalPutsEnabled() ) {
|
||||||
|
|
|
@ -1206,21 +1206,8 @@ public abstract class Loader {
|
||||||
// persistence context.
|
// persistence context.
|
||||||
final PersistenceContext persistenceContext = session.getPersistenceContextInternal();
|
final PersistenceContext persistenceContext = session.getPersistenceContextInternal();
|
||||||
if ( hydratedObjects != null && hydratedObjects.size() > 0 ) {
|
if ( hydratedObjects != null && hydratedObjects.size() > 0 ) {
|
||||||
|
|
||||||
final Iterable<PostLoadEventListener> postLoadEventListeners;
|
|
||||||
if ( session.isEventSource() ) {
|
|
||||||
final EventListenerGroup<PostLoadEventListener> listenerGroup = session.getFactory()
|
|
||||||
.getServiceRegistry()
|
|
||||||
.getService( EventListenerRegistry.class )
|
|
||||||
.getEventListenerGroup( EventType.POST_LOAD );
|
|
||||||
postLoadEventListeners = listenerGroup.listeners();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
postLoadEventListeners = Collections.emptyList();
|
|
||||||
}
|
|
||||||
|
|
||||||
for ( Object hydratedObject : hydratedObjects ) {
|
for ( Object hydratedObject : hydratedObjects ) {
|
||||||
TwoPhaseLoad.postLoad( hydratedObject, session, post, postLoadEventListeners );
|
TwoPhaseLoad.postLoad( hydratedObject, session, post );
|
||||||
if ( afterLoadActions != null ) {
|
if ( afterLoadActions != null ) {
|
||||||
for ( AfterLoadAction afterLoadAction : afterLoadActions ) {
|
for ( AfterLoadAction afterLoadAction : afterLoadActions ) {
|
||||||
final EntityEntry entityEntry = persistenceContext.getEntry( hydratedObject );
|
final EntityEntry entityEntry = persistenceContext.getEntry( hydratedObject );
|
||||||
|
|
|
@ -293,20 +293,9 @@ public abstract class AbstractRowReader implements RowReader {
|
||||||
}
|
}
|
||||||
|
|
||||||
final SharedSessionContractImplementor session = context.getSession();
|
final SharedSessionContractImplementor session = context.getSession();
|
||||||
final Iterable<PostLoadEventListener> postLoadEventListeners;
|
|
||||||
if ( session.isEventSource() ) {
|
|
||||||
final EventListenerGroup<PostLoadEventListener> listenerGroup = session.getFactory()
|
|
||||||
.getServiceRegistry()
|
|
||||||
.getService( EventListenerRegistry.class )
|
|
||||||
.getEventListenerGroup( EventType.POST_LOAD );
|
|
||||||
postLoadEventListeners = listenerGroup.listeners();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
postLoadEventListeners = Collections.emptyList();
|
|
||||||
}
|
|
||||||
|
|
||||||
for ( HydratedEntityRegistration registration : hydratedEntityRegistrations ) {
|
for ( HydratedEntityRegistration registration : hydratedEntityRegistrations ) {
|
||||||
TwoPhaseLoad.postLoad( registration.getInstance(), session, postLoadEvent, postLoadEventListeners );
|
TwoPhaseLoad.postLoad( registration.getInstance(), session, postLoadEvent );
|
||||||
if ( afterLoadActionList != null ) {
|
if ( afterLoadActionList != null ) {
|
||||||
for ( AfterLoadAction afterLoadAction : afterLoadActionList ) {
|
for ( AfterLoadAction afterLoadAction : afterLoadActionList ) {
|
||||||
afterLoadAction.afterLoad(
|
afterLoadAction.afterLoad(
|
||||||
|
|
Loading…
Reference in New Issue