HHH-6640 - Add ability for Integrator to prepare ServiceRegistryBuilder and MetadataImplementor as part of lifecycle

This commit is contained in:
Steve Ebersole 2011-09-13 18:43:35 -05:00
parent 6cd04c2fb7
commit 9f214d8018
39 changed files with 827 additions and 515 deletions

View File

@ -160,36 +160,6 @@
</variablelist>
</section>
<section id="services-ConfigurationService">
<title><interfacename>org.hibernate.service.config.spi.ConfigurationService</interfacename></title>
<variablelist>
<varlistentry>
<term>Notes</term>
<listitem>
<para>
Provides access to the initial raw, user-provided configuration values
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>Initiator</term>
<listitem>
<para>
<classname>org.hibernate.service.config.internal.ConfigurationServiceInitiator</classname>
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>Implementations</term>
<listitem>
<para>
<classname>org.hibernate.service.config.internal.ConfigurationServiceImpl</classname>
</para>
</listitem>
</varlistentry>
</variablelist>
</section>
<section id="services-ConnectionProvider">
<title><interfacename>org.hibernate.service.jdbc.connections.spi.ConnectionProvider</interfacename></title>
<variablelist>
@ -902,7 +872,37 @@
</section>
<section>
<title>Special services</title>
<title>Boot-strap services</title>
<section id="services-ConfigurationService">
<title><interfacename>org.hibernate.service.config.spi.ConfigurationService</interfacename></title>
<variablelist>
<varlistentry>
<term>Notes</term>
<listitem>
<para>
Provides access to the initial raw, user-provided configuration values
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>Initiator</term>
<listitem>
<para>
N/A
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>Implementations</term>
<listitem>
<para>
<classname>org.hibernate.service.config.internal.ConfigurationServiceImpl</classname>
</para>
</listitem>
</varlistentry>
</variablelist>
</section>
<section id="services-ClassLoaderService">
</section>

View File

@ -1743,7 +1743,9 @@ public class Configuration implements Serializable {
public SessionFactory buildSessionFactory() throws HibernateException {
Environment.verifyProperties( properties );
ConfigurationHelper.resolvePlaceHolders( properties );
final ServiceRegistry serviceRegistry = new ServiceRegistryBuilder( properties ).buildServiceRegistry();
final ServiceRegistry serviceRegistry = new ServiceRegistryBuilder()
.applySettings( properties )
.buildServiceRegistry();
setSessionFactoryObserver(
new SessionFactoryObserver() {
@Override

View File

@ -28,41 +28,38 @@ import org.jboss.logging.Logger;
import org.hibernate.cfg.beanvalidation.BeanValidationIntegrator;
import org.hibernate.integrator.spi.Integrator;
import org.hibernate.integrator.spi.IntegratorService;
import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.service.spi.ServiceRegistryImplementor;
import org.hibernate.service.classloading.spi.ClassLoaderService;
/**
* @author Steve Ebersole
*/
public class IntegratorServiceImpl implements IntegratorService {
private static final CoreMessageLogger LOG = Logger.getMessageLogger(
CoreMessageLogger.class, IntegratorServiceImpl.class.getName());
private final ServiceRegistryImplementor serviceRegistry;
private LinkedHashSet<Integrator> integrators = new LinkedHashSet<Integrator>();
private static final Logger LOG = Logger.getLogger( IntegratorServiceImpl.class.getName() );
public IntegratorServiceImpl(ServiceRegistryImplementor serviceRegistry) {
this.serviceRegistry = serviceRegistry;
// Standard integrators nameable from here. Envers and JPA, for example, need to be handled by discovery
// because in separate project/jars
private final LinkedHashSet<Integrator> integrators = new LinkedHashSet<Integrator>();
public IntegratorServiceImpl(LinkedHashSet<Integrator> providedIntegrators, ClassLoaderService classLoaderService) {
// register standard integrators. Envers and JPA, for example, need to be handled by discovery because in
// separate project/jars.
addIntegrator( new BeanValidationIntegrator() );
// register provided integrators
for ( Integrator integrator : providedIntegrators ) {
addIntegrator( integrator );
}
@Override
public void addIntegrator(Integrator integrator) {
for ( Integrator integrator : classLoaderService.loadJavaServices( Integrator.class ) ) {
addIntegrator( integrator );
}
}
private void addIntegrator(Integrator integrator) {
LOG.debugf( "Adding Integrator [%s].", integrator.getClass().getName() );
integrators.add( integrator );
}
@Override
public Iterable<Integrator> getIntegrators() {
LinkedHashSet<Integrator> integrators = new LinkedHashSet<Integrator>();
integrators.addAll( this.integrators );
for ( Integrator integrator : ServiceLoader.load( Integrator.class,serviceRegistry ) ) {
LOG.debugf( "Adding Integrator [%s].", integrator.getClass().getName() );
integrators.add( integrator );
}
return integrators;
}
}

View File

@ -1,195 +0,0 @@
/*
* 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.integrator.internal;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.ServiceConfigurationError;
import org.jboss.logging.Logger;
import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.service.classloading.spi.ClassLoaderService;
/**
* @author Strong Liu
*/
final class ServiceLoader<S> implements Iterable<S> {
private static final CoreMessageLogger LOG = Logger.getMessageLogger(
CoreMessageLogger.class, ServiceLoader.class.getName()
);
private static final String PREFIX = "META-INF/services/";
private LinkedHashMap<String, S> providers = new LinkedHashMap<String, S>();
private ServiceLoader(Class<S> svc, ServiceRegistry serviceRegistry) {
Class<S> service = svc;
ClassLoaderService loader = serviceRegistry.getService( ClassLoaderService.class );
String fullName = PREFIX + service.getName();
service.getName();
List<URL> configs = locateResources( loader, fullName );
for ( URL url : configs ) {
Iterator<String> names = parse( service, url );
while ( names.hasNext() ) {
String cn = names.next();
try {
S p = service.cast( loader.classForName( cn ).newInstance() );
providers.put( cn, p );
}
catch ( Throwable x ) {
fail( service, "Provider " + cn + " could not be instantiated: " + x, x );
}
}
}
}
private List<URL> locateResources(ClassLoaderService loader, String fullName) {
List<URL> urls = new ArrayList<URL>();
urls.addAll( loader.locateResources( fullName ) );
try {
Enumeration<URL> hibUrls = ServiceLoader.class.getClassLoader().getResources( fullName );
while ( hibUrls.hasMoreElements() ) {
URL u = hibUrls.nextElement();
if ( !urls.contains( u ) ) {
urls.add( u );
}
}
}
catch ( IOException e ) {
//ignore
}
return urls;
}
private static void fail(Class service, String msg, Throwable cause)
throws ServiceConfigurationError {
throw new ServiceConfigurationError(
service.getName() + ": " + msg,
cause
);
}
private static void fail(Class service, String msg)
throws ServiceConfigurationError {
throw new ServiceConfigurationError( service.getName() + ": " + msg );
}
private static void fail(Class service, URL u, int line, String msg)
throws ServiceConfigurationError {
fail( service, u + ":" + line + ": " + msg );
}
// Parse a single line from the given configuration file, adding the name
// on the line to the names list.
//
private int parseLine(Class service, URL u, BufferedReader r, int lc,
List<String> names)
throws IOException, ServiceConfigurationError {
String ln = r.readLine();
if ( ln == null ) {
return -1;
}
int ci = ln.indexOf( '#' );
if ( ci >= 0 ) {
ln = ln.substring( 0, ci );
}
ln = ln.trim();
int n = ln.length();
if ( n != 0 ) {
if ( ( ln.indexOf( ' ' ) >= 0 ) || ( ln.indexOf( '\t' ) >= 0 ) ) {
fail( service, u, lc, "Illegal configuration-file syntax" );
}
int cp = ln.codePointAt( 0 );
if ( !Character.isJavaIdentifierStart( cp ) ) {
fail( service, u, lc, "Illegal provider-class name: " + ln );
}
for ( int i = Character.charCount( cp ); i < n; i += Character.charCount( cp ) ) {
cp = ln.codePointAt( i );
if ( !Character.isJavaIdentifierPart( cp ) && ( cp != '.' ) ) {
fail( service, u, lc, "Illegal provider-class name: " + ln );
}
}
if ( !providers.containsKey( ln ) && !names.contains( ln ) ) {
names.add( ln );
}
}
return lc + 1;
}
private Iterator<String> parse(Class service, URL u)
throws ServiceConfigurationError {
InputStream in = null;
BufferedReader r = null;
ArrayList<String> names = new ArrayList<String>();
try {
in = u.openStream();
r = new BufferedReader( new InputStreamReader( in, "utf-8" ) );
int lc = 1;
while ( ( lc = parseLine( service, u, r, lc, names ) ) >= 0 ) {
;
}
}
catch ( IOException x ) {
fail( service, "Error reading configuration file", x );
}
finally {
try {
if ( r != null ) {
r.close();
}
if ( in != null ) {
in.close();
}
}
catch ( IOException y ) {
fail( service, "Error closing configuration file", y );
}
}
return names.iterator();
}
public Iterator<S> iterator() {
return providers.values().iterator();
}
public static <S> ServiceLoader<S> load(Class<S> service,
ServiceRegistry serviceRegistry) {
return new ServiceLoader<S>( service, serviceRegistry );
}
}

View File

@ -26,6 +26,7 @@ package org.hibernate.integrator.spi;
import org.hibernate.cfg.Configuration;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.metamodel.source.MetadataImplementor;
import org.hibernate.service.ServiceRegistryBuilder;
import org.hibernate.service.spi.SessionFactoryServiceRegistry;
/**
@ -44,6 +45,7 @@ import org.hibernate.service.spi.SessionFactoryServiceRegistry;
* @jira HHH-6081
*/
public interface Integrator {
/**
* Perform integration.
*
@ -74,4 +76,5 @@ public interface Integrator {
* @param serviceRegistry That session factory's service registry
*/
public void disintegrate(SessionFactoryImplementor sessionFactory, SessionFactoryServiceRegistry serviceRegistry);
}

View File

@ -29,15 +29,6 @@ import org.hibernate.service.Service;
* @author Steve Ebersole
*/
public interface IntegratorService extends Service {
/**
* Manually add an integrator. Added integrators supplement the set of discovered ones.
* <p/>
* This is mostly an internal contract used between modules.
*
* @param integrator The integrator
*/
public void addIntegrator(Integrator integrator);
/**
* Retrieve all integrators.
*

View File

@ -21,27 +21,22 @@
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.integrator.internal;
package org.hibernate.integrator.spi;
import java.util.Map;
import org.hibernate.integrator.spi.IntegratorService;
import org.hibernate.service.spi.BasicServiceInitiator;
import org.hibernate.service.spi.ServiceRegistryImplementor;
import org.hibernate.service.ServiceRegistryBuilder;
/**
* Additional, optional contract for Integrators that wish to contribute {@link org.hibernate.service.Service services}
* to the Hibernate {@link org.hibernate.service.ServiceRegistry}.
*
* @author Steve Ebersole
*/
public class IntegratorServiceInitiator implements BasicServiceInitiator<IntegratorService> {
public static final IntegratorServiceInitiator INSTANCE = new IntegratorServiceInitiator();
@Override
public Class<IntegratorService> getServiceInitiated() {
return IntegratorService.class;
}
@Override
public IntegratorService initiateService(Map configurationValues, ServiceRegistryImplementor registry) {
return new IntegratorServiceImpl( registry );
}
public interface ServiceContributingIntegrator extends Integrator {
/**
* Allow the integrator to alter the builder of {@link org.hibernate.service.ServiceRegistry}, presumably to
* register services into it.
*
* @param serviceRegistryBuilder The build to prepare.
*/
public void prepareServices(ServiceRegistryBuilder serviceRegistryBuilder);
}

View File

@ -66,7 +66,7 @@ public class HibernateService extends ExternalSessionFactoryConfig implements Hi
LOG.startingServiceAtJndiName( boundName );
LOG.serviceProperties( properties );
return buildConfiguration().buildSessionFactory(
new ServiceRegistryBuilder( properties ).buildServiceRegistry()
new ServiceRegistryBuilder().applySettings( properties ).buildServiceRegistry()
);
}

View File

@ -23,14 +23,30 @@
*/
package org.hibernate.service;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import org.jboss.logging.Logger;
import org.hibernate.cfg.Environment;
import org.hibernate.integrator.spi.Integrator;
import org.hibernate.integrator.spi.IntegratorService;
import org.hibernate.integrator.spi.ServiceContributingIntegrator;
import org.hibernate.internal.util.Value;
import org.hibernate.internal.util.config.ConfigurationException;
import org.hibernate.internal.util.config.ConfigurationHelper;
import org.hibernate.metamodel.source.Origin;
import org.hibernate.metamodel.source.SourceType;
import org.hibernate.metamodel.source.hbm.jaxb.config.XMLHibernateConfiguration;
import org.hibernate.service.classloading.spi.ClassLoaderService;
import org.hibernate.service.internal.BasicServiceRegistryImpl;
import org.hibernate.service.internal.BootstrapServiceRegistryImpl;
import org.hibernate.service.internal.JaxbProcessor;
import org.hibernate.service.internal.ProvidedService;
import org.hibernate.service.spi.BasicServiceInitiator;
@ -40,28 +56,38 @@ import org.hibernate.service.spi.BasicServiceInitiator;
* @author Steve Ebersole
*/
public class ServiceRegistryBuilder {
private static final Logger log = Logger.getLogger( ServiceRegistryBuilder.class );
public static final String DEFAULT_CFG_RESOURCE_NAME = "hibernate.cfg.xml";
private final Map settings;
private final List<BasicServiceInitiator> initiators = standardInitiatorList();
private final List<ProvidedService> providedServices = new ArrayList<ProvidedService>();
private final BootstrapServiceRegistryImpl bootstrapServiceRegistry;
/**
* Create a default builder
*/
public ServiceRegistryBuilder() {
this( Environment.getProperties() );
this( new BootstrapServiceRegistryImpl() );
}
/**
* Create a builder with the specified settings
* Create a builder with the specified bootstrap services.
*
* @param settings The initial set of settings to use.
* @param bootstrapServiceRegistry Provided bootstrap registry to use.
*/
public ServiceRegistryBuilder(Map settings) {
this.settings = settings;
public ServiceRegistryBuilder(BootstrapServiceRegistryImpl bootstrapServiceRegistry) {
this.settings = Environment.getProperties();
this.bootstrapServiceRegistry = bootstrapServiceRegistry;
}
/**
* Used from the {@link #initiators} variable initializer
*
* @return List of standard initiators
*/
private static List<BasicServiceInitiator> standardInitiatorList() {
final List<BasicServiceInitiator> initiators = new ArrayList<BasicServiceInitiator>();
initiators.addAll( StandardServiceInitiators.LIST );
@ -69,30 +95,87 @@ public class ServiceRegistryBuilder {
}
/**
* Read setting information from the standard resource location
* Read settings from a {@link Properties} file. Differs from {@link #configure()} and {@link #configure(String)}
* in that here we read a {@link Properties} file while for {@link #configure} we read the XML variant.
*
* @param resourceName The name by which to perform a resource look up for the properties file.
*
* @return this, for method chaining
*
* @see #configure()
* @see #configure(String)
*/
@SuppressWarnings( {"unchecked"})
public ServiceRegistryBuilder loadProperties(String resourceName) {
InputStream stream = bootstrapServiceRegistry.getService( ClassLoaderService.class ).locateResourceStream( resourceName );
try {
Properties properties = new Properties();
properties.load( stream );
settings.putAll( properties );
}
catch (IOException e) {
throw new ConfigurationException( "Unable to apply settings from properties file [" + resourceName + "]", e );
}
finally {
try {
stream.close();
}
catch (IOException e) {
log.debug(
String.format( "Unable to close properties file [%s] stream", resourceName ),
e
);
}
}
return this;
}
/**
* Read setting information from an XML file using the standard resource location
*
* @return this, for method chaining
*
* @see #DEFAULT_CFG_RESOURCE_NAME
* @see #configure(String)
* @see #loadProperties(String)
*/
public ServiceRegistryBuilder configure() {
return configure( DEFAULT_CFG_RESOURCE_NAME );
}
/**
* Read setting information from the named resource location
* Read setting information from an XML file using the named resource location
*
* @param resourceName The named resource
*
* @return this, for method chaining
*
* @see #loadProperties(String)
*/
@SuppressWarnings( {"unchecked"})
public ServiceRegistryBuilder configure(String resourceName) {
// todo : parse and apply XML
// we run into a chicken-egg problem here, in that we need the service registry in order to know how to do this
// resource lookup (ClassLoaderService)
InputStream stream = bootstrapServiceRegistry.getService( ClassLoaderService.class ).locateResourceStream( resourceName );
XMLHibernateConfiguration configurationElement = jaxbProcessorHolder.getValue().unmarshal(
stream,
new Origin( SourceType.RESOURCE, resourceName )
);
for ( XMLHibernateConfiguration.XMLSessionFactory.XMLProperty xmlProperty : configurationElement.getSessionFactory().getProperty() ) {
settings.put( xmlProperty.getName(), xmlProperty.getValue() );
}
return this;
}
private Value<JaxbProcessor> jaxbProcessorHolder = new Value<JaxbProcessor>(
new Value.DeferredInitializer<JaxbProcessor>() {
@Override
public JaxbProcessor initialize() {
return new JaxbProcessor( bootstrapServiceRegistry.getService( ClassLoaderService.class ) );
}
}
);
/**
* Apply a setting value
*
@ -157,7 +240,14 @@ public class ServiceRegistryBuilder {
settingsCopy.putAll( settings );
Environment.verifyProperties( settingsCopy );
ConfigurationHelper.resolvePlaceHolders( settingsCopy );
return new BasicServiceRegistryImpl( initiators, providedServices, settingsCopy );
for ( Integrator integrator : bootstrapServiceRegistry.getService( IntegratorService.class ).getIntegrators() ) {
if ( ServiceContributingIntegrator.class.isInstance( integrator ) ) {
ServiceContributingIntegrator.class.cast( integrator ).prepareServices( this );
}
}
return new BasicServiceRegistryImpl( bootstrapServiceRegistry, initiators, providedServices, settingsCopy );
}
/**

View File

@ -31,10 +31,8 @@ import org.hibernate.engine.jdbc.batch.internal.BatchBuilderInitiator;
import org.hibernate.engine.jdbc.internal.JdbcServicesInitiator;
import org.hibernate.engine.transaction.internal.TransactionFactoryInitiator;
import org.hibernate.id.factory.internal.MutableIdentifierGeneratorFactoryInitiator;
import org.hibernate.integrator.internal.IntegratorServiceInitiator;
import org.hibernate.persister.internal.PersisterClassResolverInitiator;
import org.hibernate.persister.internal.PersisterFactoryInitiator;
import org.hibernate.service.classloading.internal.ClassLoaderServiceInitiator;
import org.hibernate.service.config.internal.ConfigurationServiceInitiator;
import org.hibernate.service.internal.SessionFactoryServiceRegistryFactoryInitiator;
import org.hibernate.service.jdbc.connections.internal.ConnectionProviderInitiator;
@ -57,7 +55,6 @@ public class StandardServiceInitiators {
serviceInitiators.add( ConfigurationServiceInitiator.INSTANCE );
serviceInitiators.add( ClassLoaderServiceInitiator.INSTANCE );
serviceInitiators.add( JndiServiceInitiator.INSTANCE );
serviceInitiators.add( JmxServiceInitiator.INSTANCE );
@ -77,7 +74,6 @@ public class StandardServiceInitiators {
serviceInitiators.add( TransactionFactoryInitiator.INSTANCE );
serviceInitiators.add( SessionFactoryServiceRegistryFactoryInitiator.INSTANCE );
serviceInitiators.add( IntegratorServiceInitiator.INSTANCE );
serviceInitiators.add( RegionFactoryInitiator.INSTANCE );

View File

@ -23,13 +23,17 @@
*/
package org.hibernate.service.classloading.internal;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.ServiceLoader;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.service.classloading.spi.ClassLoaderService;
@ -41,23 +45,23 @@ import org.hibernate.service.classloading.spi.ClassLoadingException;
* @author Steve Ebersole
*/
public class ClassLoaderServiceImpl implements ClassLoaderService {
private final LinkedHashSet<ClassLoader> classLoadingClassLoaders;
private final ClassLoader classClassLoader;
private final ClassLoader resourcesClassLoader;
public ClassLoaderServiceImpl(Map configVales) {
this( determineClassLoaders( configVales ) );
public ClassLoaderServiceImpl() {
this( ClassLoaderServiceImpl.class.getClassLoader() );
}
private ClassLoaderServiceImpl(ClassLoader... classLoaders) {
this( classLoaders[0], classLoaders[1], classLoaders[2], classLoaders[3] );
public ClassLoaderServiceImpl(ClassLoader classLoader) {
this( classLoader, classLoader, classLoader, classLoader );
}
private static ClassLoader[] determineClassLoaders(Map configVales) {
ClassLoader applicationClassLoader = (ClassLoader) configVales.get( AvailableSettings.APP_CLASSLOADER );
ClassLoader resourcesClassLoader = (ClassLoader) configVales.get( AvailableSettings.RESOURCES_CLASSLOADER );
ClassLoader hibernateClassLoader = (ClassLoader) configVales.get( AvailableSettings.HIBERNATE_CLASSLOADER );
ClassLoader environmentClassLoader = (ClassLoader) configVales.get( AvailableSettings.ENVIRONMENT_CLASSLOADER );
public ClassLoaderServiceImpl(
ClassLoader applicationClassLoader,
ClassLoader resourcesClassLoader,
ClassLoader hibernateClassLoader,
ClassLoader environmentClassLoader) {
// Normalize missing loaders
if ( hibernateClassLoader == null ) {
hibernateClassLoader = ClassLoaderServiceImpl.class.getClassLoader();
}
@ -77,12 +81,36 @@ public class ClassLoaderServiceImpl implements ClassLoaderService {
resourcesClassLoader = applicationClassLoader;
}
return new ClassLoader[] {
applicationClassLoader,
resourcesClassLoader,
hibernateClassLoader,
environmentClassLoader
final LinkedHashSet<ClassLoader> classLoadingClassLoaders = new LinkedHashSet<ClassLoader>();
classLoadingClassLoaders.add( applicationClassLoader );
classLoadingClassLoaders.add( hibernateClassLoader );
classLoadingClassLoaders.add( environmentClassLoader );
this.classClassLoader = new ClassLoader() {
@Override
protected Class<?> findClass(String name) throws ClassNotFoundException {
for ( ClassLoader loader : classLoadingClassLoaders ) {
try {
return loader.loadClass( name );
}
catch (Exception ignore) {
}
}
throw new ClassNotFoundException( "Could not load requested class : " + name );
}
};
this.resourcesClassLoader = resourcesClassLoader;
}
@SuppressWarnings( {"UnusedDeclaration"})
public static ClassLoaderServiceImpl fromConfigSettings(Map configVales) {
return new ClassLoaderServiceImpl(
(ClassLoader) configVales.get( AvailableSettings.APP_CLASSLOADER ),
(ClassLoader) configVales.get( AvailableSettings.RESOURCES_CLASSLOADER ),
(ClassLoader) configVales.get( AvailableSettings.HIBERNATE_CLASSLOADER ),
(ClassLoader) configVales.get( AvailableSettings.ENVIRONMENT_CLASSLOADER )
);
}
private static ClassLoader locateSystemClassLoader() {
@ -103,35 +131,16 @@ public class ClassLoaderServiceImpl implements ClassLoaderService {
}
}
public ClassLoaderServiceImpl(ClassLoader classLoader) {
this( classLoader, classLoader, classLoader, classLoader );
}
public ClassLoaderServiceImpl(
ClassLoader applicationClassLoader,
ClassLoader resourcesClassLoader,
ClassLoader hibernateClassLoader,
ClassLoader environmentClassLoader) {
this.classLoadingClassLoaders = new LinkedHashSet<ClassLoader>();
classLoadingClassLoaders.add( applicationClassLoader );
classLoadingClassLoaders.add( hibernateClassLoader );
classLoadingClassLoaders.add( environmentClassLoader );
this.resourcesClassLoader = resourcesClassLoader;
}
@Override
@SuppressWarnings( {"unchecked"})
public <T> Class<T> classForName(String className) {
for ( ClassLoader classLoader : classLoadingClassLoaders ) {
try {
return (Class<T>) classLoader.loadClass( className );
return (Class<T>) classClassLoader.loadClass( className );
}
catch ( Exception ignore) {
catch (Exception e) {
throw new ClassLoadingException( "Unable to load class [" + className + "]", e );
}
}
throw new ClassLoadingException( "Unable to load class [" + className + "]" );
}
@Override
public URL locateResource(String name) {
@ -186,4 +195,63 @@ public class ClassLoaderServiceImpl implements ClassLoaderService {
return urls;
}
@Override
public <S> LinkedHashSet<S> loadJavaServices(Class<S> serviceContract) {
final ClassLoader serviceLoaderClassLoader = new ClassLoader() {
final ClassLoader[] classLoaderArray = new ClassLoader[] {
// first look on the hibernate class loader
getClass().getClassLoader(),
// next look on the resource class loader
resourcesClassLoader,
// finally look on the combined class class loader
classClassLoader
};
@Override
public Enumeration<URL> getResources(String name) throws IOException {
final HashSet<URL> resourceUrls = new HashSet<URL>();
for ( ClassLoader classLoader : classLoaderArray ) {
final Enumeration<URL> urls = classLoader.getResources( name );
while ( urls.hasMoreElements() ) {
resourceUrls.add( urls.nextElement() );
}
}
return new Enumeration<URL>() {
final Iterator<URL> resourceUrlIterator = resourceUrls.iterator();
@Override
public boolean hasMoreElements() {
return resourceUrlIterator.hasNext();
}
@Override
public URL nextElement() {
return resourceUrlIterator.next();
}
};
}
@Override
protected Class<?> findClass(String name) throws ClassNotFoundException {
for ( ClassLoader classLoader : classLoaderArray ) {
try {
classLoader.loadClass( name );
}
catch (Exception ignore) {
}
}
throw new ClassNotFoundException( "Could not load requested class : " + name );
}
};
final ServiceLoader<S> loader = ServiceLoader.load( serviceContract, serviceLoaderClassLoader );
final LinkedHashSet<S> services = new LinkedHashSet<S>();
for ( S service : loader ) {
services.add( service );
}
return services;
}
}

View File

@ -1,49 +0,0 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2010, 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.classloading.internal;
import java.util.Map;
import org.hibernate.service.classloading.spi.ClassLoaderService;
import org.hibernate.service.spi.ServiceRegistryImplementor;
import org.hibernate.service.spi.BasicServiceInitiator;
/**
* Standard initiator for the standard {@link ClassLoaderService} service.
*
* @author Steve Ebersole
*/
public class ClassLoaderServiceInitiator implements BasicServiceInitiator<ClassLoaderService> {
public static final ClassLoaderServiceInitiator INSTANCE = new ClassLoaderServiceInitiator();
@Override
public Class<ClassLoaderService> getServiceInitiated() {
return ClassLoaderService.class;
}
@Override
public ClassLoaderService initiateService(Map configurationValues, ServiceRegistryImplementor registry) {
return new ClassLoaderServiceImpl( configurationValues );
}
}

View File

@ -25,6 +25,7 @@ package org.hibernate.service.classloading.spi;
import java.io.InputStream;
import java.net.URL;
import java.util.LinkedHashSet;
import java.util.List;
import org.hibernate.service.Service;
@ -35,7 +36,6 @@ import org.hibernate.service.Service;
* @author Steve Ebersole
*/
public interface ClassLoaderService extends Service {
/**
* Locate a class by name
*
@ -73,4 +73,17 @@ public interface ClassLoaderService extends Service {
* @return The list of URL matching; may return {@code null} to indicate the resource was not found
*/
public List<URL> locateResources(String name);
/**
* Discovers and instantiates implementations of the named service contract.
* <p/>
* NOTE : the terms service here is used differently than {@link Service}. Instead here we are talking about
* services as defined by {@link java.util.ServiceLoader}.
*
* @param serviceContract The java type defining the service contract
* @param <S> The type of the service contract
*
* @return The ordered set of discovered services.
*/
public <S> LinkedHashSet<S> loadJavaServices(Class<S> serviceContract);
}

View File

@ -32,6 +32,7 @@ import org.hibernate.service.spi.BasicServiceInitiator;
import org.hibernate.service.spi.Configurable;
import org.hibernate.service.spi.ServiceInitiator;
import org.hibernate.service.spi.ServiceRegistryAwareService;
import org.hibernate.service.spi.ServiceRegistryImplementor;
/**
* Standard Hibernate implementation of the service registry.
@ -39,15 +40,15 @@ import org.hibernate.service.spi.ServiceRegistryAwareService;
* @author Steve Ebersole
*/
public class BasicServiceRegistryImpl extends AbstractServiceRegistryImpl implements BasicServiceRegistry {
private final Map configurationValues;
@SuppressWarnings( {"unchecked"})
public BasicServiceRegistryImpl(
final List<BasicServiceInitiator> serviceInitiators,
final List<ProvidedService> providedServices,
final Map configurationValues) {
super();
ServiceRegistryImplementor bootstrapServiceRegistry,
List<BasicServiceInitiator> serviceInitiators,
List<ProvidedService> providedServices,
Map<?, ?> configurationValues) {
super( bootstrapServiceRegistry );
this.configurationValues = configurationValues;

View File

@ -0,0 +1,169 @@
/*
* 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.internal;
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.Service;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.service.classloading.internal.ClassLoaderServiceImpl;
import org.hibernate.service.classloading.spi.ClassLoaderService;
import org.hibernate.service.spi.ServiceBinding;
import org.hibernate.service.spi.ServiceException;
import org.hibernate.service.spi.ServiceInitiator;
import org.hibernate.service.spi.ServiceRegistryImplementor;
/**
* {@link ServiceRegistry} implementation containing specialized "bootstrap" services, specifically:<ul>
* <li>{@link ClassLoaderService}</li>
* <li>{@link IntegratorService}</li>
* </ul>
*
* @author Steve Ebersole
*/
public class BootstrapServiceRegistryImpl implements ServiceRegistryImplementor, ServiceBinding.OwningRegistry {
private static final LinkedHashSet<Integrator> NO_INTEGRATORS = new LinkedHashSet<Integrator>();
private final ServiceBinding<ClassLoaderService> classLoaderServiceBinding;
private final ServiceBinding<IntegratorService> integratorServiceBinding;
public static Builder builder() {
return new Builder();
}
public BootstrapServiceRegistryImpl() {
this( new ClassLoaderServiceImpl(), NO_INTEGRATORS );
}
public BootstrapServiceRegistryImpl(
ClassLoaderService classLoaderService,
IntegratorService integratorService) {
this.classLoaderServiceBinding = new ServiceBinding<ClassLoaderService>(
this,
ClassLoaderService.class,
classLoaderService
);
this.integratorServiceBinding = new ServiceBinding<IntegratorService>(
this,
IntegratorService.class,
integratorService
);
}
public BootstrapServiceRegistryImpl(
ClassLoaderService classLoaderService,
LinkedHashSet<Integrator> providedIntegrators) {
this( classLoaderService, new IntegratorServiceImpl( providedIntegrators, classLoaderService ) );
}
@Override
public <R extends Service> R getService(Class<R> serviceRole) {
final ServiceBinding<R> binding = locateServiceBinding( serviceRole );
return binding == null ? null : binding.getService();
}
@Override
@SuppressWarnings( {"unchecked"})
public <R extends Service> ServiceBinding<R> locateServiceBinding(Class<R> serviceRole) {
if ( ClassLoaderService.class.equals( serviceRole ) ) {
return (ServiceBinding<R>) classLoaderServiceBinding;
}
else if ( IntegratorService.class.equals( serviceRole ) ) {
return (ServiceBinding<R>) integratorServiceBinding;
}
return null;
}
@Override
public void destroy() {
}
@Override
public ServiceRegistry getParentServiceRegistry() {
return null;
}
@Override
public <R extends Service> R initiateService(ServiceInitiator<R> serviceInitiator) {
// the bootstrap registry should currently be made up of only directly built services.
throw new ServiceException( "Boot-strap registry should only contain directly built services" );
}
public static class Builder {
private final LinkedHashSet<Integrator> providedIntegrators = new LinkedHashSet<Integrator>();
private ClassLoader applicationClassLoader;
private ClassLoader resourcesClassLoader;
private ClassLoader hibernateClassLoader;
private ClassLoader environmentClassLoader;
public Builder with(Integrator integrator) {
providedIntegrators.add( integrator );
return this;
}
public Builder withApplicationClassLoader(ClassLoader classLoader) {
this.applicationClassLoader = classLoader;
return this;
}
public Builder withResourceClassLoader(ClassLoader classLoader) {
this.resourcesClassLoader = classLoader;
return this;
}
public Builder withHibernateClassLoader(ClassLoader classLoader) {
this.hibernateClassLoader = classLoader;
return this;
}
public Builder withEnvironmentClassLoader(ClassLoader classLoader) {
this.environmentClassLoader = classLoader;
return this;
}
public BootstrapServiceRegistryImpl build() {
final ClassLoaderServiceImpl classLoaderService = new ClassLoaderServiceImpl(
applicationClassLoader,
resourcesClassLoader,
hibernateClassLoader,
environmentClassLoader
);
final IntegratorServiceImpl integratorService = new IntegratorServiceImpl(
providedIntegrators,
classLoaderService
);
return new BootstrapServiceRegistryImpl( classLoaderService, integratorService );
}
}
}

View File

@ -0,0 +1,195 @@
/*
* 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.internal;
import javax.xml.XMLConstants;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;
import javax.xml.bind.ValidationEvent;
import javax.xml.bind.ValidationEventHandler;
import javax.xml.bind.ValidationEventLocator;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
import javax.xml.transform.stream.StreamSource;
import javax.xml.validation.Schema;
import javax.xml.validation.SchemaFactory;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import org.jboss.logging.Logger;
import org.xml.sax.SAXException;
import org.hibernate.internal.util.config.ConfigurationException;
import org.hibernate.metamodel.source.MappingException;
import org.hibernate.metamodel.source.Origin;
import org.hibernate.metamodel.source.XsdException;
import org.hibernate.metamodel.source.hbm.jaxb.config.XMLHibernateConfiguration;
import org.hibernate.service.classloading.spi.ClassLoaderService;
/**
* @author Steve Ebersole
*/
public class JaxbProcessor {
private static final Logger log = Logger.getLogger( JaxbProcessor.class );
private final ClassLoaderService classLoaderService;
public JaxbProcessor(ClassLoaderService classLoaderService) {
this.classLoaderService = classLoaderService;
}
public XMLHibernateConfiguration unmarshal(InputStream stream, Origin origin) {
try {
XMLStreamReader staxReader = staxFactory().createXMLStreamReader( stream );
try {
return unmarshal( staxReader, origin );
}
finally {
try {
staxReader.close();
}
catch ( Exception ignore ) {
}
}
}
catch ( XMLStreamException e ) {
throw new MappingException( "Unable to create stax reader", e, origin );
}
}
private XMLInputFactory staxFactory;
private XMLInputFactory staxFactory() {
if ( staxFactory == null ) {
staxFactory = buildStaxFactory();
}
return staxFactory;
}
@SuppressWarnings( { "UnnecessaryLocalVariable" })
private XMLInputFactory buildStaxFactory() {
XMLInputFactory staxFactory = XMLInputFactory.newInstance();
return staxFactory;
}
@SuppressWarnings( { "unchecked" })
private XMLHibernateConfiguration unmarshal(XMLStreamReader staxReader, final Origin origin) {
final Object target;
final ContextProvidingValidationEventHandler handler = new ContextProvidingValidationEventHandler();
try {
JAXBContext jaxbContext = JAXBContext.newInstance( XMLHibernateConfiguration.class );
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
unmarshaller.setSchema( schema() );
unmarshaller.setEventHandler( handler );
target = unmarshaller.unmarshal( staxReader );
return (XMLHibernateConfiguration) target;
}
catch ( JAXBException e ) {
StringBuilder builder = new StringBuilder();
builder.append( "Unable to perform unmarshalling at line number " )
.append( handler.getLineNumber() )
.append( " and column " )
.append( handler.getColumnNumber() )
.append( " in " ).append( origin.getType().name() ).append( " " ).append( origin.getName() )
.append( ". Message: " )
.append( handler.getMessage() );
throw new ConfigurationException( builder.toString(), e );
}
}
private Schema schema;
private Schema schema() {
if ( schema == null ) {
schema = resolveLocalSchema( "/org/hibernate/hibernate-configuration-4.0.xsd" );
}
return schema;
}
private Schema resolveLocalSchema(String schemaName) {
return resolveLocalSchema( schemaName, XMLConstants.W3C_XML_SCHEMA_NS_URI );
}
private Schema resolveLocalSchema(String schemaName, String schemaLanguage) {
URL url = classLoaderService.locateResource( schemaName );
if ( url == null ) {
throw new XsdException( "Unable to locate schema [" + schemaName + "] via classpath", schemaName );
}
try {
InputStream schemaStream = url.openStream();
try {
StreamSource source = new StreamSource( url.openStream() );
SchemaFactory schemaFactory = SchemaFactory.newInstance( schemaLanguage );
return schemaFactory.newSchema( source );
}
catch ( SAXException e ) {
throw new XsdException( "Unable to load schema [" + schemaName + "]", e, schemaName );
}
catch ( IOException e ) {
throw new XsdException( "Unable to load schema [" + schemaName + "]", e, schemaName );
}
finally {
try {
schemaStream.close();
}
catch ( IOException e ) {
log.debugf( "Problem closing schema stream [%s]", e.toString() );
}
}
}
catch ( IOException e ) {
throw new XsdException( "Stream error handling schema url [" + url.toExternalForm() + "]", schemaName );
}
}
static class ContextProvidingValidationEventHandler implements ValidationEventHandler {
private int lineNumber;
private int columnNumber;
private String message;
@Override
public boolean handleEvent(ValidationEvent validationEvent) {
ValidationEventLocator locator = validationEvent.getLocator();
lineNumber = locator.getLineNumber();
columnNumber = locator.getColumnNumber();
message = validationEvent.getMessage();
return false;
}
public int getLineNumber() {
return lineNumber;
}
public int getColumnNumber() {
return columnNumber;
}
public String getMessage() {
return message;
}
}
}

View File

@ -493,7 +493,7 @@ public class SchemaExport {
private static BasicServiceRegistryImpl createServiceRegistry(Properties properties) {
Environment.verifyProperties( properties );
ConfigurationHelper.resolvePlaceHolders( properties );
return (BasicServiceRegistryImpl) new ServiceRegistryBuilder( properties ).buildServiceRegistry();
return (BasicServiceRegistryImpl) new ServiceRegistryBuilder().applySettings( properties ).buildServiceRegistry();
}
public static void main(String[] args) {

View File

@ -110,7 +110,7 @@ public class SchemaUpdate {
private static BasicServiceRegistryImpl createServiceRegistry(Properties properties) {
Environment.verifyProperties( properties );
ConfigurationHelper.resolvePlaceHolders( properties );
return (BasicServiceRegistryImpl) new ServiceRegistryBuilder( properties ).buildServiceRegistry();
return (BasicServiceRegistryImpl) new ServiceRegistryBuilder().applySettings( properties ).buildServiceRegistry();
}
public static void main(String[] args) {

View File

@ -79,7 +79,7 @@ public class SchemaValidator {
private static BasicServiceRegistryImpl createServiceRegistry(Properties properties) {
Environment.verifyProperties( properties );
ConfigurationHelper.resolvePlaceHolders( properties );
return (BasicServiceRegistryImpl) new ServiceRegistryBuilder( properties ).buildServiceRegistry();
return (BasicServiceRegistryImpl) new ServiceRegistryBuilder().applySettings( properties ).buildServiceRegistry();
}
public static void main(String[] args) {

View File

@ -42,13 +42,16 @@ public class PersisterClassProviderTest extends BaseUnitTestCase {
Configuration cfg = new Configuration();
cfg.addAnnotatedClass( Gate.class );
BasicServiceRegistry serviceRegistry = new ServiceRegistryBuilder( cfg.getProperties() ).buildServiceRegistry();
BasicServiceRegistry serviceRegistry = new ServiceRegistryBuilder()
.applySettings( cfg.getProperties() )
.buildServiceRegistry();
//no exception as the GoofyPersisterClassProvider is not set
SessionFactory sessionFactory = cfg.buildSessionFactory( serviceRegistry );
sessionFactory.close();
ServiceRegistryBuilder.destroy( serviceRegistry );
serviceRegistry = new ServiceRegistryBuilder( cfg.getProperties() )
serviceRegistry = new ServiceRegistryBuilder()
.applySettings( cfg.getProperties() )
.addService( PersisterClassResolver.class, new GoofyPersisterClassProvider() )
.buildServiceRegistry();
cfg = new Configuration();
@ -71,7 +74,8 @@ public class PersisterClassProviderTest extends BaseUnitTestCase {
cfg = new Configuration();
cfg.addAnnotatedClass( Portal.class );
cfg.addAnnotatedClass( Window.class );
serviceRegistry = new ServiceRegistryBuilder( cfg.getProperties() )
serviceRegistry = new ServiceRegistryBuilder()
.applySettings( cfg.getProperties() )
.addService( PersisterClassResolver.class, new GoofyPersisterClassProvider() )
.buildServiceRegistry();
try {

View File

@ -35,9 +35,8 @@ import org.hibernate.event.spi.DeleteEvent;
import org.hibernate.event.spi.DeleteEventListener;
import org.hibernate.event.spi.EventType;
import org.hibernate.integrator.spi.Integrator;
import org.hibernate.integrator.spi.IntegratorService;
import org.hibernate.metamodel.source.MetadataImplementor;
import org.hibernate.service.internal.BasicServiceRegistryImpl;
import org.hibernate.service.internal.BootstrapServiceRegistryImpl;
import org.hibernate.service.spi.SessionFactoryServiceRegistry;
import org.junit.Test;
@ -67,9 +66,9 @@ public class CallbackTest extends BaseCoreFunctionalTestCase {
}
@Override
protected void applyServices(BasicServiceRegistryImpl serviceRegistry) {
super.applyServices( serviceRegistry );
serviceRegistry.getService( IntegratorService.class ).addIntegrator(
protected void prepareBootstrapRegistryBuilder(BootstrapServiceRegistryImpl.Builder builder) {
super.prepareBootstrapRegistryBuilder( builder );
builder.with(
new Integrator() {
@Override

View File

@ -26,13 +26,13 @@ package org.hibernate.test.flush;
import org.hibernate.Session;
import org.hibernate.cfg.Configuration;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.event.spi.EventType;
import org.hibernate.event.service.spi.EventListenerRegistry;
import org.hibernate.integrator.spi.IntegratorService;
import org.hibernate.service.internal.BasicServiceRegistryImpl;
import org.hibernate.service.spi.SessionFactoryServiceRegistry;
import org.hibernate.event.spi.EventType;
import org.hibernate.integrator.spi.Integrator;
import org.hibernate.metamodel.source.MetadataImplementor;
import org.hibernate.service.internal.BootstrapServiceRegistryImpl;
import org.hibernate.service.spi.SessionFactoryServiceRegistry;
import org.junit.Test;
import org.hibernate.testing.FailureExpected;
@ -50,9 +50,9 @@ public class TestCollectionInitializingDuringFlush extends BaseCoreFunctionalTes
}
@Override
protected void applyServices(BasicServiceRegistryImpl serviceRegistry) {
super.applyServices( serviceRegistry );
serviceRegistry.getService( IntegratorService.class ).addIntegrator(
protected void prepareBootstrapRegistryBuilder(BootstrapServiceRegistryImpl.Builder builder) {
super.prepareBootstrapRegistryBuilder( builder );
builder.with(
new Integrator() {
@Override
@ -60,19 +60,21 @@ public class TestCollectionInitializingDuringFlush extends BaseCoreFunctionalTes
Configuration configuration,
SessionFactoryImplementor sessionFactory,
SessionFactoryServiceRegistry serviceRegistry) {
integrate(serviceRegistry);
integrate( serviceRegistry );
}
@Override
public void integrate( MetadataImplementor metadata,
public void integrate(
MetadataImplementor metadata,
SessionFactoryImplementor sessionFactory,
SessionFactoryServiceRegistry serviceRegistry ) {
integrate(serviceRegistry);
SessionFactoryServiceRegistry serviceRegistry) {
integrate( serviceRegistry );
}
private void integrate( SessionFactoryServiceRegistry serviceRegistry ) {
serviceRegistry.getService(EventListenerRegistry.class).getEventListenerGroup(EventType.PRE_UPDATE)
.appendListener(new InitializingPreUpdateEventListener());
private void integrate(SessionFactoryServiceRegistry serviceRegistry) {
serviceRegistry.getService( EventListenerRegistry.class )
.getEventListenerGroup( EventType.PRE_UPDATE )
.appendListener( new InitializingPreUpdateEventListener() );
}
@Override

View File

@ -30,22 +30,21 @@ import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Environment;
import org.hibernate.engine.spi.CascadingAction;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.event.internal.DefaultAutoFlushEventListener;
import org.hibernate.event.internal.DefaultFlushEntityEventListener;
import org.hibernate.event.internal.DefaultFlushEventListener;
import org.hibernate.event.internal.DefaultPersistEventListener;
import org.hibernate.event.service.spi.EventListenerRegistry;
import org.hibernate.event.spi.AutoFlushEventListener;
import org.hibernate.event.spi.EventType;
import org.hibernate.event.spi.FlushEntityEventListener;
import org.hibernate.event.spi.FlushEventListener;
import org.hibernate.event.spi.PersistEventListener;
import org.hibernate.event.internal.DefaultAutoFlushEventListener;
import org.hibernate.event.internal.DefaultFlushEntityEventListener;
import org.hibernate.event.internal.DefaultFlushEventListener;
import org.hibernate.event.internal.DefaultPersistEventListener;
import org.hibernate.integrator.spi.Integrator;
import org.hibernate.internal.util.collections.IdentityMap;
import org.hibernate.metamodel.source.MetadataImplementor;
import org.hibernate.proxy.EntityNotFoundDelegate;
import org.hibernate.event.service.spi.EventListenerRegistry;
import org.hibernate.integrator.spi.IntegratorService;
import org.hibernate.service.internal.BasicServiceRegistryImpl;
import org.hibernate.service.internal.BootstrapServiceRegistryImpl;
import org.hibernate.service.spi.SessionFactoryServiceRegistry;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
@ -70,9 +69,8 @@ public abstract class AbstractJPATest extends BaseCoreFunctionalTestCase {
}
@Override
protected void applyServices(BasicServiceRegistryImpl serviceRegistry) {
super.applyServices( serviceRegistry );
serviceRegistry.getService( IntegratorService.class ).addIntegrator(
protected void prepareBootstrapRegistryBuilder(BootstrapServiceRegistryImpl.Builder builder) {
builder.with(
new Integrator() {
@Override
@ -80,17 +78,18 @@ public abstract class AbstractJPATest extends BaseCoreFunctionalTestCase {
Configuration configuration,
SessionFactoryImplementor sessionFactory,
SessionFactoryServiceRegistry serviceRegistry) {
integrate(serviceRegistry);
integrate( serviceRegistry );
}
@Override
public void integrate( MetadataImplementor metadata,
public void integrate(
MetadataImplementor metadata,
SessionFactoryImplementor sessionFactory,
SessionFactoryServiceRegistry serviceRegistry ) {
integrate(serviceRegistry);
SessionFactoryServiceRegistry serviceRegistry) {
integrate( serviceRegistry );
}
private void integrate( SessionFactoryServiceRegistry serviceRegistry ) {
private void integrate(SessionFactoryServiceRegistry serviceRegistry) {
EventListenerRegistry eventListenerRegistry = serviceRegistry.getService( EventListenerRegistry.class );
eventListenerRegistry.setListeners( EventType.PERSIST, buildPersistEventListeners() );
eventListenerRegistry.setListeners(

View File

@ -28,16 +28,16 @@ import org.hibernate.Session;
import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Environment;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.event.internal.DefaultLoadEventListener;
import org.hibernate.event.service.spi.EventListenerRegistry;
import org.hibernate.event.spi.EventType;
import org.hibernate.event.spi.LoadEvent;
import org.hibernate.event.spi.LoadEventListener;
import org.hibernate.event.internal.DefaultLoadEventListener;
import org.hibernate.event.service.spi.EventListenerRegistry;
import org.hibernate.integrator.spi.IntegratorService;
import org.hibernate.service.internal.BasicServiceRegistryImpl;
import org.hibernate.service.spi.SessionFactoryServiceRegistry;
import org.hibernate.integrator.spi.Integrator;
import org.hibernate.metamodel.source.MetadataImplementor;
import org.hibernate.service.internal.BootstrapServiceRegistryImpl;
import org.hibernate.service.spi.SessionFactoryServiceRegistry;
import org.junit.Test;
import org.hibernate.testing.TestForIssue;
@ -63,10 +63,9 @@ public class EagerKeyManyToOneTest extends BaseCoreFunctionalTestCase {
}
@Override
protected void applyServices(BasicServiceRegistryImpl serviceRegistry) {
super.applyServices( serviceRegistry );
serviceRegistry.getService( IntegratorService.class ).addIntegrator(
protected void prepareBootstrapRegistryBuilder(BootstrapServiceRegistryImpl.Builder builder) {
super.prepareBootstrapRegistryBuilder( builder );
builder.with(
new Integrator() {
@Override

View File

@ -68,7 +68,8 @@ public class BatchingTest extends BaseUnitTestCase implements BatchKey {
@Before
public void setUp() throws Exception {
serviceRegistry = (BasicServiceRegistryImpl) new ServiceRegistryBuilder( ConnectionProviderBuilder.getConnectionProviderProperties() )
serviceRegistry = (BasicServiceRegistryImpl) new ServiceRegistryBuilder()
.applySettings( ConnectionProviderBuilder.getConnectionProviderProperties() )
.buildServiceRegistry();
}

View File

@ -150,7 +150,8 @@ public class SchemaBasedMultiTenancyTest extends BaseUnitTestCase {
false // do not *just* perform the create
);
serviceRegistry = (ServiceRegistryImplementor) new ServiceRegistryBuilder( cfg.getProperties() )
serviceRegistry = (ServiceRegistryImplementor) new ServiceRegistryBuilder()
.applySettings( cfg.getProperties() )
.addService( MultiTenantConnectionProvider.class, multiTenantConnectionProvider )
.buildServiceRegistry();

View File

@ -47,9 +47,9 @@ import org.hibernate.testing.junit4.BaseUnitTestCase;
public class ServiceBootstrappingTest extends BaseUnitTestCase {
@Test
public void testBasicBuild() {
BasicServiceRegistryImpl serviceRegistry = (BasicServiceRegistryImpl) new ServiceRegistryBuilder(
ConnectionProviderBuilder.getConnectionProviderProperties()
).buildServiceRegistry();
BasicServiceRegistryImpl serviceRegistry = (BasicServiceRegistryImpl) new ServiceRegistryBuilder()
.applySettings( ConnectionProviderBuilder.getConnectionProviderProperties() )
.buildServiceRegistry();
JdbcServices jdbcServices = serviceRegistry.getService( JdbcServices.class );
assertTrue( jdbcServices.getDialect() instanceof H2Dialect );
@ -64,7 +64,9 @@ public class ServiceBootstrappingTest extends BaseUnitTestCase {
Properties props = ConnectionProviderBuilder.getConnectionProviderProperties();
props.put( Environment.SHOW_SQL, "true" );
BasicServiceRegistryImpl serviceRegistry = (BasicServiceRegistryImpl) new ServiceRegistryBuilder( props ).buildServiceRegistry();
BasicServiceRegistryImpl serviceRegistry = (BasicServiceRegistryImpl) new ServiceRegistryBuilder()
.applySettings( props )
.buildServiceRegistry();
JdbcServices jdbcServices = serviceRegistry.getService( JdbcServices.class );
@ -77,7 +79,8 @@ public class ServiceBootstrappingTest extends BaseUnitTestCase {
@Test
public void testBuildWithServiceOverride() {
BasicServiceRegistryImpl serviceRegistry = (BasicServiceRegistryImpl) new ServiceRegistryBuilder( ConnectionProviderBuilder.getConnectionProviderProperties() )
BasicServiceRegistryImpl serviceRegistry = (BasicServiceRegistryImpl) new ServiceRegistryBuilder()
.applySettings( ConnectionProviderBuilder.getConnectionProviderProperties() )
.buildServiceRegistry();
JdbcServices jdbcServices = serviceRegistry.getService( JdbcServices.class );
@ -87,7 +90,8 @@ public class ServiceBootstrappingTest extends BaseUnitTestCase {
Properties props = ConnectionProviderBuilder.getConnectionProviderProperties();
props.setProperty( Environment.DIALECT, H2Dialect.class.getName() );
serviceRegistry = (BasicServiceRegistryImpl) new ServiceRegistryBuilder( props )
serviceRegistry = (BasicServiceRegistryImpl) new ServiceRegistryBuilder()
.applySettings( props )
.addService( ConnectionProvider.class, new UserSuppliedConnectionProviderImpl() )
.buildServiceRegistry();
jdbcServices = serviceRegistry.getService( JdbcServices.class );

View File

@ -59,7 +59,8 @@ public class TestExpectedUsage extends BaseUnitTestCase {
@Before
public void setUp() throws Exception {
serviceRegistry = (BasicServiceRegistryImpl) new ServiceRegistryBuilder( ConnectionProviderBuilder.getConnectionProviderProperties() )
serviceRegistry = (BasicServiceRegistryImpl) new ServiceRegistryBuilder()
.applySettings( ConnectionProviderBuilder.getConnectionProviderProperties() )
.buildServiceRegistry();
}

View File

@ -71,7 +71,9 @@ public class BasicDrivingTest extends BaseUnitTestCase {
configValues.putAll( ConnectionProviderBuilder.getConnectionProviderProperties() );
configValues.put( Environment.TRANSACTION_STRATEGY, JtaTransactionFactory.class.getName() );
TestingJtaBootstrap.prepare( configValues );
serviceRegistry = (BasicServiceRegistryImpl) new ServiceRegistryBuilder( configValues ).buildServiceRegistry();
serviceRegistry = (BasicServiceRegistryImpl) new ServiceRegistryBuilder()
.applySettings( configValues )
.buildServiceRegistry();
}
@After

View File

@ -71,7 +71,9 @@ public class ManagedDrivingTest extends BaseUnitTestCase {
TestingJtaBootstrap.prepare( configValues );
configValues.put( Environment.TRANSACTION_STRATEGY, CMTTransactionFactory.class.getName() );
serviceRegistry = (BasicServiceRegistryImpl) new ServiceRegistryBuilder( configValues ).buildServiceRegistry();
serviceRegistry = (BasicServiceRegistryImpl) new ServiceRegistryBuilder()
.applySettings( configValues )
.buildServiceRegistry();
}
@After

View File

@ -92,7 +92,6 @@ import org.hibernate.engine.spi.FilterDefinition;
import org.hibernate.engine.transaction.internal.jdbc.JdbcTransactionFactory;
import org.hibernate.engine.transaction.internal.jta.CMTTransactionFactory;
import org.hibernate.id.factory.spi.MutableIdentifierGeneratorFactory;
import org.hibernate.integrator.spi.IntegratorService;
import org.hibernate.internal.util.ReflectHelper;
import org.hibernate.internal.util.StringHelper;
import org.hibernate.internal.util.collections.CollectionHelper;
@ -103,8 +102,8 @@ import org.hibernate.mapping.AuxiliaryDatabaseObject;
import org.hibernate.mapping.PersistentClass;
import org.hibernate.proxy.EntityNotFoundDelegate;
import org.hibernate.secure.internal.JACCConfiguration;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.service.ServiceRegistryBuilder;
import org.hibernate.service.internal.BootstrapServiceRegistryImpl;
import org.hibernate.service.jdbc.connections.internal.DatasourceConnectionProviderImpl;
/**
@ -133,6 +132,7 @@ import org.hibernate.service.jdbc.connections.internal.DatasourceConnectionProvi
* <a href="http://opensource.atlassian.com/projects/hibernate/browse/HHH-6159">HHH-6159</a> for details
*/
@Deprecated
@SuppressWarnings( {"JavaDoc"})
public class Ejb3Configuration implements Serializable, Referenceable {
private static final EntityManagerMessageLogger LOG = Logger.getMessageLogger(
@ -883,27 +883,32 @@ public class Ejb3Configuration implements Serializable, Referenceable {
}
public EntityManagerFactory buildEntityManagerFactory() {
return buildEntityManagerFactory( new ServiceRegistryBuilder( cfg.getProperties() ).buildServiceRegistry() );
return buildEntityManagerFactory( BootstrapServiceRegistryImpl.builder() );
}
public EntityManagerFactory buildEntityManagerFactory(ServiceRegistry serviceRegistry) {
public EntityManagerFactory buildEntityManagerFactory(BootstrapServiceRegistryImpl.Builder builder) {
Thread thread = null;
ClassLoader contextClassLoader = null;
if (overridenClassLoader != null) {
if ( overridenClassLoader != null ) {
thread = Thread.currentThread();
contextClassLoader = thread.getContextClassLoader();
thread.setContextClassLoader( overridenClassLoader );
}
try {
configure( (Properties)null, null );
NamingHelper.bind(this);
serviceRegistry.getService( IntegratorService.class ).addIntegrator( new JpaIntegrator() );
final ServiceRegistryBuilder serviceRegistryBuilder = new ServiceRegistryBuilder(
builder.with( new JpaIntegrator() ).build()
);
serviceRegistryBuilder.applySettings( cfg.getProperties() );
configure( (Properties) null, null );
NamingHelper.bind( this );
return new EntityManagerFactoryImpl(
transactionType,
discardOnClose,
getSessionInterceptorClass( cfg.getProperties() ),
cfg,
serviceRegistry
serviceRegistryBuilder.buildServiceRegistry()
);
}
catch (HibernateException e) {

View File

@ -41,9 +41,11 @@ import org.hibernate.cfg.Environment;
import org.hibernate.dialect.Dialect;
import org.hibernate.ejb.AvailableSettings;
import org.hibernate.ejb.Ejb3Configuration;
import org.hibernate.internal.util.config.ConfigurationHelper;
import org.hibernate.ejb.EntityManagerFactoryImpl;
import org.hibernate.internal.SessionFactoryImpl;
import org.hibernate.service.ServiceRegistryBuilder;
import org.hibernate.service.internal.BasicServiceRegistryImpl;
import org.hibernate.service.internal.BootstrapServiceRegistryImpl;
import org.junit.After;
import org.junit.Before;
@ -66,7 +68,7 @@ public abstract class BaseEntityManagerFunctionalTestCase extends BaseUnitTestCa
private Ejb3Configuration ejb3Configuration;
private BasicServiceRegistryImpl serviceRegistry;
private EntityManagerFactory entityManagerFactory;
private EntityManagerFactoryImpl entityManagerFactory;
private EntityManager em;
private ArrayList<EntityManager> isolatedEms = new ArrayList<EntityManager>();
@ -90,12 +92,17 @@ public abstract class BaseEntityManagerFunctionalTestCase extends BaseUnitTestCa
ejb3Configuration = buildConfiguration();
ejb3Configuration.configure( getConfig() );
afterConfigurationBuilt( ejb3Configuration );
serviceRegistry = buildServiceRegistry( ejb3Configuration.getHibernateConfiguration() );
applyServices( serviceRegistry );
entityManagerFactory = ejb3Configuration.buildEntityManagerFactory( serviceRegistry );
entityManagerFactory = (EntityManagerFactoryImpl) ejb3Configuration.buildEntityManagerFactory( bootstrapRegistryBuilder() );
serviceRegistry = (BasicServiceRegistryImpl) ( (SessionFactoryImpl) entityManagerFactory.getSessionFactory() ).getServiceRegistry().getParentServiceRegistry();
afterEntityManagerFactoryBuilt();
}
private BootstrapServiceRegistryImpl.Builder bootstrapRegistryBuilder() {
return BootstrapServiceRegistryImpl.builder();
}
protected Ejb3Configuration buildConfiguration() {
Ejb3Configuration ejb3Cfg = constructConfiguration();
addMappings( ejb3Cfg.getHibernateConfiguration() );
@ -199,16 +206,8 @@ public abstract class BaseEntityManagerFunctionalTestCase extends BaseUnitTestCa
protected void afterConfigurationBuilt(Ejb3Configuration ejb3Configuration) {
}
protected BasicServiceRegistryImpl buildServiceRegistry(Configuration configuration) {
Properties properties = new Properties();
properties.putAll( configuration.getProperties() );
Environment.verifyProperties( properties );
ConfigurationHelper.resolvePlaceHolders( properties );
return (BasicServiceRegistryImpl) new ServiceRegistryBuilder( properties ).buildServiceRegistry();
}
@SuppressWarnings( {"UnusedParameters"})
protected void applyServices(BasicServiceRegistryImpl serviceRegistry) {
protected void applyServices(ServiceRegistryBuilder registryBuilder) {
}
protected void afterEntityManagerFactoryBuilt() {

View File

@ -23,28 +23,30 @@
*/
package org.hibernate.envers.test;
import javax.persistence.EntityManager;
import java.io.IOException;
import java.util.Properties;
import org.hibernate.cfg.Environment;
import org.hibernate.ejb.Ejb3Configuration;
import org.hibernate.ejb.EntityManagerFactoryImpl;
import org.hibernate.envers.AuditReader;
import org.hibernate.envers.AuditReaderFactory;
import org.hibernate.envers.event.EnversIntegrator;
import org.hibernate.internal.util.config.ConfigurationHelper;
import org.hibernate.service.ServiceRegistryBuilder;
import org.hibernate.internal.SessionFactoryImpl;
import org.hibernate.service.internal.BasicServiceRegistryImpl;
import org.hibernate.testing.AfterClassOnce;
import org.hibernate.testing.BeforeClassOnce;
import org.hibernate.service.internal.BootstrapServiceRegistryImpl;
import org.junit.Before;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import java.io.IOException;
import java.util.Properties;
import org.hibernate.testing.AfterClassOnce;
import org.hibernate.testing.BeforeClassOnce;
/**
* @author Adam Warski (adam at warski dot org)
*/
public abstract class AbstractEntityTest extends AbstractEnversTest {
private EntityManagerFactory emf;
private EntityManagerFactoryImpl emf;
private EntityManager entityManager;
private AuditReader auditReader;
private Ejb3Configuration cfg;
@ -104,20 +106,18 @@ public abstract class AbstractEntityTest extends AbstractEnversTest {
configure(cfg);
cfg.configure(configurationProperties);
serviceRegistry = createServiceRegistry(cfg);
emf = (EntityManagerFactoryImpl) cfg.buildEntityManagerFactory( createBootstrapRegistryBuilder() );
emf = cfg.buildEntityManagerFactory( serviceRegistry );
serviceRegistry = (BasicServiceRegistryImpl) ( (SessionFactoryImpl) emf.getSessionFactory() ).getServiceRegistry().getParentServiceRegistry();
newEntityManager();
}
private BasicServiceRegistryImpl createServiceRegistry(Ejb3Configuration configuration) {
Properties properties = new Properties();
properties.putAll(configuration.getHibernateConfiguration().getProperties());
ConfigurationHelper.resolvePlaceHolders(properties);
return (BasicServiceRegistryImpl) new ServiceRegistryBuilder(properties).buildServiceRegistry();
private BootstrapServiceRegistryImpl.Builder createBootstrapRegistryBuilder() {
return BootstrapServiceRegistryImpl.builder();
}
@AfterClassOnce
public void close() {
closeEntityManager();

View File

@ -79,7 +79,7 @@ public abstract class AbstractGeneralDataRegionTestCase extends AbstractRegionIm
private void evictOrRemoveTest() throws Exception {
Configuration cfg = createConfiguration();
InfinispanRegionFactory regionFactory = CacheTestUtil.startRegionFactory(
new ServiceRegistryBuilder( cfg.getProperties() ).buildServiceRegistry(),
new ServiceRegistryBuilder().applySettings( cfg.getProperties() ).buildServiceRegistry(),
cfg,
getCacheTestSupport()
);
@ -96,7 +96,7 @@ public abstract class AbstractGeneralDataRegionTestCase extends AbstractRegionIm
cfg = createConfiguration();
regionFactory = CacheTestUtil.startRegionFactory(
new ServiceRegistryBuilder( cfg.getProperties() ).buildServiceRegistry(),
new ServiceRegistryBuilder().applySettings( cfg.getProperties() ).buildServiceRegistry(),
cfg,
getCacheTestSupport()
);
@ -142,7 +142,7 @@ public abstract class AbstractGeneralDataRegionTestCase extends AbstractRegionIm
private void evictOrRemoveAllTest(String configName) throws Exception {
Configuration cfg = createConfiguration();
InfinispanRegionFactory regionFactory = CacheTestUtil.startRegionFactory(
new ServiceRegistryBuilder( cfg.getProperties() ).buildServiceRegistry(),
new ServiceRegistryBuilder().applySettings( cfg.getProperties() ).buildServiceRegistry(),
cfg,
getCacheTestSupport()
);
@ -160,7 +160,7 @@ public abstract class AbstractGeneralDataRegionTestCase extends AbstractRegionIm
cfg = createConfiguration();
regionFactory = CacheTestUtil.startRegionFactory(
new ServiceRegistryBuilder( cfg.getProperties() ).buildServiceRegistry(),
new ServiceRegistryBuilder().applySettings( cfg.getProperties() ).buildServiceRegistry(),
cfg,
getCacheTestSupport()
);

View File

@ -109,7 +109,9 @@ public class NodeEnvironment {
}
public void prepare() throws Exception {
serviceRegistry = (BasicServiceRegistryImpl) new ServiceRegistryBuilder( configuration.getProperties() ).buildServiceRegistry();
serviceRegistry = (BasicServiceRegistryImpl) new ServiceRegistryBuilder()
.applySettings( configuration.getProperties() )
.buildServiceRegistry();
regionFactory = CacheTestUtil.startRegionFactory( serviceRegistry, configuration );
}

View File

@ -89,7 +89,7 @@ public class QueryRegionImplTestCase extends AbstractGeneralDataRegionTestCase {
private void putDoesNotBlockGetTest() throws Exception {
Configuration cfg = createConfiguration();
InfinispanRegionFactory regionFactory = CacheTestUtil.startRegionFactory(
new ServiceRegistryBuilder( cfg.getProperties() ).buildServiceRegistry(),
new ServiceRegistryBuilder().applySettings( cfg.getProperties() ).buildServiceRegistry(),
cfg,
getCacheTestSupport()
);
@ -189,7 +189,7 @@ public class QueryRegionImplTestCase extends AbstractGeneralDataRegionTestCase {
private void getDoesNotBlockPutTest() throws Exception {
Configuration cfg = createConfiguration();
InfinispanRegionFactory regionFactory = CacheTestUtil.startRegionFactory(
new ServiceRegistryBuilder( cfg.getProperties() ).buildServiceRegistry(),
new ServiceRegistryBuilder().applySettings( cfg.getProperties() ).buildServiceRegistry(),
cfg,
getCacheTestSupport()
);

View File

@ -82,7 +82,7 @@ public class TimestampsRegionImplTestCase extends AbstractGeneralDataRegionTestC
public void testClearTimestampsRegionInIsolated() throws Exception {
Configuration cfg = createConfiguration();
InfinispanRegionFactory regionFactory = CacheTestUtil.startRegionFactory(
new ServiceRegistryBuilder( cfg.getProperties() ).buildServiceRegistry(),
new ServiceRegistryBuilder().applySettings( cfg.getProperties() ).buildServiceRegistry(),
cfg,
getCacheTestSupport()
);
@ -91,7 +91,7 @@ public class TimestampsRegionImplTestCase extends AbstractGeneralDataRegionTestC
Configuration cfg2 = createConfiguration();
InfinispanRegionFactory regionFactory2 = CacheTestUtil.startRegionFactory(
new ServiceRegistryBuilder( cfg.getProperties() ).buildServiceRegistry(),
new ServiceRegistryBuilder().applySettings( cfg.getProperties() ).buildServiceRegistry(),
cfg2,
getCacheTestSupport()
);

View File

@ -38,7 +38,9 @@ public class ServiceRegistryBuilder {
}
public static BasicServiceRegistryImpl buildServiceRegistry(Map serviceRegistryConfig) {
return (BasicServiceRegistryImpl) new org.hibernate.service.ServiceRegistryBuilder( serviceRegistryConfig ).buildServiceRegistry();
return (BasicServiceRegistryImpl) new org.hibernate.service.ServiceRegistryBuilder()
.applySettings( serviceRegistryConfig )
.buildServiceRegistry();
}
public static void destroy(ServiceRegistry serviceRegistry) {

View File

@ -54,8 +54,10 @@ import org.hibernate.mapping.SimpleValue;
import org.hibernate.metamodel.MetadataSources;
import org.hibernate.metamodel.source.MetadataImplementor;
import org.hibernate.service.BasicServiceRegistry;
import org.hibernate.service.ServiceRegistryBuilder;
import org.hibernate.service.config.spi.ConfigurationService;
import org.hibernate.service.internal.BasicServiceRegistryImpl;
import org.hibernate.service.internal.BootstrapServiceRegistryImpl;
import org.junit.After;
import org.junit.Before;
@ -321,12 +323,24 @@ public abstract class BaseCoreFunctionalTestCase extends BaseUnitTestCase {
properties.putAll( configuration.getProperties() );
Environment.verifyProperties( properties );
ConfigurationHelper.resolvePlaceHolders( properties );
BasicServiceRegistryImpl serviceRegistry = (BasicServiceRegistryImpl) new org.hibernate.service.ServiceRegistryBuilder( properties ).buildServiceRegistry();
applyServices( serviceRegistry );
return serviceRegistry;
final BootstrapServiceRegistryImpl bootstrapServiceRegistry = generateBootstrapRegistry( properties );
ServiceRegistryBuilder registryBuilder = new ServiceRegistryBuilder( bootstrapServiceRegistry )
.applySettings( properties );
prepareBasicRegistryBuilder( registryBuilder );
return (BasicServiceRegistryImpl) registryBuilder.buildServiceRegistry();
}
protected void applyServices(BasicServiceRegistryImpl serviceRegistry) {
protected BootstrapServiceRegistryImpl generateBootstrapRegistry(Properties properties) {
final BootstrapServiceRegistryImpl.Builder builder = BootstrapServiceRegistryImpl.builder();
prepareBootstrapRegistryBuilder( builder );
return builder.build();
}
protected void prepareBootstrapRegistryBuilder(BootstrapServiceRegistryImpl.Builder builder) {
}
protected void prepareBasicRegistryBuilder(ServiceRegistryBuilder serviceRegistryBuilder) {
}
protected void afterSessionFactoryBuilt() {