HHH-6683 - Consolidate (consistency) building of service registries

This commit is contained in:
Steve Ebersole 2011-09-27 12:45:07 -05:00
parent f4fa176255
commit e14e47968f
10 changed files with 64 additions and 20 deletions

View File

@ -0,0 +1,33 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2011, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to:
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.service;
/**
* Specialization of the {@link ServiceRegistry} contract mainly to make the
* {@link ServiceRegistryBuilder#ServiceRegistryBuilder(BootstrapServiceRegistry)} signature type-safe
*
* @author Steve Ebersole
*/
public interface BootstrapServiceRegistry extends ServiceRegistry {
}

View File

@ -36,7 +36,7 @@ import org.hibernate.service.internal.BootstrapServiceRegistryImpl;
* @author Steve Ebersole
*
* @see BootstrapServiceRegistryImpl
* @see ServiceRegistryBuilder#ServiceRegistryBuilder(BootstrapServiceRegistryImpl)
* @see ServiceRegistryBuilder#ServiceRegistryBuilder(BootstrapServiceRegistry)
*/
public class BootstrapServiceRegistryBuilder {
private final LinkedHashSet<Integrator> providedIntegrators = new LinkedHashSet<Integrator>();
@ -109,7 +109,7 @@ public class BootstrapServiceRegistryBuilder {
*
* @return The built bootstrap registry
*/
public ServiceRegistry build() {
public BootstrapServiceRegistry build() {
final ClassLoaderServiceImpl classLoaderService = new ClassLoaderServiceImpl(
applicationClassLoader,
resourcesClassLoader,

View File

@ -67,7 +67,7 @@ public class ServiceRegistryBuilder {
private final List<BasicServiceInitiator> initiators = standardInitiatorList();
private final List<ProvidedService> providedServices = new ArrayList<ProvidedService>();
private final BootstrapServiceRegistryImpl bootstrapServiceRegistry;
private final BootstrapServiceRegistry bootstrapServiceRegistry;
/**
* Create a default builder
@ -81,7 +81,7 @@ public class ServiceRegistryBuilder {
*
* @param bootstrapServiceRegistry Provided bootstrap registry to use.
*/
public ServiceRegistryBuilder(BootstrapServiceRegistryImpl bootstrapServiceRegistry) {
public ServiceRegistryBuilder(BootstrapServiceRegistry bootstrapServiceRegistry) {
this.settings = Environment.getProperties();
this.bootstrapServiceRegistry = bootstrapServiceRegistry;
}

View File

@ -33,6 +33,7 @@ import org.jboss.logging.Logger;
import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.internal.util.collections.CollectionHelper;
import org.hibernate.service.BootstrapServiceRegistry;
import org.hibernate.service.Service;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.service.UnknownServiceException;
@ -61,16 +62,29 @@ public abstract class AbstractServiceRegistryImpl implements ServiceRegistryImpl
@SuppressWarnings( {"UnusedDeclaration"})
protected AbstractServiceRegistryImpl() {
this( null );
this( (ServiceRegistryImplementor) null );
}
protected AbstractServiceRegistryImpl(ServiceRegistryImplementor parent) {
this.parent = parent;
prepare();
}
private void prepare() {
// assume 20 services for initial sizing
this.serviceBindingMap = CollectionHelper.concurrentMap( 20 );
this.serviceList = CollectionHelper.arrayList( 20 );
}
public AbstractServiceRegistryImpl(BootstrapServiceRegistry bootstrapServiceRegistry) {
if ( ! ServiceRegistryImplementor.class.isInstance( bootstrapServiceRegistry ) ) {
throw new IllegalArgumentException( "Boot-strap registry was not " );
}
this.parent = (ServiceRegistryImplementor) bootstrapServiceRegistry;
prepare();
}
@SuppressWarnings({ "unchecked" })
protected <R extends Service> void createServiceBinding(ServiceInitiator<R> initiator) {
serviceBindingMap.put( initiator.getServiceInitiated(), new ServiceBinding( this, initiator ) );

View File

@ -28,7 +28,7 @@ import java.util.LinkedHashSet;
import org.hibernate.integrator.internal.IntegratorServiceImpl;
import org.hibernate.integrator.spi.Integrator;
import org.hibernate.integrator.spi.IntegratorService;
import org.hibernate.service.BootstrapServiceRegistryBuilder;
import org.hibernate.service.BootstrapServiceRegistry;
import org.hibernate.service.Service;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.service.classloading.internal.ClassLoaderServiceImpl;
@ -46,16 +46,13 @@ import org.hibernate.service.spi.ServiceRegistryImplementor;
*
* @author Steve Ebersole
*/
public class BootstrapServiceRegistryImpl implements ServiceRegistryImplementor, ServiceBinding.OwningRegistry {
public class BootstrapServiceRegistryImpl
implements ServiceRegistryImplementor, BootstrapServiceRegistry, ServiceBinding.OwningRegistry {
private static final LinkedHashSet<Integrator> NO_INTEGRATORS = new LinkedHashSet<Integrator>();
private final ServiceBinding<ClassLoaderService> classLoaderServiceBinding;
private final ServiceBinding<IntegratorService> integratorServiceBinding;
public static BootstrapServiceRegistryBuilder builder() {
return new BootstrapServiceRegistryBuilder();
}
public BootstrapServiceRegistryImpl() {
this( new ClassLoaderServiceImpl(), NO_INTEGRATORS );
}

View File

@ -26,6 +26,7 @@ package org.hibernate.service.internal;
import java.util.List;
import java.util.Map;
import org.hibernate.service.BootstrapServiceRegistry;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.service.Service;
import org.hibernate.service.spi.BasicServiceInitiator;
@ -44,7 +45,7 @@ public class StandardServiceRegistryImpl extends AbstractServiceRegistryImpl imp
@SuppressWarnings( {"unchecked"})
public StandardServiceRegistryImpl(
ServiceRegistryImplementor bootstrapServiceRegistry,
BootstrapServiceRegistry bootstrapServiceRegistry,
List<BasicServiceInitiator> serviceInitiators,
List<ProvidedService> providedServices,
Map<?, ?> configurationValues) {

View File

@ -884,7 +884,7 @@ public class Ejb3Configuration implements Serializable, Referenceable {
}
public EntityManagerFactory buildEntityManagerFactory() {
return buildEntityManagerFactory( BootstrapServiceRegistryImpl.builder() );
return buildEntityManagerFactory( new BootstrapServiceRegistryBuilder() );
}
public EntityManagerFactory buildEntityManagerFactory(BootstrapServiceRegistryBuilder builder) {

View File

@ -46,7 +46,6 @@ import org.hibernate.internal.SessionFactoryImpl;
import org.hibernate.service.BootstrapServiceRegistryBuilder;
import org.hibernate.service.ServiceRegistryBuilder;
import org.hibernate.service.internal.StandardServiceRegistryImpl;
import org.hibernate.service.internal.BootstrapServiceRegistryImpl;
import org.junit.After;
import org.junit.Before;
@ -101,7 +100,7 @@ public abstract class BaseEntityManagerFunctionalTestCase extends BaseUnitTestCa
}
private BootstrapServiceRegistryBuilder bootstrapRegistryBuilder() {
return BootstrapServiceRegistryImpl.builder();
return new BootstrapServiceRegistryBuilder();
}
protected Ejb3Configuration buildConfiguration() {

View File

@ -36,7 +36,6 @@ import org.hibernate.envers.event.EnversIntegrator;
import org.hibernate.internal.SessionFactoryImpl;
import org.hibernate.service.BootstrapServiceRegistryBuilder;
import org.hibernate.service.internal.StandardServiceRegistryImpl;
import org.hibernate.service.internal.BootstrapServiceRegistryImpl;
import org.junit.Before;
@ -115,7 +114,7 @@ public abstract class AbstractEntityTest extends AbstractEnversTest {
}
private BootstrapServiceRegistryBuilder createBootstrapRegistryBuilder() {
return BootstrapServiceRegistryImpl.builder();
return new BootstrapServiceRegistryBuilder();
}

View File

@ -53,6 +53,7 @@ import org.hibernate.mapping.Property;
import org.hibernate.mapping.SimpleValue;
import org.hibernate.metamodel.MetadataSources;
import org.hibernate.metamodel.source.MetadataImplementor;
import org.hibernate.service.BootstrapServiceRegistry;
import org.hibernate.service.BootstrapServiceRegistryBuilder;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.service.ServiceRegistryBuilder;
@ -325,15 +326,15 @@ public abstract class BaseCoreFunctionalTestCase extends BaseUnitTestCase {
Environment.verifyProperties( properties );
ConfigurationHelper.resolvePlaceHolders( properties );
final BootstrapServiceRegistryImpl bootstrapServiceRegistry = generateBootstrapRegistry( properties );
final BootstrapServiceRegistry bootstrapServiceRegistry = generateBootstrapRegistry( properties );
ServiceRegistryBuilder registryBuilder = new ServiceRegistryBuilder( bootstrapServiceRegistry )
.applySettings( properties );
prepareBasicRegistryBuilder( registryBuilder );
return (StandardServiceRegistryImpl) registryBuilder.buildServiceRegistry();
}
protected BootstrapServiceRegistryImpl generateBootstrapRegistry(Properties properties) {
final BootstrapServiceRegistryBuilder builder = BootstrapServiceRegistryImpl.builder();
protected BootstrapServiceRegistry generateBootstrapRegistry(Properties properties) {
final BootstrapServiceRegistryBuilder builder = new BootstrapServiceRegistryBuilder();
prepareBootstrapRegistryBuilder( builder );
return builder.build();
}