HHH-6051 - Create a SessionFactory scoped ServiceRegistry

This commit is contained in:
Steve Ebersole 2011-03-25 10:54:18 -05:00
parent 7ece2ee52f
commit d4783bdaeb
2 changed files with 16 additions and 5 deletions

View File

@ -104,13 +104,18 @@ public abstract class AbstractServiceRegistryImpl implements ServiceRegistryImpl
protected <R extends Service> ServiceBinding<R> locateOrCreateServiceBinding(Class<R> serviceRole, boolean checkParent) {
ServiceBinding<R> serviceBinding = locateServiceBinding( serviceRole, checkParent );
if ( serviceBinding == null ) {
R proxy = serviceProxyFactory.makeProxy( serviceRole );
serviceBinding = new ServiceBinding<R>( proxy );
serviceBindingMap.put( serviceRole, serviceBinding );
createServiceBinding( serviceRole );
}
return serviceBinding;
}
protected <R extends Service> ServiceBinding<R> createServiceBinding(Class<R> serviceRole) {
R proxy = serviceProxyFactory.makeProxy( serviceRole );
ServiceBinding<R> serviceBinding = new ServiceBinding<R>( proxy );
serviceBindingMap.put( serviceRole, serviceBinding );
return serviceBinding;
}
@Override
public <R extends Service> void registerService(Class<R> serviceRole, R service) {
ServiceBinding<R> serviceBinding = locateOrCreateServiceBinding( serviceRole, false );

View File

@ -23,7 +23,6 @@
*/
package org.hibernate.service.internal;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ -37,7 +36,6 @@ import org.hibernate.service.StandardServiceInitiators;
import org.hibernate.service.UnknownServiceException;
import org.hibernate.service.spi.BasicServiceInitiator;
import org.hibernate.service.spi.Configurable;
import org.hibernate.service.spi.InjectService;
import org.hibernate.service.spi.ServiceException;
import org.hibernate.service.spi.ServiceRegistryAwareService;
@ -56,10 +54,15 @@ public class BasicServiceRegistryImpl extends AbstractServiceRegistryImpl implem
this( StandardServiceInitiators.LIST, configurationValues );
}
@SuppressWarnings( {"unchecked"})
public BasicServiceRegistryImpl(List<BasicServiceInitiator> serviceInitiators, Map configurationValues) {
super();
this.serviceInitiatorMap = toMap( serviceInitiators );
this.configurationValues = configurationValues;
for ( BasicServiceInitiator initiator : serviceInitiatorMap.values() ) {
// create the bindings up front to help identify to which registry services belong
createServiceBinding( initiator.getServiceInitiated() );
}
}
/**
@ -87,6 +90,9 @@ public class BasicServiceRegistryImpl extends AbstractServiceRegistryImpl implem
if ( serviceBinding != null ) {
serviceBinding.setTarget( null );
}
else {
createServiceBinding( initiator.getServiceInitiated() );
}
final Object previous = serviceInitiatorMap.put( initiator.getServiceInitiated(), initiator );
if ( previous != null ) {
LOG.debugf( "Over-wrote existing service initiator [role=%s]", initiator.getServiceInitiated().getName() );