Merge pull request #92 from gbadner/HHH-6267-metadata-to-svc-initiators
HHH-6267 : Plumb MetadataImplementor into service initiators registered i
This commit is contained in:
commit
b11dafbc26
|
@ -26,6 +26,7 @@ package org.hibernate.event.service.internal;
|
|||
import org.hibernate.cfg.Configuration;
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
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.SessionFactoryServiceInitiator;
|
||||
|
||||
|
@ -50,4 +51,11 @@ public class EventListenerServiceInitiator implements SessionFactoryServiceIniti
|
|||
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.CollectionRegionAccessStrategy;
|
||||
import org.hibernate.cache.spi.access.EntityRegionAccessStrategy;
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
import org.hibernate.cfg.Configuration;
|
||||
import org.hibernate.cfg.Environment;
|
||||
import org.hibernate.cfg.Settings;
|
||||
|
@ -123,6 +124,7 @@ import org.hibernate.pretty.MessageHelper;
|
|||
import org.hibernate.proxy.EntityNotFoundDelegate;
|
||||
import org.hibernate.service.ServiceRegistry;
|
||||
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.jndi.spi.JndiService;
|
||||
import org.hibernate.service.jta.platform.spi.JtaPlatform;
|
||||
|
@ -181,7 +183,7 @@ public final class SessionFactoryImpl
|
|||
private final transient Map namedQueries;
|
||||
private final transient Map namedSqlQueries;
|
||||
private final transient Map sqlResultSetMappings;
|
||||
private final transient Map filters;
|
||||
private final transient Map<String, FilterDefinition> filters;
|
||||
private final transient Map fetchProfiles;
|
||||
private final transient Map imports;
|
||||
private final transient Interceptor interceptor;
|
||||
|
@ -205,6 +207,7 @@ public final class SessionFactoryImpl
|
|||
private final transient TypeHelper typeHelper;
|
||||
private final transient TransactionEnvironment transactionEnvironment;
|
||||
|
||||
@SuppressWarnings( {"unchecked"} )
|
||||
public SessionFactoryImpl(
|
||||
Configuration cfg,
|
||||
Mapping mapping,
|
||||
|
@ -231,7 +234,7 @@ public final class SessionFactoryImpl
|
|||
this.typeResolver = cfg.getTypeResolver().scope( this );
|
||||
this.typeHelper = new TypeLocatorImpl( typeResolver );
|
||||
|
||||
this.filters = new HashMap();
|
||||
this.filters = new HashMap<String, FilterDefinition>();
|
||||
this.filters.putAll( cfg.getFilterDefinitions() );
|
||||
|
||||
LOG.debugf("Session factory constructed with filter configurations : %s", filters);
|
||||
|
@ -523,13 +526,9 @@ public final class SessionFactoryImpl
|
|||
this.namedQueries = null;
|
||||
this.namedSqlQueries = null;
|
||||
this.sqlResultSetMappings = null;
|
||||
this.filters = null;
|
||||
this.fetchProfiles = null;
|
||||
this.imports = null;
|
||||
this.interceptor = null;
|
||||
this.serviceRegistry = null;
|
||||
this.settings = null;
|
||||
this.properties = null;
|
||||
this.queryCache = null;
|
||||
this.updateTimestampsCache = null;
|
||||
this.queryCaches = null;
|
||||
|
@ -537,10 +536,40 @@ public final class SessionFactoryImpl
|
|||
this.entityNotFoundDelegate = null;
|
||||
this.sqlFunctionRegistry = null;
|
||||
this.queryPlanCache = null;
|
||||
this.typeResolver = null;
|
||||
this.typeHelper = 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<String, FilterDefinition>();
|
||||
for ( FilterDefinition filterDefinition : metadata.getFilterDefinitions() ) {
|
||||
filters.put( filterDefinition.getFilterName(), filterDefinition );
|
||||
}
|
||||
|
||||
LOG.debugf("Session factory constructed with filter configurations : %s", filters);
|
||||
LOG.debugf("Instantiating session factory with properties: %s", configurationService.getSettings() );
|
||||
|
||||
// TODO: implement
|
||||
|
||||
}
|
||||
|
|
|
@ -25,6 +25,7 @@ package org.hibernate.service.internal;
|
|||
|
||||
import org.hibernate.cfg.Configuration;
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.metamodel.source.spi.MetadataImplementor;
|
||||
import org.hibernate.service.Service;
|
||||
import org.hibernate.service.spi.ServiceRegistryImplementor;
|
||||
import org.hibernate.service.spi.SessionFactoryServiceRegistryFactory;
|
||||
|
@ -48,4 +49,12 @@ public class SessionFactoryServiceRegistryFactoryImpl implements SessionFactoryS
|
|||
Configuration 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.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.metamodel.source.spi.MetadataImplementor;
|
||||
import org.hibernate.service.Service;
|
||||
import org.hibernate.service.StandardSessionFactoryServiceInitiators;
|
||||
import org.hibernate.service.spi.ServiceInitiator;
|
||||
|
@ -39,7 +40,8 @@ import org.hibernate.service.spi.SessionFactoryServiceRegistry;
|
|||
public class SessionFactoryServiceRegistryImpl extends AbstractServiceRegistryImpl implements SessionFactoryServiceRegistry {
|
||||
|
||||
// for now we need to hold on to the Configuration... :(
|
||||
private Configuration configuration;
|
||||
private final Configuration configuration;
|
||||
private final MetadataImplementor metadata;
|
||||
private final SessionFactoryImplementor sessionFactory;
|
||||
|
||||
@SuppressWarnings( {"unchecked"})
|
||||
|
@ -51,6 +53,25 @@ public class SessionFactoryServiceRegistryImpl extends AbstractServiceRegistryIm
|
|||
|
||||
this.sessionFactory = sessionFactory;
|
||||
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 ( SessionFactoryServiceInitiator initiator : StandardSessionFactoryServiceInitiators.LIST ) {
|
||||
|
@ -62,7 +83,17 @@ public class SessionFactoryServiceRegistryImpl extends AbstractServiceRegistryIm
|
|||
@Override
|
||||
public <R extends Service> R initiateService(ServiceInitiator<R> serviceInitiator) {
|
||||
// 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
|
||||
|
|
|
@ -25,6 +25,7 @@ package org.hibernate.service.spi;
|
|||
|
||||
import org.hibernate.cfg.Configuration;
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.metamodel.source.spi.MetadataImplementor;
|
||||
import org.hibernate.service.Service;
|
||||
|
||||
/**
|
||||
|
@ -44,4 +45,19 @@ public interface SessionFactoryServiceInitiator<R extends Service> extends Servi
|
|||
* @return The initiated service.
|
||||
*/
|
||||
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.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.metamodel.source.spi.MetadataImplementor;
|
||||
import org.hibernate.service.Service;
|
||||
import org.hibernate.service.internal.SessionFactoryServiceRegistryImpl;
|
||||
|
||||
|
@ -50,4 +51,20 @@ public interface SessionFactoryServiceRegistryFactory extends Service {
|
|||
public SessionFactoryServiceRegistryImpl buildServiceRegistry(
|
||||
SessionFactoryImplementor sessionFactory,
|
||||
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.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.internal.CoreMessageLogger;
|
||||
import org.hibernate.metamodel.source.spi.MetadataImplementor;
|
||||
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.SessionFactoryServiceInitiator;
|
||||
import org.hibernate.stat.spi.StatisticsFactory;
|
||||
|
@ -60,6 +62,23 @@ public class StatisticsInitiator implements SessionFactoryServiceInitiator<Stati
|
|||
Configuration configuration,
|
||||
ServiceRegistryImplementor registry) {
|
||||
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;
|
||||
if ( configValue == null ) {
|
||||
|
|
Loading…
Reference in New Issue