HHH-11051 : Cache EventListenerRegistry and StatisticsImplementor
This commit is contained in:
parent
898fe4f533
commit
97318b71f0
|
@ -206,6 +206,8 @@ public final class SessionFactoryImpl implements SessionFactoryImplementor {
|
|||
private final transient SessionFactoryOptions sessionFactoryOptions;
|
||||
private final transient Map<String, RegionAccessStrategy> cacheAccessStrategiesMap = new HashMap();
|
||||
|
||||
private transient StatisticsImplementor statisticsImplementor;
|
||||
|
||||
public SessionFactoryImpl(final MetadataImplementor metadata, SessionFactoryOptions options) {
|
||||
LOG.debug( "Building session factory" );
|
||||
|
||||
|
@ -1170,7 +1172,10 @@ public final class SessionFactoryImpl implements SessionFactoryImplementor {
|
|||
}
|
||||
|
||||
public StatisticsImplementor getStatisticsImplementor() {
|
||||
return serviceRegistry.getService( StatisticsImplementor.class );
|
||||
if ( statisticsImplementor == null ) {
|
||||
statisticsImplementor = serviceRegistry.getService( StatisticsImplementor.class );
|
||||
}
|
||||
return statisticsImplementor;
|
||||
}
|
||||
|
||||
public FilterDefinition getFilterDefinition(String filterName) throws HibernateException {
|
||||
|
|
|
@ -8,7 +8,9 @@ package org.hibernate.service.internal;
|
|||
|
||||
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;
|
||||
|
@ -22,6 +24,7 @@ public class SessionFactoryServiceRegistryImpl extends AbstractServiceRegistryIm
|
|||
|
||||
private final SessionFactoryOptions sessionFactoryOptions;
|
||||
private final SessionFactoryImplementor sessionFactory;
|
||||
private EventListenerRegistry cachedEventListenerRegistry;
|
||||
|
||||
@SuppressWarnings( {"unchecked"})
|
||||
public SessionFactoryServiceRegistryImpl(
|
||||
|
@ -50,4 +53,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