HHH-6683 - Consolidate (consistency) building of service registries
This commit is contained in:
parent
f4fa176255
commit
e14e47968f
|
@ -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 {
|
||||||
|
}
|
|
@ -36,7 +36,7 @@ import org.hibernate.service.internal.BootstrapServiceRegistryImpl;
|
||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
*
|
*
|
||||||
* @see BootstrapServiceRegistryImpl
|
* @see BootstrapServiceRegistryImpl
|
||||||
* @see ServiceRegistryBuilder#ServiceRegistryBuilder(BootstrapServiceRegistryImpl)
|
* @see ServiceRegistryBuilder#ServiceRegistryBuilder(BootstrapServiceRegistry)
|
||||||
*/
|
*/
|
||||||
public class BootstrapServiceRegistryBuilder {
|
public class BootstrapServiceRegistryBuilder {
|
||||||
private final LinkedHashSet<Integrator> providedIntegrators = new LinkedHashSet<Integrator>();
|
private final LinkedHashSet<Integrator> providedIntegrators = new LinkedHashSet<Integrator>();
|
||||||
|
@ -109,7 +109,7 @@ public class BootstrapServiceRegistryBuilder {
|
||||||
*
|
*
|
||||||
* @return The built bootstrap registry
|
* @return The built bootstrap registry
|
||||||
*/
|
*/
|
||||||
public ServiceRegistry build() {
|
public BootstrapServiceRegistry build() {
|
||||||
final ClassLoaderServiceImpl classLoaderService = new ClassLoaderServiceImpl(
|
final ClassLoaderServiceImpl classLoaderService = new ClassLoaderServiceImpl(
|
||||||
applicationClassLoader,
|
applicationClassLoader,
|
||||||
resourcesClassLoader,
|
resourcesClassLoader,
|
||||||
|
|
|
@ -67,7 +67,7 @@ public class ServiceRegistryBuilder {
|
||||||
private final List<BasicServiceInitiator> initiators = standardInitiatorList();
|
private final List<BasicServiceInitiator> initiators = standardInitiatorList();
|
||||||
private final List<ProvidedService> providedServices = new ArrayList<ProvidedService>();
|
private final List<ProvidedService> providedServices = new ArrayList<ProvidedService>();
|
||||||
|
|
||||||
private final BootstrapServiceRegistryImpl bootstrapServiceRegistry;
|
private final BootstrapServiceRegistry bootstrapServiceRegistry;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a default builder
|
* Create a default builder
|
||||||
|
@ -81,7 +81,7 @@ public class ServiceRegistryBuilder {
|
||||||
*
|
*
|
||||||
* @param bootstrapServiceRegistry Provided bootstrap registry to use.
|
* @param bootstrapServiceRegistry Provided bootstrap registry to use.
|
||||||
*/
|
*/
|
||||||
public ServiceRegistryBuilder(BootstrapServiceRegistryImpl bootstrapServiceRegistry) {
|
public ServiceRegistryBuilder(BootstrapServiceRegistry bootstrapServiceRegistry) {
|
||||||
this.settings = Environment.getProperties();
|
this.settings = Environment.getProperties();
|
||||||
this.bootstrapServiceRegistry = bootstrapServiceRegistry;
|
this.bootstrapServiceRegistry = bootstrapServiceRegistry;
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,6 +33,7 @@ import org.jboss.logging.Logger;
|
||||||
|
|
||||||
import org.hibernate.internal.CoreMessageLogger;
|
import org.hibernate.internal.CoreMessageLogger;
|
||||||
import org.hibernate.internal.util.collections.CollectionHelper;
|
import org.hibernate.internal.util.collections.CollectionHelper;
|
||||||
|
import org.hibernate.service.BootstrapServiceRegistry;
|
||||||
import org.hibernate.service.Service;
|
import org.hibernate.service.Service;
|
||||||
import org.hibernate.service.ServiceRegistry;
|
import org.hibernate.service.ServiceRegistry;
|
||||||
import org.hibernate.service.UnknownServiceException;
|
import org.hibernate.service.UnknownServiceException;
|
||||||
|
@ -61,16 +62,29 @@ public abstract class AbstractServiceRegistryImpl implements ServiceRegistryImpl
|
||||||
|
|
||||||
@SuppressWarnings( {"UnusedDeclaration"})
|
@SuppressWarnings( {"UnusedDeclaration"})
|
||||||
protected AbstractServiceRegistryImpl() {
|
protected AbstractServiceRegistryImpl() {
|
||||||
this( null );
|
this( (ServiceRegistryImplementor) null );
|
||||||
}
|
}
|
||||||
|
|
||||||
protected AbstractServiceRegistryImpl(ServiceRegistryImplementor parent) {
|
protected AbstractServiceRegistryImpl(ServiceRegistryImplementor parent) {
|
||||||
this.parent = parent;
|
this.parent = parent;
|
||||||
|
prepare();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void prepare() {
|
||||||
// assume 20 services for initial sizing
|
// assume 20 services for initial sizing
|
||||||
this.serviceBindingMap = CollectionHelper.concurrentMap( 20 );
|
this.serviceBindingMap = CollectionHelper.concurrentMap( 20 );
|
||||||
this.serviceList = CollectionHelper.arrayList( 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" })
|
@SuppressWarnings({ "unchecked" })
|
||||||
protected <R extends Service> void createServiceBinding(ServiceInitiator<R> initiator) {
|
protected <R extends Service> void createServiceBinding(ServiceInitiator<R> initiator) {
|
||||||
serviceBindingMap.put( initiator.getServiceInitiated(), new ServiceBinding( this, initiator ) );
|
serviceBindingMap.put( initiator.getServiceInitiated(), new ServiceBinding( this, initiator ) );
|
||||||
|
|
|
@ -28,7 +28,7 @@ import java.util.LinkedHashSet;
|
||||||
import org.hibernate.integrator.internal.IntegratorServiceImpl;
|
import org.hibernate.integrator.internal.IntegratorServiceImpl;
|
||||||
import org.hibernate.integrator.spi.Integrator;
|
import org.hibernate.integrator.spi.Integrator;
|
||||||
import org.hibernate.integrator.spi.IntegratorService;
|
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.Service;
|
||||||
import org.hibernate.service.ServiceRegistry;
|
import org.hibernate.service.ServiceRegistry;
|
||||||
import org.hibernate.service.classloading.internal.ClassLoaderServiceImpl;
|
import org.hibernate.service.classloading.internal.ClassLoaderServiceImpl;
|
||||||
|
@ -46,16 +46,13 @@ import org.hibernate.service.spi.ServiceRegistryImplementor;
|
||||||
*
|
*
|
||||||
* @author Steve Ebersole
|
* @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 static final LinkedHashSet<Integrator> NO_INTEGRATORS = new LinkedHashSet<Integrator>();
|
||||||
|
|
||||||
private final ServiceBinding<ClassLoaderService> classLoaderServiceBinding;
|
private final ServiceBinding<ClassLoaderService> classLoaderServiceBinding;
|
||||||
private final ServiceBinding<IntegratorService> integratorServiceBinding;
|
private final ServiceBinding<IntegratorService> integratorServiceBinding;
|
||||||
|
|
||||||
public static BootstrapServiceRegistryBuilder builder() {
|
|
||||||
return new BootstrapServiceRegistryBuilder();
|
|
||||||
}
|
|
||||||
|
|
||||||
public BootstrapServiceRegistryImpl() {
|
public BootstrapServiceRegistryImpl() {
|
||||||
this( new ClassLoaderServiceImpl(), NO_INTEGRATORS );
|
this( new ClassLoaderServiceImpl(), NO_INTEGRATORS );
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,6 +26,7 @@ package org.hibernate.service.internal;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.hibernate.service.BootstrapServiceRegistry;
|
||||||
import org.hibernate.service.ServiceRegistry;
|
import org.hibernate.service.ServiceRegistry;
|
||||||
import org.hibernate.service.Service;
|
import org.hibernate.service.Service;
|
||||||
import org.hibernate.service.spi.BasicServiceInitiator;
|
import org.hibernate.service.spi.BasicServiceInitiator;
|
||||||
|
@ -44,7 +45,7 @@ public class StandardServiceRegistryImpl extends AbstractServiceRegistryImpl imp
|
||||||
|
|
||||||
@SuppressWarnings( {"unchecked"})
|
@SuppressWarnings( {"unchecked"})
|
||||||
public StandardServiceRegistryImpl(
|
public StandardServiceRegistryImpl(
|
||||||
ServiceRegistryImplementor bootstrapServiceRegistry,
|
BootstrapServiceRegistry bootstrapServiceRegistry,
|
||||||
List<BasicServiceInitiator> serviceInitiators,
|
List<BasicServiceInitiator> serviceInitiators,
|
||||||
List<ProvidedService> providedServices,
|
List<ProvidedService> providedServices,
|
||||||
Map<?, ?> configurationValues) {
|
Map<?, ?> configurationValues) {
|
||||||
|
|
|
@ -884,7 +884,7 @@ public class Ejb3Configuration implements Serializable, Referenceable {
|
||||||
}
|
}
|
||||||
|
|
||||||
public EntityManagerFactory buildEntityManagerFactory() {
|
public EntityManagerFactory buildEntityManagerFactory() {
|
||||||
return buildEntityManagerFactory( BootstrapServiceRegistryImpl.builder() );
|
return buildEntityManagerFactory( new BootstrapServiceRegistryBuilder() );
|
||||||
}
|
}
|
||||||
|
|
||||||
public EntityManagerFactory buildEntityManagerFactory(BootstrapServiceRegistryBuilder builder) {
|
public EntityManagerFactory buildEntityManagerFactory(BootstrapServiceRegistryBuilder builder) {
|
||||||
|
|
|
@ -46,7 +46,6 @@ import org.hibernate.internal.SessionFactoryImpl;
|
||||||
import org.hibernate.service.BootstrapServiceRegistryBuilder;
|
import org.hibernate.service.BootstrapServiceRegistryBuilder;
|
||||||
import org.hibernate.service.ServiceRegistryBuilder;
|
import org.hibernate.service.ServiceRegistryBuilder;
|
||||||
import org.hibernate.service.internal.StandardServiceRegistryImpl;
|
import org.hibernate.service.internal.StandardServiceRegistryImpl;
|
||||||
import org.hibernate.service.internal.BootstrapServiceRegistryImpl;
|
|
||||||
|
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
|
@ -101,7 +100,7 @@ public abstract class BaseEntityManagerFunctionalTestCase extends BaseUnitTestCa
|
||||||
}
|
}
|
||||||
|
|
||||||
private BootstrapServiceRegistryBuilder bootstrapRegistryBuilder() {
|
private BootstrapServiceRegistryBuilder bootstrapRegistryBuilder() {
|
||||||
return BootstrapServiceRegistryImpl.builder();
|
return new BootstrapServiceRegistryBuilder();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Ejb3Configuration buildConfiguration() {
|
protected Ejb3Configuration buildConfiguration() {
|
||||||
|
|
|
@ -36,7 +36,6 @@ import org.hibernate.envers.event.EnversIntegrator;
|
||||||
import org.hibernate.internal.SessionFactoryImpl;
|
import org.hibernate.internal.SessionFactoryImpl;
|
||||||
import org.hibernate.service.BootstrapServiceRegistryBuilder;
|
import org.hibernate.service.BootstrapServiceRegistryBuilder;
|
||||||
import org.hibernate.service.internal.StandardServiceRegistryImpl;
|
import org.hibernate.service.internal.StandardServiceRegistryImpl;
|
||||||
import org.hibernate.service.internal.BootstrapServiceRegistryImpl;
|
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
|
|
||||||
|
@ -115,7 +114,7 @@ public abstract class AbstractEntityTest extends AbstractEnversTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
private BootstrapServiceRegistryBuilder createBootstrapRegistryBuilder() {
|
private BootstrapServiceRegistryBuilder createBootstrapRegistryBuilder() {
|
||||||
return BootstrapServiceRegistryImpl.builder();
|
return new BootstrapServiceRegistryBuilder();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -53,6 +53,7 @@ import org.hibernate.mapping.Property;
|
||||||
import org.hibernate.mapping.SimpleValue;
|
import org.hibernate.mapping.SimpleValue;
|
||||||
import org.hibernate.metamodel.MetadataSources;
|
import org.hibernate.metamodel.MetadataSources;
|
||||||
import org.hibernate.metamodel.source.MetadataImplementor;
|
import org.hibernate.metamodel.source.MetadataImplementor;
|
||||||
|
import org.hibernate.service.BootstrapServiceRegistry;
|
||||||
import org.hibernate.service.BootstrapServiceRegistryBuilder;
|
import org.hibernate.service.BootstrapServiceRegistryBuilder;
|
||||||
import org.hibernate.service.ServiceRegistry;
|
import org.hibernate.service.ServiceRegistry;
|
||||||
import org.hibernate.service.ServiceRegistryBuilder;
|
import org.hibernate.service.ServiceRegistryBuilder;
|
||||||
|
@ -325,15 +326,15 @@ public abstract class BaseCoreFunctionalTestCase extends BaseUnitTestCase {
|
||||||
Environment.verifyProperties( properties );
|
Environment.verifyProperties( properties );
|
||||||
ConfigurationHelper.resolvePlaceHolders( properties );
|
ConfigurationHelper.resolvePlaceHolders( properties );
|
||||||
|
|
||||||
final BootstrapServiceRegistryImpl bootstrapServiceRegistry = generateBootstrapRegistry( properties );
|
final BootstrapServiceRegistry bootstrapServiceRegistry = generateBootstrapRegistry( properties );
|
||||||
ServiceRegistryBuilder registryBuilder = new ServiceRegistryBuilder( bootstrapServiceRegistry )
|
ServiceRegistryBuilder registryBuilder = new ServiceRegistryBuilder( bootstrapServiceRegistry )
|
||||||
.applySettings( properties );
|
.applySettings( properties );
|
||||||
prepareBasicRegistryBuilder( registryBuilder );
|
prepareBasicRegistryBuilder( registryBuilder );
|
||||||
return (StandardServiceRegistryImpl) registryBuilder.buildServiceRegistry();
|
return (StandardServiceRegistryImpl) registryBuilder.buildServiceRegistry();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected BootstrapServiceRegistryImpl generateBootstrapRegistry(Properties properties) {
|
protected BootstrapServiceRegistry generateBootstrapRegistry(Properties properties) {
|
||||||
final BootstrapServiceRegistryBuilder builder = BootstrapServiceRegistryImpl.builder();
|
final BootstrapServiceRegistryBuilder builder = new BootstrapServiceRegistryBuilder();
|
||||||
prepareBootstrapRegistryBuilder( builder );
|
prepareBootstrapRegistryBuilder( builder );
|
||||||
return builder.build();
|
return builder.build();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue