HHH-6796 Make the service configuration logic being executed by the owning service registry
This commit is contained in:
parent
944ae2c488
commit
c04442281b
|
@ -43,6 +43,7 @@ import org.hibernate.service.spi.Manageable;
|
|||
import org.hibernate.service.spi.ServiceBinding;
|
||||
import org.hibernate.service.spi.ServiceException;
|
||||
import org.hibernate.service.spi.ServiceInitiator;
|
||||
import org.hibernate.service.spi.ServiceRegistryAwareService;
|
||||
import org.hibernate.service.spi.ServiceRegistryImplementor;
|
||||
import org.hibernate.service.spi.Startable;
|
||||
import org.hibernate.service.spi.Stoppable;
|
||||
|
@ -156,15 +157,26 @@ public abstract class AbstractServiceRegistryImpl implements ServiceRegistryImpl
|
|||
return null;
|
||||
}
|
||||
|
||||
// PHASE 2 : configure service (***potentially recursive***)
|
||||
configureService( service );
|
||||
// PHASE 2 : inject service (***potentially recursive***)
|
||||
injectService( service );
|
||||
|
||||
// PHASE 3 : Start service
|
||||
// PHASE 3 : configure service
|
||||
serviceBinding.getServiceRegistry().configureService( service );
|
||||
|
||||
// PHASE 4 : Start service
|
||||
startService( serviceBinding );
|
||||
|
||||
return service;
|
||||
}
|
||||
|
||||
protected <T extends Service> void injectService(T service) {
|
||||
applyInjections( service );
|
||||
|
||||
if ( ServiceRegistryAwareService.class.isInstance( service ) ) {
|
||||
( (ServiceRegistryAwareService) service ).injectServices( this );
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings( {"unchecked"})
|
||||
protected <R extends Service> R createService(ServiceBinding<R> serviceBinding) {
|
||||
final ServiceInitiator<R> serviceInitiator = serviceBinding.getServiceInitiator();
|
||||
|
@ -188,8 +200,6 @@ public abstract class AbstractServiceRegistryImpl implements ServiceRegistryImpl
|
|||
}
|
||||
}
|
||||
|
||||
protected abstract <T extends Service> void configureService(T service);
|
||||
|
||||
protected <T extends Service> void applyInjections(T service) {
|
||||
try {
|
||||
for ( Method method : service.getClass().getMethods() ) {
|
||||
|
|
|
@ -116,4 +116,9 @@ public class BootstrapServiceRegistryImpl
|
|||
throw new ServiceException( "Boot-strap registry should only contain directly built services" );
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R extends Service> void configureService(R service) {
|
||||
//nothing do to for bootstrap style services
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -96,11 +96,7 @@ public class SessionFactoryServiceRegistryImpl extends AbstractServiceRegistryIm
|
|||
}
|
||||
|
||||
@Override
|
||||
protected <T extends Service> void configureService(T service) {
|
||||
applyInjections( service );
|
||||
|
||||
if ( ServiceRegistryAwareService.class.isInstance( service ) ) {
|
||||
( (ServiceRegistryAwareService) service ).injectServices( this );
|
||||
}
|
||||
public <T extends Service> void configureService(T service) {
|
||||
//TODO nothing to do here or should we inject SessionFactory properties?
|
||||
}
|
||||
}
|
||||
|
|
|
@ -70,13 +70,7 @@ public class StandardServiceRegistryImpl extends AbstractServiceRegistryImpl imp
|
|||
}
|
||||
|
||||
@Override
|
||||
protected <T extends Service> void configureService(T service) {
|
||||
applyInjections( service );
|
||||
|
||||
if ( ServiceRegistryAwareService.class.isInstance( service ) ) {
|
||||
( (ServiceRegistryAwareService) service ).injectServices( this );
|
||||
}
|
||||
|
||||
public <T extends Service> void configureService(T service) {
|
||||
if ( Configurable.class.isInstance( service ) ) {
|
||||
( (Configurable) service ).configure( configurationValues );
|
||||
}
|
||||
|
|
|
@ -37,6 +37,7 @@ public final class ServiceBinding<R extends Service> {
|
|||
|
||||
public static interface OwningRegistry {
|
||||
public <R extends Service> R initiateService(ServiceInitiator<R> serviceInitiator);
|
||||
public <R extends Service> void configureService(R service);
|
||||
}
|
||||
|
||||
private final OwningRegistry serviceRegistry;
|
||||
|
|
Loading…
Reference in New Issue