HHH-11051 : Cache EventListenerRegistry and StatisticsImplementor
(cherry picked from commit97318b71f0
) Conflicts: hibernate-core/src/main/java/org/hibernate/internal/SessionFactoryImpl.java (cherry picked from commit836691b5a7
) Conflicts: hibernate-core/src/main/java/org/hibernate/internal/SessionFactoryImpl.java
This commit is contained in:
parent
f201d2829e
commit
65422a6750
|
@ -191,6 +191,7 @@ public final class SessionFactoryImpl implements SessionFactoryImplementor {
|
|||
|
||||
private final transient TypeResolver typeResolver;
|
||||
private final transient TypeHelper typeHelper;
|
||||
private transient StatisticsImplementor statisticsImplementor;
|
||||
|
||||
|
||||
public SessionFactoryImpl(final MetadataImplementor metadata, SessionFactoryOptions options) {
|
||||
|
|
|
@ -10,7 +10,9 @@ import java.util.List;
|
|||
|
||||
import org.hibernate.boot.spi.SessionFactoryOptions;
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.event.service.spi.EventListenerRegistry;
|
||||
import org.hibernate.service.Service;
|
||||
import org.hibernate.service.UnknownServiceException;
|
||||
import org.hibernate.service.spi.ServiceBinding;
|
||||
import org.hibernate.service.spi.ServiceInitiator;
|
||||
import org.hibernate.service.spi.ServiceRegistryImplementor;
|
||||
|
@ -24,6 +26,7 @@ public class SessionFactoryServiceRegistryImpl extends AbstractServiceRegistryIm
|
|||
|
||||
private final SessionFactoryOptions sessionFactoryOptions;
|
||||
private final SessionFactoryImplementor sessionFactory;
|
||||
private EventListenerRegistry cachedEventListenerRegistry;
|
||||
|
||||
@SuppressWarnings( {"unchecked"})
|
||||
public SessionFactoryServiceRegistryImpl(
|
||||
|
@ -59,4 +62,19 @@ public class SessionFactoryServiceRegistryImpl extends AbstractServiceRegistryIm
|
|||
public <R extends Service> void configureService(ServiceBinding<R> serviceBinding) {
|
||||
//TODO nothing to do here or should we inject SessionFactory properties?
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R extends Service> R getService(Class<R> serviceRole) {
|
||||
|
||||
//HHH-11051 cache EventListenerRegistry
|
||||
if ( serviceRole.equals( EventListenerRegistry.class ) ) {
|
||||
if ( cachedEventListenerRegistry == null ) {
|
||||
cachedEventListenerRegistry = (EventListenerRegistry) super.getService( serviceRole );
|
||||
}
|
||||
return (R) cachedEventListenerRegistry;
|
||||
}
|
||||
|
||||
return super.getService( serviceRole );
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue