HHH-6051 - Create a SessionFactory scoped ServiceRegistry
This commit is contained in:
parent
7ece2ee52f
commit
d4783bdaeb
|
@ -104,13 +104,18 @@ public abstract class AbstractServiceRegistryImpl implements ServiceRegistryImpl
|
||||||
protected <R extends Service> ServiceBinding<R> locateOrCreateServiceBinding(Class<R> serviceRole, boolean checkParent) {
|
protected <R extends Service> ServiceBinding<R> locateOrCreateServiceBinding(Class<R> serviceRole, boolean checkParent) {
|
||||||
ServiceBinding<R> serviceBinding = locateServiceBinding( serviceRole, checkParent );
|
ServiceBinding<R> serviceBinding = locateServiceBinding( serviceRole, checkParent );
|
||||||
if ( serviceBinding == null ) {
|
if ( serviceBinding == null ) {
|
||||||
R proxy = serviceProxyFactory.makeProxy( serviceRole );
|
createServiceBinding( serviceRole );
|
||||||
serviceBinding = new ServiceBinding<R>( proxy );
|
|
||||||
serviceBindingMap.put( serviceRole, serviceBinding );
|
|
||||||
}
|
}
|
||||||
return serviceBinding;
|
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
|
@Override
|
||||||
public <R extends Service> void registerService(Class<R> serviceRole, R service) {
|
public <R extends Service> void registerService(Class<R> serviceRole, R service) {
|
||||||
ServiceBinding<R> serviceBinding = locateOrCreateServiceBinding( serviceRole, false );
|
ServiceBinding<R> serviceBinding = locateOrCreateServiceBinding( serviceRole, false );
|
||||||
|
|
|
@ -23,7 +23,6 @@
|
||||||
*/
|
*/
|
||||||
package org.hibernate.service.internal;
|
package org.hibernate.service.internal;
|
||||||
|
|
||||||
import java.lang.reflect.Method;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -37,7 +36,6 @@ import org.hibernate.service.StandardServiceInitiators;
|
||||||
import org.hibernate.service.UnknownServiceException;
|
import org.hibernate.service.UnknownServiceException;
|
||||||
import org.hibernate.service.spi.BasicServiceInitiator;
|
import org.hibernate.service.spi.BasicServiceInitiator;
|
||||||
import org.hibernate.service.spi.Configurable;
|
import org.hibernate.service.spi.Configurable;
|
||||||
import org.hibernate.service.spi.InjectService;
|
|
||||||
import org.hibernate.service.spi.ServiceException;
|
import org.hibernate.service.spi.ServiceException;
|
||||||
import org.hibernate.service.spi.ServiceRegistryAwareService;
|
import org.hibernate.service.spi.ServiceRegistryAwareService;
|
||||||
|
|
||||||
|
@ -56,10 +54,15 @@ public class BasicServiceRegistryImpl extends AbstractServiceRegistryImpl implem
|
||||||
this( StandardServiceInitiators.LIST, configurationValues );
|
this( StandardServiceInitiators.LIST, configurationValues );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings( {"unchecked"})
|
||||||
public BasicServiceRegistryImpl(List<BasicServiceInitiator> serviceInitiators, Map configurationValues) {
|
public BasicServiceRegistryImpl(List<BasicServiceInitiator> serviceInitiators, Map configurationValues) {
|
||||||
super();
|
super();
|
||||||
this.serviceInitiatorMap = toMap( serviceInitiators );
|
this.serviceInitiatorMap = toMap( serviceInitiators );
|
||||||
this.configurationValues = configurationValues;
|
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 ) {
|
if ( serviceBinding != null ) {
|
||||||
serviceBinding.setTarget( null );
|
serviceBinding.setTarget( null );
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
createServiceBinding( initiator.getServiceInitiated() );
|
||||||
|
}
|
||||||
final Object previous = serviceInitiatorMap.put( initiator.getServiceInitiated(), initiator );
|
final Object previous = serviceInitiatorMap.put( initiator.getServiceInitiated(), initiator );
|
||||||
if ( previous != null ) {
|
if ( previous != null ) {
|
||||||
LOG.debugf( "Over-wrote existing service initiator [role=%s]", initiator.getServiceInitiated().getName() );
|
LOG.debugf( "Over-wrote existing service initiator [role=%s]", initiator.getServiceInitiated().getName() );
|
||||||
|
|
Loading…
Reference in New Issue