HHH-14029 Improve 2LC post-load event invocations
This commit is contained in:
parent
02c3cc9e2e
commit
b08ae4cd14
|
@ -46,6 +46,7 @@ import org.hibernate.exception.spi.SQLExceptionConverter;
|
|||
import org.hibernate.graph.spi.RootGraphImplementor;
|
||||
import org.hibernate.id.IdentifierGenerator;
|
||||
import org.hibernate.id.factory.IdentifierGeneratorFactory;
|
||||
import org.hibernate.internal.FastSessionServices;
|
||||
import org.hibernate.metadata.ClassMetadata;
|
||||
import org.hibernate.metadata.CollectionMetadata;
|
||||
import org.hibernate.metamodel.spi.MetamodelImplementor;
|
||||
|
@ -388,6 +389,11 @@ public class SessionFactoryDelegatingImpl implements SessionFactoryImplementor,
|
|||
return delegate.iterateEntityNameResolvers();
|
||||
}
|
||||
|
||||
@Override
|
||||
public FastSessionServices getFastSessionServices() {
|
||||
return delegate.getFastSessionServices();
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityPersister locateEntityPersister(Class byClass) {
|
||||
return delegate.locateEntityPersister( byClass );
|
||||
|
|
|
@ -36,6 +36,7 @@ import org.hibernate.event.spi.EventEngine;
|
|||
import org.hibernate.exception.spi.SQLExceptionConverter;
|
||||
import org.hibernate.graph.spi.RootGraphImplementor;
|
||||
import org.hibernate.id.IdentifierGenerator;
|
||||
import org.hibernate.internal.FastSessionServices;
|
||||
import org.hibernate.metamodel.spi.MetamodelImplementor;
|
||||
import org.hibernate.persister.collection.CollectionPersister;
|
||||
import org.hibernate.persister.entity.EntityPersister;
|
||||
|
@ -182,6 +183,11 @@ public interface SessionFactoryImplementor extends Mapping, SessionFactory, Quer
|
|||
return getMetamodel().getEntityNameResolvers();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the FastSessionServices instance associated with this SessionFactory
|
||||
*/
|
||||
FastSessionServices getFastSessionServices();
|
||||
|
||||
/**
|
||||
* Contract for resolving this SessionFactory on deserialization
|
||||
*/
|
||||
|
|
|
@ -32,6 +32,8 @@ import org.hibernate.event.spi.LoadEventListener;
|
|||
import org.hibernate.event.spi.LockEventListener;
|
||||
import org.hibernate.event.spi.MergeEventListener;
|
||||
import org.hibernate.event.spi.PersistEventListener;
|
||||
import org.hibernate.event.spi.PostLoadEvent;
|
||||
import org.hibernate.event.spi.PostLoadEventListener;
|
||||
import org.hibernate.event.spi.RefreshEventListener;
|
||||
import org.hibernate.event.spi.ReplicateEventListener;
|
||||
import org.hibernate.event.spi.ResolveNaturalIdEventListener;
|
||||
|
@ -80,7 +82,7 @@ import static org.hibernate.cfg.AvailableSettings.JPA_SHARED_CACHE_STORE_MODE;
|
|||
*
|
||||
* @author Sanne Grinovero
|
||||
*/
|
||||
final class FastSessionServices {
|
||||
public final class FastSessionServices {
|
||||
|
||||
/**
|
||||
* Default session properties
|
||||
|
@ -107,6 +109,9 @@ final class FastSessionServices {
|
|||
final EventListenerGroup<SaveOrUpdateEventListener> eventListenerGroup_SAVE_UPDATE;
|
||||
final EventListenerGroup<SaveOrUpdateEventListener> eventListenerGroup_UPDATE;
|
||||
|
||||
//Frequently used by 2LC initialization:
|
||||
final EventListenerGroup<PostLoadEventListener> eventListenerGroup_POST_LOAD;
|
||||
|
||||
//Intentionally Package private:
|
||||
final boolean disallowOutOfTransactionUpdateOperations;
|
||||
final boolean useStreamForLobBinding;
|
||||
|
@ -155,6 +160,7 @@ final class FastSessionServices {
|
|||
this.eventListenerGroup_SAVE = listeners( eventListenerRegistry, EventType.SAVE );
|
||||
this.eventListenerGroup_SAVE_UPDATE = listeners( eventListenerRegistry, EventType.SAVE_UPDATE );
|
||||
this.eventListenerGroup_UPDATE = listeners( eventListenerRegistry, EventType.UPDATE );
|
||||
this.eventListenerGroup_POST_LOAD = listeners( eventListenerRegistry, EventType.POST_LOAD );
|
||||
|
||||
//Other highly useful constants:
|
||||
this.dialect = jdbcServices.getJdbcEnvironment().getDialect();
|
||||
|
@ -285,4 +291,7 @@ final class FastSessionServices {
|
|||
return defaultJdbcObservers;
|
||||
}
|
||||
|
||||
public void firePostLoadEvent(final PostLoadEvent postLoadEvent) {
|
||||
eventListenerGroup_POST_LOAD.fireEventOnEachListener( postLoadEvent, PostLoadEventListener::onPostLoad );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1658,7 +1658,8 @@ public class SessionFactoryImpl implements SessionFactoryImplementor {
|
|||
/**
|
||||
* @return the FastSessionServices for this SessionFactory.
|
||||
*/
|
||||
FastSessionServices getFastSessionServices() {
|
||||
@Override
|
||||
public FastSessionServices getFastSessionServices() {
|
||||
return this.fastSessionServices;
|
||||
}
|
||||
|
||||
|
|
|
@ -36,6 +36,7 @@ import org.hibernate.event.spi.PostLoadEvent;
|
|||
import org.hibernate.event.spi.PostLoadEventListener;
|
||||
import org.hibernate.internal.CoreLogging;
|
||||
import org.hibernate.internal.CoreMessageLogger;
|
||||
import org.hibernate.internal.FastSessionServices;
|
||||
import org.hibernate.persister.entity.EntityPersister;
|
||||
import org.hibernate.pretty.MessageHelper;
|
||||
import org.hibernate.proxy.HibernateProxy;
|
||||
|
@ -354,22 +355,13 @@ public class CacheEntityLoaderHelper extends AbstractLockUpgradeEventListener {
|
|||
.setId( entityId )
|
||||
.setPersister( persister );
|
||||
|
||||
for ( PostLoadEventListener listener : postLoadEventListeners( session ) ) {
|
||||
listener.onPostLoad( postLoadEvent );
|
||||
}
|
||||
session.getSessionFactory()
|
||||
.getFastSessionServices()
|
||||
.firePostLoadEvent( postLoadEvent );
|
||||
|
||||
return entity;
|
||||
}
|
||||
|
||||
private Iterable<PostLoadEventListener> postLoadEventListeners(EventSource session) {
|
||||
return session
|
||||
.getFactory()
|
||||
.getServiceRegistry()
|
||||
.getService( EventListenerRegistry.class )
|
||||
.getEventListenerGroup( EventType.POST_LOAD )
|
||||
.listeners();
|
||||
}
|
||||
|
||||
public static class PersistenceContextEntry {
|
||||
private final Object entity;
|
||||
private EntityStatus status;
|
||||
|
|
Loading…
Reference in New Issue