HHH-6267 : Plumb MetadataImplementor into service initiators registered in SessionFactoryServiceRegistry
This commit is contained in:
parent
d99f2ad2da
commit
8a0eeedec8
|
@ -26,6 +26,7 @@ package org.hibernate.event.service.internal;
|
||||||
import org.hibernate.cfg.Configuration;
|
import org.hibernate.cfg.Configuration;
|
||||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||||
import org.hibernate.event.service.spi.EventListenerRegistry;
|
import org.hibernate.event.service.spi.EventListenerRegistry;
|
||||||
|
import org.hibernate.metamodel.source.spi.MetadataImplementor;
|
||||||
import org.hibernate.service.spi.ServiceRegistryImplementor;
|
import org.hibernate.service.spi.ServiceRegistryImplementor;
|
||||||
import org.hibernate.service.spi.SessionFactoryServiceInitiator;
|
import org.hibernate.service.spi.SessionFactoryServiceInitiator;
|
||||||
|
|
||||||
|
@ -50,4 +51,11 @@ public class EventListenerServiceInitiator implements SessionFactoryServiceIniti
|
||||||
return new EventListenerRegistryImpl();
|
return new EventListenerRegistryImpl();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public EventListenerRegistry initiateService(
|
||||||
|
SessionFactoryImplementor sessionFactory,
|
||||||
|
MetadataImplementor metadata,
|
||||||
|
ServiceRegistryImplementor registry) {
|
||||||
|
return new EventListenerRegistryImpl();
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -75,6 +75,7 @@ import org.hibernate.cache.spi.UpdateTimestampsCache;
|
||||||
import org.hibernate.cache.spi.access.AccessType;
|
import org.hibernate.cache.spi.access.AccessType;
|
||||||
import org.hibernate.cache.spi.access.CollectionRegionAccessStrategy;
|
import org.hibernate.cache.spi.access.CollectionRegionAccessStrategy;
|
||||||
import org.hibernate.cache.spi.access.EntityRegionAccessStrategy;
|
import org.hibernate.cache.spi.access.EntityRegionAccessStrategy;
|
||||||
|
import org.hibernate.cfg.AvailableSettings;
|
||||||
import org.hibernate.cfg.Configuration;
|
import org.hibernate.cfg.Configuration;
|
||||||
import org.hibernate.cfg.Environment;
|
import org.hibernate.cfg.Environment;
|
||||||
import org.hibernate.cfg.Settings;
|
import org.hibernate.cfg.Settings;
|
||||||
|
@ -123,6 +124,7 @@ import org.hibernate.pretty.MessageHelper;
|
||||||
import org.hibernate.proxy.EntityNotFoundDelegate;
|
import org.hibernate.proxy.EntityNotFoundDelegate;
|
||||||
import org.hibernate.service.ServiceRegistry;
|
import org.hibernate.service.ServiceRegistry;
|
||||||
import org.hibernate.integrator.spi.IntegratorService;
|
import org.hibernate.integrator.spi.IntegratorService;
|
||||||
|
import org.hibernate.service.config.spi.ConfigurationService;
|
||||||
import org.hibernate.service.jdbc.connections.spi.ConnectionProvider;
|
import org.hibernate.service.jdbc.connections.spi.ConnectionProvider;
|
||||||
import org.hibernate.service.jndi.spi.JndiService;
|
import org.hibernate.service.jndi.spi.JndiService;
|
||||||
import org.hibernate.service.jta.platform.spi.JtaPlatform;
|
import org.hibernate.service.jta.platform.spi.JtaPlatform;
|
||||||
|
@ -523,13 +525,9 @@ public final class SessionFactoryImpl
|
||||||
this.namedQueries = null;
|
this.namedQueries = null;
|
||||||
this.namedSqlQueries = null;
|
this.namedSqlQueries = null;
|
||||||
this.sqlResultSetMappings = null;
|
this.sqlResultSetMappings = null;
|
||||||
this.filters = null;
|
|
||||||
this.fetchProfiles = null;
|
this.fetchProfiles = null;
|
||||||
this.imports = null;
|
this.imports = null;
|
||||||
this.interceptor = null;
|
this.interceptor = null;
|
||||||
this.serviceRegistry = null;
|
|
||||||
this.settings = null;
|
|
||||||
this.properties = null;
|
|
||||||
this.queryCache = null;
|
this.queryCache = null;
|
||||||
this.updateTimestampsCache = null;
|
this.updateTimestampsCache = null;
|
||||||
this.queryCaches = null;
|
this.queryCaches = null;
|
||||||
|
@ -537,10 +535,38 @@ public final class SessionFactoryImpl
|
||||||
this.entityNotFoundDelegate = null;
|
this.entityNotFoundDelegate = null;
|
||||||
this.sqlFunctionRegistry = null;
|
this.sqlFunctionRegistry = null;
|
||||||
this.queryPlanCache = null;
|
this.queryPlanCache = null;
|
||||||
this.typeResolver = null;
|
|
||||||
this.typeHelper = null;
|
|
||||||
this.transactionEnvironment = null;
|
this.transactionEnvironment = null;
|
||||||
|
|
||||||
|
ConfigurationService configurationService = serviceRegistry.getService( ConfigurationService.class );
|
||||||
|
this.settings = null;
|
||||||
|
|
||||||
|
this.serviceRegistry = serviceRegistry.getService( SessionFactoryServiceRegistryFactory.class ).buildServiceRegistry(
|
||||||
|
this,
|
||||||
|
metadata
|
||||||
|
);
|
||||||
|
|
||||||
|
// TODO: get Interceptor from ConfurationService
|
||||||
|
//this.interceptor = cfg.getInterceptor();
|
||||||
|
|
||||||
|
// TODO: find references to properties and make sure everything needed is available to services via
|
||||||
|
// ConfigurationService
|
||||||
|
this.properties = null;
|
||||||
|
|
||||||
|
// TODO: should this be build along w/ metadata? seems like it should so app has more control over it...
|
||||||
|
//this.sqlFunctionRegistry = new SQLFunctionRegistry( getDialect(), metadata.getSqlFunctions() );
|
||||||
|
if ( observer != null ) {
|
||||||
|
this.observer.addObserver( observer );
|
||||||
|
}
|
||||||
|
|
||||||
|
this.typeResolver = metadata.getTypeResolver().scope( this );
|
||||||
|
this.typeHelper = new TypeLocatorImpl( typeResolver );
|
||||||
|
|
||||||
|
this.filters = new HashMap();
|
||||||
|
this.filters.putAll( metadata.getFilterDefinitions() );
|
||||||
|
|
||||||
|
LOG.debugf("Session factory constructed with filter configurations : %s", filters);
|
||||||
|
LOG.debugf("Instantiating session factory with properties: %s", configurationService.getSettings() );
|
||||||
|
|
||||||
// TODO: implement
|
// TODO: implement
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,6 +25,7 @@ package org.hibernate.service.internal;
|
||||||
|
|
||||||
import org.hibernate.cfg.Configuration;
|
import org.hibernate.cfg.Configuration;
|
||||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||||
|
import org.hibernate.metamodel.source.spi.MetadataImplementor;
|
||||||
import org.hibernate.service.Service;
|
import org.hibernate.service.Service;
|
||||||
import org.hibernate.service.spi.ServiceRegistryImplementor;
|
import org.hibernate.service.spi.ServiceRegistryImplementor;
|
||||||
import org.hibernate.service.spi.SessionFactoryServiceRegistryFactory;
|
import org.hibernate.service.spi.SessionFactoryServiceRegistryFactory;
|
||||||
|
@ -48,4 +49,12 @@ public class SessionFactoryServiceRegistryFactoryImpl implements SessionFactoryS
|
||||||
Configuration configuration) {
|
Configuration configuration) {
|
||||||
return new SessionFactoryServiceRegistryImpl( theBasicServiceRegistry, sessionFactory, configuration );
|
return new SessionFactoryServiceRegistryImpl( theBasicServiceRegistry, sessionFactory, configuration );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SessionFactoryServiceRegistryImpl buildServiceRegistry(
|
||||||
|
SessionFactoryImplementor sessionFactory,
|
||||||
|
MetadataImplementor metadata) {
|
||||||
|
return new SessionFactoryServiceRegistryImpl( theBasicServiceRegistry, sessionFactory, metadata );
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,6 +25,7 @@ package org.hibernate.service.internal;
|
||||||
|
|
||||||
import org.hibernate.cfg.Configuration;
|
import org.hibernate.cfg.Configuration;
|
||||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||||
|
import org.hibernate.metamodel.source.spi.MetadataImplementor;
|
||||||
import org.hibernate.service.Service;
|
import org.hibernate.service.Service;
|
||||||
import org.hibernate.service.StandardSessionFactoryServiceInitiators;
|
import org.hibernate.service.StandardSessionFactoryServiceInitiators;
|
||||||
import org.hibernate.service.spi.ServiceInitiator;
|
import org.hibernate.service.spi.ServiceInitiator;
|
||||||
|
@ -40,6 +41,7 @@ public class SessionFactoryServiceRegistryImpl extends AbstractServiceRegistryIm
|
||||||
|
|
||||||
// for now we need to hold on to the Configuration... :(
|
// for now we need to hold on to the Configuration... :(
|
||||||
private Configuration configuration;
|
private Configuration configuration;
|
||||||
|
private MetadataImplementor metadata;
|
||||||
private final SessionFactoryImplementor sessionFactory;
|
private final SessionFactoryImplementor sessionFactory;
|
||||||
|
|
||||||
@SuppressWarnings( {"unchecked"})
|
@SuppressWarnings( {"unchecked"})
|
||||||
|
@ -51,6 +53,25 @@ public class SessionFactoryServiceRegistryImpl extends AbstractServiceRegistryIm
|
||||||
|
|
||||||
this.sessionFactory = sessionFactory;
|
this.sessionFactory = sessionFactory;
|
||||||
this.configuration = configuration;
|
this.configuration = configuration;
|
||||||
|
this.metadata = null;
|
||||||
|
|
||||||
|
// for now, just use the standard initiator list
|
||||||
|
for ( SessionFactoryServiceInitiator initiator : StandardSessionFactoryServiceInitiators.LIST ) {
|
||||||
|
// create the bindings up front to help identify to which registry services belong
|
||||||
|
createServiceBinding( initiator );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings( {"unchecked"})
|
||||||
|
public SessionFactoryServiceRegistryImpl(
|
||||||
|
ServiceRegistryImplementor parent,
|
||||||
|
SessionFactoryImplementor sessionFactory,
|
||||||
|
MetadataImplementor metadata) {
|
||||||
|
super( parent );
|
||||||
|
|
||||||
|
this.sessionFactory = sessionFactory;
|
||||||
|
this.configuration = null;
|
||||||
|
this.metadata = metadata;
|
||||||
|
|
||||||
// for now, just use the standard initiator list
|
// for now, just use the standard initiator list
|
||||||
for ( SessionFactoryServiceInitiator initiator : StandardSessionFactoryServiceInitiators.LIST ) {
|
for ( SessionFactoryServiceInitiator initiator : StandardSessionFactoryServiceInitiators.LIST ) {
|
||||||
|
@ -62,7 +83,17 @@ public class SessionFactoryServiceRegistryImpl extends AbstractServiceRegistryIm
|
||||||
@Override
|
@Override
|
||||||
public <R extends Service> R initiateService(ServiceInitiator<R> serviceInitiator) {
|
public <R extends Service> R initiateService(ServiceInitiator<R> serviceInitiator) {
|
||||||
// todo : add check/error for unexpected initiator types?
|
// todo : add check/error for unexpected initiator types?
|
||||||
return ( (SessionFactoryServiceInitiator<R>) serviceInitiator ).initiateService( sessionFactory, configuration, this );
|
SessionFactoryServiceInitiator<R> sessionFactoryServiceInitiator =
|
||||||
|
(SessionFactoryServiceInitiator<R>) serviceInitiator;
|
||||||
|
if ( metadata != null ) {
|
||||||
|
return sessionFactoryServiceInitiator.initiateService( sessionFactory, metadata, this );
|
||||||
|
}
|
||||||
|
else if ( configuration != null ) {
|
||||||
|
return sessionFactoryServiceInitiator.initiateService( sessionFactory, configuration, this );
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
throw new IllegalStateException( "Both metadata and configuration are null." );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -25,6 +25,7 @@ package org.hibernate.service.spi;
|
||||||
|
|
||||||
import org.hibernate.cfg.Configuration;
|
import org.hibernate.cfg.Configuration;
|
||||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||||
|
import org.hibernate.metamodel.source.spi.MetadataImplementor;
|
||||||
import org.hibernate.service.Service;
|
import org.hibernate.service.Service;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -44,4 +45,19 @@ public interface SessionFactoryServiceInitiator<R extends Service> extends Servi
|
||||||
* @return The initiated service.
|
* @return The initiated service.
|
||||||
*/
|
*/
|
||||||
public R initiateService(SessionFactoryImplementor sessionFactory, Configuration configuration, ServiceRegistryImplementor registry);
|
public R initiateService(SessionFactoryImplementor sessionFactory, Configuration configuration, ServiceRegistryImplementor registry);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initiates the managed service.
|
||||||
|
* <p/>
|
||||||
|
* Note for implementors: signature is guaranteed to change once redesign of SessionFactory building is complete
|
||||||
|
*
|
||||||
|
* @param sessionFactory The session factory. Note the the session factory is still in flux; care needs to be taken
|
||||||
|
* in regards to what you call.
|
||||||
|
* @param metadata The configuration.
|
||||||
|
* @param registry The service registry. Can be used to locate services needed to fulfill initiation.
|
||||||
|
*
|
||||||
|
* @return The initiated service.
|
||||||
|
*/
|
||||||
|
public R initiateService(SessionFactoryImplementor sessionFactory, MetadataImplementor metadata, ServiceRegistryImplementor registry);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,6 +25,7 @@ package org.hibernate.service.spi;
|
||||||
|
|
||||||
import org.hibernate.cfg.Configuration;
|
import org.hibernate.cfg.Configuration;
|
||||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||||
|
import org.hibernate.metamodel.source.spi.MetadataImplementor;
|
||||||
import org.hibernate.service.Service;
|
import org.hibernate.service.Service;
|
||||||
import org.hibernate.service.internal.SessionFactoryServiceRegistryImpl;
|
import org.hibernate.service.internal.SessionFactoryServiceRegistryImpl;
|
||||||
|
|
||||||
|
@ -50,4 +51,20 @@ public interface SessionFactoryServiceRegistryFactory extends Service {
|
||||||
public SessionFactoryServiceRegistryImpl buildServiceRegistry(
|
public SessionFactoryServiceRegistryImpl buildServiceRegistry(
|
||||||
SessionFactoryImplementor sessionFactory,
|
SessionFactoryImplementor sessionFactory,
|
||||||
Configuration configuration);
|
Configuration configuration);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create the registry.
|
||||||
|
*
|
||||||
|
* @todo : fully expect this signature to change!
|
||||||
|
*
|
||||||
|
* @param sessionFactory The (in flux) session factory. Generally this is useful for grabbing a reference for later
|
||||||
|
* use. However, care should be taken when invoking on the session factory until after it has been fully
|
||||||
|
* initialized.
|
||||||
|
* @param metadata The configuration object.
|
||||||
|
*
|
||||||
|
* @return The registry
|
||||||
|
*/
|
||||||
|
public SessionFactoryServiceRegistryImpl buildServiceRegistry(
|
||||||
|
SessionFactoryImplementor sessionFactory,
|
||||||
|
MetadataImplementor metadata);
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,7 +29,9 @@ import org.hibernate.HibernateException;
|
||||||
import org.hibernate.cfg.Configuration;
|
import org.hibernate.cfg.Configuration;
|
||||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||||
import org.hibernate.internal.CoreMessageLogger;
|
import org.hibernate.internal.CoreMessageLogger;
|
||||||
|
import org.hibernate.metamodel.source.spi.MetadataImplementor;
|
||||||
import org.hibernate.service.classloading.spi.ClassLoaderService;
|
import org.hibernate.service.classloading.spi.ClassLoaderService;
|
||||||
|
import org.hibernate.service.config.spi.ConfigurationService;
|
||||||
import org.hibernate.service.spi.ServiceRegistryImplementor;
|
import org.hibernate.service.spi.ServiceRegistryImplementor;
|
||||||
import org.hibernate.service.spi.SessionFactoryServiceInitiator;
|
import org.hibernate.service.spi.SessionFactoryServiceInitiator;
|
||||||
import org.hibernate.stat.spi.StatisticsFactory;
|
import org.hibernate.stat.spi.StatisticsFactory;
|
||||||
|
@ -60,6 +62,23 @@ public class StatisticsInitiator implements SessionFactoryServiceInitiator<Stati
|
||||||
Configuration configuration,
|
Configuration configuration,
|
||||||
ServiceRegistryImplementor registry) {
|
ServiceRegistryImplementor registry) {
|
||||||
final Object configValue = configuration.getProperties().get( STATS_BUILDER );
|
final Object configValue = configuration.getProperties().get( STATS_BUILDER );
|
||||||
|
return initiateServiceInternal( sessionFactory, configValue, registry );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public StatisticsImplementor initiateService(
|
||||||
|
SessionFactoryImplementor sessionFactory,
|
||||||
|
MetadataImplementor metadata,
|
||||||
|
ServiceRegistryImplementor registry) {
|
||||||
|
ConfigurationService configurationService = registry.getService( ConfigurationService.class );
|
||||||
|
final Object configValue = configurationService.getSetting( STATS_BUILDER, null );
|
||||||
|
return initiateServiceInternal( sessionFactory, configValue, registry );
|
||||||
|
}
|
||||||
|
|
||||||
|
private StatisticsImplementor initiateServiceInternal(
|
||||||
|
SessionFactoryImplementor sessionFactory,
|
||||||
|
Object configValue,
|
||||||
|
ServiceRegistryImplementor registry) {
|
||||||
|
|
||||||
StatisticsFactory statisticsFactory;
|
StatisticsFactory statisticsFactory;
|
||||||
if ( configValue == null ) {
|
if ( configValue == null ) {
|
||||||
|
|
Loading…
Reference in New Issue