diff --git a/hibernate-core/src/main/java/org/hibernate/boot/registry/classloading/internal/ClassLoaderServiceImpl.java b/hibernate-core/src/main/java/org/hibernate/boot/registry/classloading/internal/ClassLoaderServiceImpl.java index 0e4643fef5..143eec93b7 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/registry/classloading/internal/ClassLoaderServiceImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/registry/classloading/internal/ClassLoaderServiceImpl.java @@ -325,6 +325,11 @@ public class ClassLoaderServiceImpl implements ClassLoaderService { return services; } + + @Override + public ClassLoader getAggregatedClassLoader() { + return aggregatedClassLoader; + } // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! // completely temporary !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! diff --git a/hibernate-core/src/main/java/org/hibernate/boot/registry/classloading/spi/ClassLoaderService.java b/hibernate-core/src/main/java/org/hibernate/boot/registry/classloading/spi/ClassLoaderService.java index 25b94c726b..572351d2e5 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/registry/classloading/spi/ClassLoaderService.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/registry/classloading/spi/ClassLoaderService.java @@ -87,4 +87,11 @@ public interface ClassLoaderService extends Service { * @return The ordered set of discovered services. */ public LinkedHashSet loadJavaServices(Class serviceContract); + + /** + * Some 3rd party libraries take ClassLoaders as arguments. Support using the aggregated ClassLoader. + * + * @return The aggregated ClassLoader + */ + public ClassLoader getAggregatedClassLoader(); } diff --git a/hibernate-core/src/main/java/org/hibernate/internal/util/ConfigHelper.java b/hibernate-core/src/main/java/org/hibernate/internal/util/ConfigHelper.java index 0f19a3051b..54fc0b2878 100644 --- a/hibernate-core/src/main/java/org/hibernate/internal/util/ConfigHelper.java +++ b/hibernate-core/src/main/java/org/hibernate/internal/util/ConfigHelper.java @@ -32,6 +32,7 @@ import java.net.URL; import java.util.Properties; import org.hibernate.HibernateException; +import org.hibernate.boot.registry.classloading.spi.ClassLoaderService; import org.hibernate.cfg.Environment; import org.hibernate.internal.CoreMessageLogger; import org.jboss.logging.Logger; @@ -50,63 +51,34 @@ public final class ConfigHelper { /** Try to locate a local URL representing the incoming path. The first attempt * assumes that the incoming path is an actual URL string (file://, etc). If this - * does not work, then the next attempts try to locate this UURL as a java system - * resource. + * does not work, then the next attempts try to locate this URL as a java system + * resource through {@link ClassLoaderService}. * * @param path The path representing the config location. + * @param classLoaderService The ClassLoaderService. * @return An appropriate URL or null. */ - public static URL locateConfig(final String path) { + public static URL locateConfig(final String path, final ClassLoaderService classLoaderService) { try { return new URL(path); } catch(MalformedURLException e) { - return findAsResource(path); + return classLoaderService.locateResource( path ); } } - /** - * Try to locate a local URL representing the incoming path. - * This method only attempts to locate this URL as a - * java system resource. - * - * @param path The path representing the config location. - * @return An appropriate URL or null. - */ - public static URL findAsResource(final String path) { - URL url = null; - - // First, try to locate this resource through the current - // context classloader. - ClassLoader contextClassLoader = ClassLoaderHelper.getContextClassLoader(); - if (contextClassLoader!=null) { - url = contextClassLoader.getResource(path); - } - if (url != null) - return url; - - // Next, try to locate this resource through this class's classloader - url = ConfigHelper.class.getClassLoader().getResource(path); - if (url != null) - return url; - - // Next, try to locate this resource through the system classloader - url = ClassLoader.getSystemClassLoader().getResource(path); - - // Anywhere else we should look? - return url; - } - /** Open an InputStream to the URL represented by the incoming path. First makes a call * to {@link #locateConfig(java.lang.String)} in order to find an appropriate URL. * {@link java.net.URL#openStream()} is then called to obtain the stream. * * @param path The path representing the config location. + * @param classLoaderService The ClassLoaderService. * @return An input stream to the requested config resource. * @throws HibernateException Unable to open stream to that resource. */ - public static InputStream getConfigStream(final String path) throws HibernateException { - final URL url = ConfigHelper.locateConfig(path); + public static InputStream getConfigStream(final String path, + final ClassLoaderService classLoaderService) throws HibernateException { + final URL url = ConfigHelper.locateConfig(path, classLoaderService); if (url == null) { String msg = LOG.unableToLocateConfigFile(path); @@ -128,23 +100,27 @@ public final class ConfigHelper { * wrapped in a Reader. * * @param path The path representing the config location. + * @param classLoaderService The ClassLoaderService. * @return An input stream to the requested config resource. * @throws HibernateException Unable to open reader to that resource. */ - public static Reader getConfigStreamReader(final String path) throws HibernateException { - return new InputStreamReader( getConfigStream(path) ); + public static Reader getConfigStreamReader(final String path, + final ClassLoaderService classLoaderService) throws HibernateException { + return new InputStreamReader( getConfigStream(path, classLoaderService) ); } /** Loads a properties instance based on the data at the incoming config location. * * @param path The path representing the config location. + * @param classLoaderService The ClassLoaderService. * @return The loaded properties instance. * @throws HibernateException Unable to load properties from that resource. */ - public static Properties getConfigProperties(String path) throws HibernateException { + public static Properties getConfigProperties(String path, + final ClassLoaderService classLoaderService) throws HibernateException { try { Properties properties = new Properties(); - properties.load( getConfigStream(path) ); + properties.load( getConfigStream(path, classLoaderService) ); return properties; } catch(IOException e) { diff --git a/hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/internal/EntityManagerFactoryBuilderImpl.java b/hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/internal/EntityManagerFactoryBuilderImpl.java index 5ff73da5fb..52d988d4c7 100644 --- a/hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/internal/EntityManagerFactoryBuilderImpl.java +++ b/hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/internal/EntityManagerFactoryBuilderImpl.java @@ -40,15 +40,6 @@ import java.util.Properties; import java.util.Set; import java.util.StringTokenizer; -import org.jboss.jandex.AnnotationInstance; -import org.jboss.jandex.ClassInfo; -import org.jboss.jandex.CompositeIndex; -import org.jboss.jandex.DotName; -import org.jboss.jandex.Index; -import org.jboss.jandex.IndexView; -import org.jboss.jandex.Indexer; - -import org.jboss.logging.Logger; import javax.persistence.AttributeConverter; import javax.persistence.EntityManagerFactory; import javax.persistence.EntityNotFoundException; @@ -84,10 +75,10 @@ import org.hibernate.engine.transaction.internal.jta.CMTTransactionFactory; import org.hibernate.id.factory.spi.MutableIdentifierGeneratorFactory; import org.hibernate.integrator.spi.Integrator; import org.hibernate.internal.util.StringHelper; +import org.hibernate.internal.util.ValueHolder; import org.hibernate.internal.util.collections.CollectionHelper; import org.hibernate.jaxb.spi.cfg.JaxbHibernateConfiguration; import org.hibernate.jaxb.spi.cfg.JaxbHibernateConfiguration.JaxbSessionFactory.JaxbMapping; -import org.hibernate.internal.util.ValueHolder; import org.hibernate.jpa.AvailableSettings; import org.hibernate.jpa.boot.scan.internal.StandardScanOptions; import org.hibernate.jpa.boot.scan.internal.StandardScanner; @@ -122,6 +113,14 @@ import org.hibernate.secure.spi.GrantedPermission; import org.hibernate.secure.spi.JaccService; import org.hibernate.service.ServiceRegistry; import org.hibernate.service.spi.ServiceRegistryImplementor; +import org.jboss.jandex.AnnotationInstance; +import org.jboss.jandex.ClassInfo; +import org.jboss.jandex.CompositeIndex; +import org.jboss.jandex.DotName; +import org.jboss.jandex.Index; +import org.jboss.jandex.IndexView; +import org.jboss.jandex.Indexer; +import org.jboss.logging.Logger; /** * @author Steve Ebersole @@ -474,7 +473,8 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil metadataSources.converterDescriptors.add( new MetadataSources.ConverterDescriptor( className, - JandexHelper.getValue( converterAnnotation, "autoApply", boolean.class ) + JandexHelper.getValue( converterAnnotation, "autoApply", boolean.class, + serviceRegistryBuilder.getBootstrapServiceRegistry().getService( ClassLoaderService.class ) ) ) ); } diff --git a/hibernate-entitymanager/src/main/java/org/hibernate/jpa/spi/AbstractEntityManagerImpl.java b/hibernate-entitymanager/src/main/java/org/hibernate/jpa/spi/AbstractEntityManagerImpl.java index acf43e3eca..66dd96a1e0 100755 --- a/hibernate-entitymanager/src/main/java/org/hibernate/jpa/spi/AbstractEntityManagerImpl.java +++ b/hibernate-entitymanager/src/main/java/org/hibernate/jpa/spi/AbstractEntityManagerImpl.java @@ -23,6 +23,16 @@ */ package org.hibernate.jpa.spi; +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.io.Serializable; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + import javax.persistence.CacheRetrieveMode; import javax.persistence.CacheStoreMode; import javax.persistence.EntityExistsException; @@ -57,17 +67,6 @@ import javax.persistence.spi.PersistenceUnitTransactionType; import javax.transaction.Status; import javax.transaction.SystemException; import javax.transaction.TransactionManager; -import java.io.IOException; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.io.Serializable; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.jboss.logging.Logger; import org.hibernate.AssertionFailure; import org.hibernate.CacheMode; @@ -83,12 +82,12 @@ import org.hibernate.SQLQuery; import org.hibernate.Session; import org.hibernate.StaleObjectStateException; import org.hibernate.StaleStateException; -import org.hibernate.procedure.ProcedureCall; import org.hibernate.TransientObjectException; import org.hibernate.TypeMismatchException; import org.hibernate.UnresolvableObjectException; +import org.hibernate.boot.registry.classloading.spi.ClassLoaderService; +import org.hibernate.boot.registry.classloading.spi.ClassLoadingException; import org.hibernate.cfg.Environment; -import org.hibernate.cfg.NotYetImplementedException; import org.hibernate.dialect.lock.LockingStrategyException; import org.hibernate.dialect.lock.OptimisticEntityLockException; import org.hibernate.dialect.lock.PessimisticEntityLockException; @@ -100,6 +99,7 @@ import org.hibernate.engine.spi.NamedSQLQueryDefinition; import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.engine.spi.SessionImplementor; import org.hibernate.engine.transaction.internal.jta.JtaStatusHelper; +import org.hibernate.engine.transaction.jta.platform.spi.JtaPlatform; import org.hibernate.engine.transaction.spi.JoinStatus; import org.hibernate.engine.transaction.spi.TransactionCoordinator; import org.hibernate.engine.transaction.spi.TransactionImplementor; @@ -107,7 +107,6 @@ import org.hibernate.engine.transaction.synchronization.spi.AfterCompletionActio import org.hibernate.engine.transaction.synchronization.spi.ExceptionMapper; import org.hibernate.engine.transaction.synchronization.spi.ManagedFlushChecker; import org.hibernate.engine.transaction.synchronization.spi.SynchronizationCallbackCoordinator; -import org.hibernate.internal.util.ReflectHelper; import org.hibernate.internal.util.collections.CollectionHelper; import org.hibernate.jpa.AvailableSettings; import org.hibernate.jpa.HibernateEntityManagerFactory; @@ -124,11 +123,12 @@ import org.hibernate.jpa.internal.TransactionImpl; import org.hibernate.jpa.internal.util.CacheModeHelper; import org.hibernate.jpa.internal.util.ConfigurationHelper; import org.hibernate.jpa.internal.util.LockModeTypeHelper; +import org.hibernate.procedure.ProcedureCall; import org.hibernate.procedure.ProcedureCallMemento; import org.hibernate.proxy.HibernateProxy; -import org.hibernate.engine.transaction.jta.platform.spi.JtaPlatform; import org.hibernate.transform.BasicTransformerAdapter; import org.hibernate.type.Type; +import org.jboss.logging.Logger; /** @@ -756,9 +756,10 @@ public abstract class AbstractEntityManagerImpl implements HibernateEntityManage if ( nativeSQLQueryReturn instanceof NativeSQLQueryRootReturn ) { final String entityClassName = ( ( NativeSQLQueryRootReturn ) nativeSQLQueryReturn ).getReturnEntityName(); try { - actualReturnedClass = ReflectHelper.classForName( entityClassName, AbstractEntityManagerImpl.class ); + actualReturnedClass = factoryImplementor.getServiceRegistry().getService( + ClassLoaderService.class ).classForName( entityClassName ); } - catch ( ClassNotFoundException e ) { + catch ( ClassLoadingException e ) { throw new AssertionFailure( "Unable to instantiate class declared on named native query: " + name + " " + entityClassName ); } if ( !resultClass.isAssignableFrom( actualReturnedClass ) ) { diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/packaging/PackagedEntityManagerTest.java b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/packaging/PackagedEntityManagerTest.java index 1575b0cc47..6081d76f6d 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/packaging/PackagedEntityManagerTest.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/packaging/PackagedEntityManagerTest.java @@ -23,19 +23,28 @@ */ package org.hibernate.jpa.test.packaging; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + import java.io.File; import java.util.HashMap; import java.util.HashSet; import java.util.Properties; + import javax.persistence.EntityManager; import javax.persistence.EntityManagerFactory; import javax.persistence.Persistence; import javax.persistence.PersistenceException; -import org.junit.Test; - +import org.hibernate.boot.registry.classloading.spi.ClassLoaderService; import org.hibernate.ejb.AvailableSettings; import org.hibernate.ejb.HibernateEntityManagerFactory; +import org.hibernate.engine.spi.SessionImplementor; +import org.hibernate.event.service.spi.EventListenerRegistry; +import org.hibernate.event.spi.EventType; import org.hibernate.jpa.test.Distributor; import org.hibernate.jpa.test.Item; import org.hibernate.jpa.test.pack.cfgxmlpar.Morito; @@ -56,18 +65,9 @@ import org.hibernate.jpa.test.pack.explodedpar.Elephant; import org.hibernate.jpa.test.pack.externaljar.Scooter; import org.hibernate.jpa.test.pack.various.Airplane; import org.hibernate.jpa.test.pack.various.Seat; -import org.hibernate.engine.spi.SessionImplementor; -import org.hibernate.event.service.spi.EventListenerRegistry; -import org.hibernate.event.spi.EventType; -import org.hibernate.internal.util.ConfigHelper; import org.hibernate.stat.Statistics; import org.hibernate.testing.FailureExpectedWithNewMetamodel; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import org.junit.Test; /** * In this test we verify that it is possible to bootstrap Hibernate/JPA from @@ -306,7 +306,8 @@ public class PackagedEntityManagerTest extends PackagingTestCase { HashMap properties = new HashMap(); properties.put( AvailableSettings.JTA_DATASOURCE, null ); Properties p = new Properties(); - p.load( ConfigHelper.getResourceAsStream( "/overridenpar.properties" ) ); + p.load( serviceRegistry().getService( ClassLoaderService.class ).locateResourceStream( + "/overridenpar.properties" ) ); properties.putAll( p ); EntityManagerFactory emf = Persistence.createEntityManagerFactory( "overridenpar", properties ); EntityManager em = emf.createEntityManager(); diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/configuration/spi/AuditConfiguration.java b/hibernate-envers/src/main/java/org/hibernate/envers/configuration/spi/AuditConfiguration.java index 2675a1a541..bfb02a6c83 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/configuration/spi/AuditConfiguration.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/configuration/spi/AuditConfiguration.java @@ -105,10 +105,10 @@ public class AuditConfiguration { } public AuditConfiguration(Configuration cfg, ClassLoaderService classLoaderService) { - // TODO: Temporarily allow Envers to continuing using - // hibernate-commons-annotations' for reflection and class loading. + // TODO: Temporarily allow Envers to continuing to use hibernate-commons-annotations' for reflection and class + // loading. final ClassLoader tccl = Thread.currentThread().getContextClassLoader(); - Thread.currentThread().setContextClassLoader( ClassLoaderHelper.getContextClassLoader() ); + Thread.currentThread().setContextClassLoader( classLoaderService.getAggregatedClassLoader() ); final Properties properties = cfg.getProperties(); diff --git a/hibernate-infinispan/src/main/java/org/hibernate/cache/infinispan/InfinispanRegionFactory.java b/hibernate-infinispan/src/main/java/org/hibernate/cache/infinispan/InfinispanRegionFactory.java index 49ecb7cab2..2c8decb7b1 100644 --- a/hibernate-infinispan/src/main/java/org/hibernate/cache/infinispan/InfinispanRegionFactory.java +++ b/hibernate-infinispan/src/main/java/org/hibernate/cache/infinispan/InfinispanRegionFactory.java @@ -12,8 +12,31 @@ import java.util.Properties; import java.util.Set; import java.util.concurrent.TimeUnit; +import org.hibernate.boot.registry.classloading.spi.ClassLoaderService; +import org.hibernate.cache.CacheException; +import org.hibernate.cache.infinispan.collection.CollectionRegionImpl; +import org.hibernate.cache.infinispan.entity.EntityRegionImpl; +import org.hibernate.cache.infinispan.impl.BaseRegion; +import org.hibernate.cache.infinispan.naturalid.NaturalIdRegionImpl; +import org.hibernate.cache.infinispan.query.QueryResultsRegionImpl; import org.hibernate.cache.infinispan.timestamp.ClusteredTimestampsRegionImpl; +import org.hibernate.cache.infinispan.timestamp.TimestampTypeOverrides; +import org.hibernate.cache.infinispan.timestamp.TimestampsRegionImpl; +import org.hibernate.cache.infinispan.tm.HibernateTransactionManagerLookup; +import org.hibernate.cache.infinispan.util.CacheCommandFactory; import org.hibernate.cache.infinispan.util.Caches; +import org.hibernate.cache.spi.AbstractRegionFactory; +import org.hibernate.cache.spi.CacheDataDescription; +import org.hibernate.cache.spi.CollectionRegion; +import org.hibernate.cache.spi.EntityRegion; +import org.hibernate.cache.spi.NaturalIdRegion; +import org.hibernate.cache.spi.QueryResultsRegion; +import org.hibernate.cache.spi.RegionFactory; +import org.hibernate.cache.spi.TimestampsRegion; +import org.hibernate.cache.spi.access.AccessType; +import org.hibernate.engine.config.spi.ConfigurationService; +import org.hibernate.internal.util.config.ConfigurationHelper; +import org.hibernate.service.ServiceRegistry; import org.infinispan.AdvancedCache; import org.infinispan.commands.module.ModuleCommandFactory; import org.infinispan.configuration.cache.CacheMode; @@ -26,36 +49,11 @@ import org.infinispan.manager.DefaultCacheManager; import org.infinispan.manager.EmbeddedCacheManager; import org.infinispan.transaction.TransactionMode; import org.infinispan.transaction.lookup.GenericTransactionManagerLookup; -import org.infinispan.util.concurrent.IsolationLevel; import org.infinispan.util.FileLookupFactory; +import org.infinispan.util.concurrent.IsolationLevel; import org.infinispan.util.logging.Log; import org.infinispan.util.logging.LogFactory; -import org.hibernate.cache.infinispan.impl.BaseRegion; -import org.hibernate.cache.infinispan.naturalid.NaturalIdRegionImpl; -import org.hibernate.cache.infinispan.util.CacheCommandFactory; -import org.hibernate.cache.spi.AbstractRegionFactory; -import org.hibernate.cache.spi.CacheDataDescription; -import org.hibernate.cache.CacheException; -import org.hibernate.cache.infinispan.collection.CollectionRegionImpl; -import org.hibernate.cache.infinispan.entity.EntityRegionImpl; -import org.hibernate.cache.infinispan.query.QueryResultsRegionImpl; -import org.hibernate.cache.infinispan.timestamp.TimestampTypeOverrides; -import org.hibernate.cache.infinispan.timestamp.TimestampsRegionImpl; -import org.hibernate.cache.infinispan.tm.HibernateTransactionManagerLookup; -import org.hibernate.cache.spi.CollectionRegion; -import org.hibernate.cache.spi.EntityRegion; -import org.hibernate.cache.spi.NaturalIdRegion; -import org.hibernate.cache.spi.QueryResultsRegion; -import org.hibernate.cache.spi.RegionFactory; -import org.hibernate.cache.spi.TimestampsRegion; -import org.hibernate.cache.spi.access.AccessType; -import org.hibernate.cfg.Settings; -import org.hibernate.engine.config.spi.ConfigurationService; -import org.hibernate.internal.util.config.ConfigurationHelper; -import org.hibernate.service.ServiceRegistry; -import org.hibernate.internal.util.ClassLoaderHelper; - /** * A {@link RegionFactory} for Infinispan-backed cache * regions. @@ -396,10 +394,10 @@ public class InfinispanRegionFactory extends AbstractRegionFactory { try { String configLoc = ConfigurationHelper.getString( INFINISPAN_CONFIG_RESOURCE_PROP, properties, DEF_INFINISPAN_CONFIG_RESOURCE); - ClassLoader classLoader = ClassLoaderHelper.getContextClassLoader(); + ClassLoaderService classLoaderService = getServiceRegistry().getService( ClassLoaderService.class ); InputStream is = FileLookupFactory.newInstance().lookupFileStrict( - configLoc, classLoader); - ParserRegistry parserRegistry = new ParserRegistry(classLoader); + configLoc, classLoaderService.getAggregatedClassLoader()); + ParserRegistry parserRegistry = new ParserRegistry(classLoaderService.getAggregatedClassLoader()); ConfigurationBuilderHolder holder = parserRegistry.parse(is); // Override global jmx statistics exposure diff --git a/hibernate-osgi/src/main/java/org/hibernate/osgi/HibernateBundleActivator.java b/hibernate-osgi/src/main/java/org/hibernate/osgi/HibernateBundleActivator.java index 022fd938dd..bc25a00255 100644 --- a/hibernate-osgi/src/main/java/org/hibernate/osgi/HibernateBundleActivator.java +++ b/hibernate-osgi/src/main/java/org/hibernate/osgi/HibernateBundleActivator.java @@ -72,6 +72,8 @@ public class HibernateBundleActivator implements BundleActivator { final OsgiClassLoader osgiClassLoader = new OsgiClassLoader(); osgiClassLoader.addBundle( FrameworkUtil.getBundle( Session.class ) ); osgiClassLoader.addBundle( FrameworkUtil.getBundle( HibernatePersistenceProvider.class ) ); + // TODO: Completely temporary until .cfg & .mapping are removed/repurposed. Once static CL checks are gone + // (and we 100% rely on ClassLoaderService), remove. ClassLoaderHelper.overridenClassLoader = osgiClassLoader; // Build a JtaPlatform specific for this OSGi context diff --git a/hibernate-proxool/src/main/java/org/hibernate/proxool/internal/ProxoolConnectionProvider.java b/hibernate-proxool/src/main/java/org/hibernate/proxool/internal/ProxoolConnectionProvider.java index bb47c7a9c4..790cef2b42 100644 --- a/hibernate-proxool/src/main/java/org/hibernate/proxool/internal/ProxoolConnectionProvider.java +++ b/hibernate-proxool/src/main/java/org/hibernate/proxool/internal/ProxoolConnectionProvider.java @@ -28,14 +28,8 @@ import java.sql.DriverManager; import java.sql.SQLException; import java.util.Map; -import org.logicalcobwebs.proxool.ProxoolException; -import org.logicalcobwebs.proxool.ProxoolFacade; -import org.logicalcobwebs.proxool.configuration.JAXPConfigurator; -import org.logicalcobwebs.proxool.configuration.PropertyConfigurator; - -import org.jboss.logging.Logger; - import org.hibernate.HibernateException; +import org.hibernate.boot.registry.classloading.spi.ClassLoaderService; import org.hibernate.cfg.Environment; import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider; import org.hibernate.internal.util.ConfigHelper; @@ -43,7 +37,14 @@ import org.hibernate.internal.util.StringHelper; import org.hibernate.internal.util.config.ConfigurationHelper; import org.hibernate.service.UnknownUnwrapTypeException; import org.hibernate.service.spi.Configurable; +import org.hibernate.service.spi.ServiceRegistryAwareService; +import org.hibernate.service.spi.ServiceRegistryImplementor; import org.hibernate.service.spi.Stoppable; +import org.jboss.logging.Logger; +import org.logicalcobwebs.proxool.ProxoolException; +import org.logicalcobwebs.proxool.ProxoolFacade; +import org.logicalcobwebs.proxool.configuration.JAXPConfigurator; +import org.logicalcobwebs.proxool.configuration.PropertyConfigurator; /** * A connection provider that uses a Proxool connection pool. Hibernate will use this by @@ -51,7 +52,7 @@ import org.hibernate.service.spi.Stoppable; * * @see ConnectionProvider */ -public class ProxoolConnectionProvider implements ConnectionProvider, Configurable, Stoppable { +public class ProxoolConnectionProvider implements ConnectionProvider, Configurable, Stoppable, ServiceRegistryAwareService { private static final ProxoolMessageLogger LOG = Logger.getMessageLogger( ProxoolMessageLogger.class, ProxoolConnectionProvider.class.getName() @@ -69,6 +70,8 @@ public class ProxoolConnectionProvider implements ConnectionProvider, Configurab private Integer isolation; private boolean autocommit; + + private ServiceRegistryImplementor serviceRegistry; @Override public Connection getConnection() throws SQLException { @@ -114,6 +117,8 @@ public class ProxoolConnectionProvider implements ConnectionProvider, Configurab @Override public void configure(Map props) { + final ClassLoaderService classLoaderService = serviceRegistry.getService( ClassLoaderService.class ); + // Get the configurator files (if available) final String jaxpFile = (String) props.get( Environment.PROXOOL_XML ); final String propFile = (String) props.get( Environment.PROXOOL_PROPERTIES ); @@ -152,7 +157,7 @@ public class ProxoolConnectionProvider implements ConnectionProvider, Configurab } try { - JAXPConfigurator.configure( ConfigHelper.getConfigStreamReader( jaxpFile ), false ); + JAXPConfigurator.configure( ConfigHelper.getConfigStreamReader( jaxpFile, classLoaderService ), false ); } catch (ProxoolException e) { final String msg = LOG.unableToLoadJaxpConfiguratorFile( jaxpFile ); @@ -177,7 +182,7 @@ public class ProxoolConnectionProvider implements ConnectionProvider, Configurab } try { - PropertyConfigurator.configure( ConfigHelper.getConfigProperties( propFile ) ); + PropertyConfigurator.configure( ConfigHelper.getConfigProperties( propFile, classLoaderService ) ); } catch (ProxoolException e) { final String msg = LOG.unableToLoadPropertyConfiguratorFile( propFile ); @@ -243,4 +248,9 @@ public class ProxoolConnectionProvider implements ConnectionProvider, Configurab stop(); } + @Override + public void injectServices(ServiceRegistryImplementor serviceRegistry) { + this.serviceRegistry = serviceRegistry; + } + }