HHH-11051 : Cache EventListenerRegistry and StatisticsImplementor

(cherry picked from commit 97318b71f0)

Conflicts:
	hibernate-core/src/main/java/org/hibernate/internal/SessionFactoryImpl.java

(cherry picked from commit 836691b5a7)

Conflicts:
	hibernate-core/src/main/java/org/hibernate/internal/SessionFactoryImpl.java
This commit is contained in:
johara 2016-08-16 16:29:18 +01:00 committed by Gail Badner
parent f201d2829e
commit 65422a6750
2 changed files with 19 additions and 0 deletions

View File

@ -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) {

View File

@ -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 );
}
}