diff --git a/hibernate-core/src/main/java/org/hibernate/service/internal/AbstractServiceRegistryImpl.java b/hibernate-core/src/main/java/org/hibernate/service/internal/AbstractServiceRegistryImpl.java index 2822492d45..f8dfb2032c 100644 --- a/hibernate-core/src/main/java/org/hibernate/service/internal/AbstractServiceRegistryImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/service/internal/AbstractServiceRegistryImpl.java @@ -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 void injectService(T service) { + applyInjections( service ); + + if ( ServiceRegistryAwareService.class.isInstance( service ) ) { + ( (ServiceRegistryAwareService) service ).injectServices( this ); + } + } + @SuppressWarnings( {"unchecked"}) protected R createService(ServiceBinding serviceBinding) { final ServiceInitiator serviceInitiator = serviceBinding.getServiceInitiator(); @@ -188,8 +200,6 @@ public abstract class AbstractServiceRegistryImpl implements ServiceRegistryImpl } } - protected abstract void configureService(T service); - protected void applyInjections(T service) { try { for ( Method method : service.getClass().getMethods() ) { diff --git a/hibernate-core/src/main/java/org/hibernate/service/internal/BootstrapServiceRegistryImpl.java b/hibernate-core/src/main/java/org/hibernate/service/internal/BootstrapServiceRegistryImpl.java index 033698de0a..e1eedf4a98 100644 --- a/hibernate-core/src/main/java/org/hibernate/service/internal/BootstrapServiceRegistryImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/service/internal/BootstrapServiceRegistryImpl.java @@ -116,4 +116,9 @@ public class BootstrapServiceRegistryImpl throw new ServiceException( "Boot-strap registry should only contain directly built services" ); } + @Override + public void configureService(R service) { + //nothing do to for bootstrap style services + } + } diff --git a/hibernate-core/src/main/java/org/hibernate/service/internal/SessionFactoryServiceRegistryImpl.java b/hibernate-core/src/main/java/org/hibernate/service/internal/SessionFactoryServiceRegistryImpl.java index 48243fd918..a89bd86c20 100644 --- a/hibernate-core/src/main/java/org/hibernate/service/internal/SessionFactoryServiceRegistryImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/service/internal/SessionFactoryServiceRegistryImpl.java @@ -96,11 +96,7 @@ public class SessionFactoryServiceRegistryImpl extends AbstractServiceRegistryIm } @Override - protected void configureService(T service) { - applyInjections( service ); - - if ( ServiceRegistryAwareService.class.isInstance( service ) ) { - ( (ServiceRegistryAwareService) service ).injectServices( this ); - } + public void configureService(T service) { + //TODO nothing to do here or should we inject SessionFactory properties? } } diff --git a/hibernate-core/src/main/java/org/hibernate/service/internal/StandardServiceRegistryImpl.java b/hibernate-core/src/main/java/org/hibernate/service/internal/StandardServiceRegistryImpl.java index 39bf9f6829..0f8b39551c 100644 --- a/hibernate-core/src/main/java/org/hibernate/service/internal/StandardServiceRegistryImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/service/internal/StandardServiceRegistryImpl.java @@ -70,13 +70,7 @@ public class StandardServiceRegistryImpl extends AbstractServiceRegistryImpl imp } @Override - protected void configureService(T service) { - applyInjections( service ); - - if ( ServiceRegistryAwareService.class.isInstance( service ) ) { - ( (ServiceRegistryAwareService) service ).injectServices( this ); - } - + public void configureService(T service) { if ( Configurable.class.isInstance( service ) ) { ( (Configurable) service ).configure( configurationValues ); } diff --git a/hibernate-core/src/main/java/org/hibernate/service/spi/ServiceBinding.java b/hibernate-core/src/main/java/org/hibernate/service/spi/ServiceBinding.java index d34629d8bb..a6b934c0a7 100644 --- a/hibernate-core/src/main/java/org/hibernate/service/spi/ServiceBinding.java +++ b/hibernate-core/src/main/java/org/hibernate/service/spi/ServiceBinding.java @@ -37,6 +37,7 @@ public final class ServiceBinding { public static interface OwningRegistry { public R initiateService(ServiceInitiator serviceInitiator); + public void configureService(R service); } private final OwningRegistry serviceRegistry;