HHH-8118 Updated CL use in entitymanager and services
This commit is contained in:
parent
84ebec72d3
commit
5143caf303
|
@ -326,6 +326,11 @@ public class ClassLoaderServiceImpl implements ClassLoaderService {
|
||||||
return services;
|
return services;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ClassLoader getAggregatedClassLoader() {
|
||||||
|
return aggregatedClassLoader;
|
||||||
|
}
|
||||||
|
|
||||||
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||||
// completely temporary !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
// completely temporary !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||||
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||||
|
|
|
@ -87,4 +87,11 @@ public interface ClassLoaderService extends Service {
|
||||||
* @return The ordered set of discovered services.
|
* @return The ordered set of discovered services.
|
||||||
*/
|
*/
|
||||||
public <S> LinkedHashSet<S> loadJavaServices(Class<S> serviceContract);
|
public <S> LinkedHashSet<S> loadJavaServices(Class<S> serviceContract);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Some 3rd party libraries take ClassLoaders as arguments. Support using the aggregated ClassLoader.
|
||||||
|
*
|
||||||
|
* @return The aggregated ClassLoader
|
||||||
|
*/
|
||||||
|
public ClassLoader getAggregatedClassLoader();
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,6 +32,7 @@ import java.net.URL;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
import org.hibernate.HibernateException;
|
import org.hibernate.HibernateException;
|
||||||
|
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
|
||||||
import org.hibernate.cfg.Environment;
|
import org.hibernate.cfg.Environment;
|
||||||
import org.hibernate.internal.CoreMessageLogger;
|
import org.hibernate.internal.CoreMessageLogger;
|
||||||
import org.jboss.logging.Logger;
|
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
|
/** 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
|
* 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
|
* does not work, then the next attempts try to locate this URL as a java system
|
||||||
* resource.
|
* resource through {@link ClassLoaderService}.
|
||||||
*
|
*
|
||||||
* @param path The path representing the config location.
|
* @param path The path representing the config location.
|
||||||
|
* @param classLoaderService The ClassLoaderService.
|
||||||
* @return An appropriate URL or null.
|
* @return An appropriate URL or null.
|
||||||
*/
|
*/
|
||||||
public static URL locateConfig(final String path) {
|
public static URL locateConfig(final String path, final ClassLoaderService classLoaderService) {
|
||||||
try {
|
try {
|
||||||
return new URL(path);
|
return new URL(path);
|
||||||
}
|
}
|
||||||
catch(MalformedURLException e) {
|
catch(MalformedURLException e) {
|
||||||
return findAsResource(path);
|
return classLoaderService.locateResource( path );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Try to locate a local URL representing the incoming path.
|
|
||||||
* This method <b>only</b> 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
|
/** 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.
|
* 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.
|
* {@link java.net.URL#openStream()} is then called to obtain the stream.
|
||||||
*
|
*
|
||||||
* @param path The path representing the config location.
|
* @param path The path representing the config location.
|
||||||
|
* @param classLoaderService The ClassLoaderService.
|
||||||
* @return An input stream to the requested config resource.
|
* @return An input stream to the requested config resource.
|
||||||
* @throws HibernateException Unable to open stream to that resource.
|
* @throws HibernateException Unable to open stream to that resource.
|
||||||
*/
|
*/
|
||||||
public static InputStream getConfigStream(final String path) throws HibernateException {
|
public static InputStream getConfigStream(final String path,
|
||||||
final URL url = ConfigHelper.locateConfig(path);
|
final ClassLoaderService classLoaderService) throws HibernateException {
|
||||||
|
final URL url = ConfigHelper.locateConfig(path, classLoaderService);
|
||||||
|
|
||||||
if (url == null) {
|
if (url == null) {
|
||||||
String msg = LOG.unableToLocateConfigFile(path);
|
String msg = LOG.unableToLocateConfigFile(path);
|
||||||
|
@ -128,23 +100,27 @@ public final class ConfigHelper {
|
||||||
* wrapped in a Reader.
|
* wrapped in a Reader.
|
||||||
*
|
*
|
||||||
* @param path The path representing the config location.
|
* @param path The path representing the config location.
|
||||||
|
* @param classLoaderService The ClassLoaderService.
|
||||||
* @return An input stream to the requested config resource.
|
* @return An input stream to the requested config resource.
|
||||||
* @throws HibernateException Unable to open reader to that resource.
|
* @throws HibernateException Unable to open reader to that resource.
|
||||||
*/
|
*/
|
||||||
public static Reader getConfigStreamReader(final String path) throws HibernateException {
|
public static Reader getConfigStreamReader(final String path,
|
||||||
return new InputStreamReader( getConfigStream(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.
|
/** Loads a properties instance based on the data at the incoming config location.
|
||||||
*
|
*
|
||||||
* @param path The path representing the config location.
|
* @param path The path representing the config location.
|
||||||
|
* @param classLoaderService The ClassLoaderService.
|
||||||
* @return The loaded properties instance.
|
* @return The loaded properties instance.
|
||||||
* @throws HibernateException Unable to load properties from that resource.
|
* @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 {
|
try {
|
||||||
Properties properties = new Properties();
|
Properties properties = new Properties();
|
||||||
properties.load( getConfigStream(path) );
|
properties.load( getConfigStream(path, classLoaderService) );
|
||||||
return properties;
|
return properties;
|
||||||
}
|
}
|
||||||
catch(IOException e) {
|
catch(IOException e) {
|
||||||
|
|
|
@ -40,15 +40,6 @@ import java.util.Properties;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.StringTokenizer;
|
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.AttributeConverter;
|
||||||
import javax.persistence.EntityManagerFactory;
|
import javax.persistence.EntityManagerFactory;
|
||||||
import javax.persistence.EntityNotFoundException;
|
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.id.factory.spi.MutableIdentifierGeneratorFactory;
|
||||||
import org.hibernate.integrator.spi.Integrator;
|
import org.hibernate.integrator.spi.Integrator;
|
||||||
import org.hibernate.internal.util.StringHelper;
|
import org.hibernate.internal.util.StringHelper;
|
||||||
|
import org.hibernate.internal.util.ValueHolder;
|
||||||
import org.hibernate.internal.util.collections.CollectionHelper;
|
import org.hibernate.internal.util.collections.CollectionHelper;
|
||||||
import org.hibernate.jaxb.spi.cfg.JaxbHibernateConfiguration;
|
import org.hibernate.jaxb.spi.cfg.JaxbHibernateConfiguration;
|
||||||
import org.hibernate.jaxb.spi.cfg.JaxbHibernateConfiguration.JaxbSessionFactory.JaxbMapping;
|
import org.hibernate.jaxb.spi.cfg.JaxbHibernateConfiguration.JaxbSessionFactory.JaxbMapping;
|
||||||
import org.hibernate.internal.util.ValueHolder;
|
|
||||||
import org.hibernate.jpa.AvailableSettings;
|
import org.hibernate.jpa.AvailableSettings;
|
||||||
import org.hibernate.jpa.boot.scan.internal.StandardScanOptions;
|
import org.hibernate.jpa.boot.scan.internal.StandardScanOptions;
|
||||||
import org.hibernate.jpa.boot.scan.internal.StandardScanner;
|
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.secure.spi.JaccService;
|
||||||
import org.hibernate.service.ServiceRegistry;
|
import org.hibernate.service.ServiceRegistry;
|
||||||
import org.hibernate.service.spi.ServiceRegistryImplementor;
|
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
|
* @author Steve Ebersole
|
||||||
|
@ -474,7 +473,8 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil
|
||||||
metadataSources.converterDescriptors.add(
|
metadataSources.converterDescriptors.add(
|
||||||
new MetadataSources.ConverterDescriptor(
|
new MetadataSources.ConverterDescriptor(
|
||||||
className,
|
className,
|
||||||
JandexHelper.getValue( converterAnnotation, "autoApply", boolean.class )
|
JandexHelper.getValue( converterAnnotation, "autoApply", boolean.class,
|
||||||
|
serviceRegistryBuilder.getBootstrapServiceRegistry().getService( ClassLoaderService.class ) )
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,16 @@
|
||||||
*/
|
*/
|
||||||
package org.hibernate.jpa.spi;
|
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.CacheRetrieveMode;
|
||||||
import javax.persistence.CacheStoreMode;
|
import javax.persistence.CacheStoreMode;
|
||||||
import javax.persistence.EntityExistsException;
|
import javax.persistence.EntityExistsException;
|
||||||
|
@ -57,17 +67,6 @@ import javax.persistence.spi.PersistenceUnitTransactionType;
|
||||||
import javax.transaction.Status;
|
import javax.transaction.Status;
|
||||||
import javax.transaction.SystemException;
|
import javax.transaction.SystemException;
|
||||||
import javax.transaction.TransactionManager;
|
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.AssertionFailure;
|
||||||
import org.hibernate.CacheMode;
|
import org.hibernate.CacheMode;
|
||||||
|
@ -83,12 +82,12 @@ import org.hibernate.SQLQuery;
|
||||||
import org.hibernate.Session;
|
import org.hibernate.Session;
|
||||||
import org.hibernate.StaleObjectStateException;
|
import org.hibernate.StaleObjectStateException;
|
||||||
import org.hibernate.StaleStateException;
|
import org.hibernate.StaleStateException;
|
||||||
import org.hibernate.procedure.ProcedureCall;
|
|
||||||
import org.hibernate.TransientObjectException;
|
import org.hibernate.TransientObjectException;
|
||||||
import org.hibernate.TypeMismatchException;
|
import org.hibernate.TypeMismatchException;
|
||||||
import org.hibernate.UnresolvableObjectException;
|
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.Environment;
|
||||||
import org.hibernate.cfg.NotYetImplementedException;
|
|
||||||
import org.hibernate.dialect.lock.LockingStrategyException;
|
import org.hibernate.dialect.lock.LockingStrategyException;
|
||||||
import org.hibernate.dialect.lock.OptimisticEntityLockException;
|
import org.hibernate.dialect.lock.OptimisticEntityLockException;
|
||||||
import org.hibernate.dialect.lock.PessimisticEntityLockException;
|
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.SessionFactoryImplementor;
|
||||||
import org.hibernate.engine.spi.SessionImplementor;
|
import org.hibernate.engine.spi.SessionImplementor;
|
||||||
import org.hibernate.engine.transaction.internal.jta.JtaStatusHelper;
|
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.JoinStatus;
|
||||||
import org.hibernate.engine.transaction.spi.TransactionCoordinator;
|
import org.hibernate.engine.transaction.spi.TransactionCoordinator;
|
||||||
import org.hibernate.engine.transaction.spi.TransactionImplementor;
|
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.ExceptionMapper;
|
||||||
import org.hibernate.engine.transaction.synchronization.spi.ManagedFlushChecker;
|
import org.hibernate.engine.transaction.synchronization.spi.ManagedFlushChecker;
|
||||||
import org.hibernate.engine.transaction.synchronization.spi.SynchronizationCallbackCoordinator;
|
import org.hibernate.engine.transaction.synchronization.spi.SynchronizationCallbackCoordinator;
|
||||||
import org.hibernate.internal.util.ReflectHelper;
|
|
||||||
import org.hibernate.internal.util.collections.CollectionHelper;
|
import org.hibernate.internal.util.collections.CollectionHelper;
|
||||||
import org.hibernate.jpa.AvailableSettings;
|
import org.hibernate.jpa.AvailableSettings;
|
||||||
import org.hibernate.jpa.HibernateEntityManagerFactory;
|
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.CacheModeHelper;
|
||||||
import org.hibernate.jpa.internal.util.ConfigurationHelper;
|
import org.hibernate.jpa.internal.util.ConfigurationHelper;
|
||||||
import org.hibernate.jpa.internal.util.LockModeTypeHelper;
|
import org.hibernate.jpa.internal.util.LockModeTypeHelper;
|
||||||
|
import org.hibernate.procedure.ProcedureCall;
|
||||||
import org.hibernate.procedure.ProcedureCallMemento;
|
import org.hibernate.procedure.ProcedureCallMemento;
|
||||||
import org.hibernate.proxy.HibernateProxy;
|
import org.hibernate.proxy.HibernateProxy;
|
||||||
import org.hibernate.engine.transaction.jta.platform.spi.JtaPlatform;
|
|
||||||
import org.hibernate.transform.BasicTransformerAdapter;
|
import org.hibernate.transform.BasicTransformerAdapter;
|
||||||
import org.hibernate.type.Type;
|
import org.hibernate.type.Type;
|
||||||
|
import org.jboss.logging.Logger;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -756,9 +756,10 @@ public abstract class AbstractEntityManagerImpl implements HibernateEntityManage
|
||||||
if ( nativeSQLQueryReturn instanceof NativeSQLQueryRootReturn ) {
|
if ( nativeSQLQueryReturn instanceof NativeSQLQueryRootReturn ) {
|
||||||
final String entityClassName = ( ( NativeSQLQueryRootReturn ) nativeSQLQueryReturn ).getReturnEntityName();
|
final String entityClassName = ( ( NativeSQLQueryRootReturn ) nativeSQLQueryReturn ).getReturnEntityName();
|
||||||
try {
|
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 );
|
throw new AssertionFailure( "Unable to instantiate class declared on named native query: " + name + " " + entityClassName );
|
||||||
}
|
}
|
||||||
if ( !resultClass.isAssignableFrom( actualReturnedClass ) ) {
|
if ( !resultClass.isAssignableFrom( actualReturnedClass ) ) {
|
||||||
|
|
|
@ -23,19 +23,28 @@
|
||||||
*/
|
*/
|
||||||
package org.hibernate.jpa.test.packaging;
|
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.io.File;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
import javax.persistence.EntityManager;
|
import javax.persistence.EntityManager;
|
||||||
import javax.persistence.EntityManagerFactory;
|
import javax.persistence.EntityManagerFactory;
|
||||||
import javax.persistence.Persistence;
|
import javax.persistence.Persistence;
|
||||||
import javax.persistence.PersistenceException;
|
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.AvailableSettings;
|
||||||
import org.hibernate.ejb.HibernateEntityManagerFactory;
|
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.Distributor;
|
||||||
import org.hibernate.jpa.test.Item;
|
import org.hibernate.jpa.test.Item;
|
||||||
import org.hibernate.jpa.test.pack.cfgxmlpar.Morito;
|
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.externaljar.Scooter;
|
||||||
import org.hibernate.jpa.test.pack.various.Airplane;
|
import org.hibernate.jpa.test.pack.various.Airplane;
|
||||||
import org.hibernate.jpa.test.pack.various.Seat;
|
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.stat.Statistics;
|
||||||
import org.hibernate.testing.FailureExpectedWithNewMetamodel;
|
import org.hibernate.testing.FailureExpectedWithNewMetamodel;
|
||||||
|
import org.junit.Test;
|
||||||
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;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* In this test we verify that it is possible to bootstrap Hibernate/JPA from
|
* 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();
|
HashMap properties = new HashMap();
|
||||||
properties.put( AvailableSettings.JTA_DATASOURCE, null );
|
properties.put( AvailableSettings.JTA_DATASOURCE, null );
|
||||||
Properties p = new Properties();
|
Properties p = new Properties();
|
||||||
p.load( ConfigHelper.getResourceAsStream( "/overridenpar.properties" ) );
|
p.load( serviceRegistry().getService( ClassLoaderService.class ).locateResourceStream(
|
||||||
|
"/overridenpar.properties" ) );
|
||||||
properties.putAll( p );
|
properties.putAll( p );
|
||||||
EntityManagerFactory emf = Persistence.createEntityManagerFactory( "overridenpar", properties );
|
EntityManagerFactory emf = Persistence.createEntityManagerFactory( "overridenpar", properties );
|
||||||
EntityManager em = emf.createEntityManager();
|
EntityManager em = emf.createEntityManager();
|
||||||
|
|
|
@ -105,10 +105,10 @@ public class AuditConfiguration {
|
||||||
}
|
}
|
||||||
|
|
||||||
public AuditConfiguration(Configuration cfg, ClassLoaderService classLoaderService) {
|
public AuditConfiguration(Configuration cfg, ClassLoaderService classLoaderService) {
|
||||||
// TODO: Temporarily allow Envers to continuing using
|
// TODO: Temporarily allow Envers to continuing to use hibernate-commons-annotations' for reflection and class
|
||||||
// hibernate-commons-annotations' for reflection and class loading.
|
// loading.
|
||||||
final ClassLoader tccl = Thread.currentThread().getContextClassLoader();
|
final ClassLoader tccl = Thread.currentThread().getContextClassLoader();
|
||||||
Thread.currentThread().setContextClassLoader( ClassLoaderHelper.getContextClassLoader() );
|
Thread.currentThread().setContextClassLoader( classLoaderService.getAggregatedClassLoader() );
|
||||||
|
|
||||||
final Properties properties = cfg.getProperties();
|
final Properties properties = cfg.getProperties();
|
||||||
|
|
||||||
|
|
|
@ -12,8 +12,31 @@ import java.util.Properties;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.TimeUnit;
|
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.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.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.AdvancedCache;
|
||||||
import org.infinispan.commands.module.ModuleCommandFactory;
|
import org.infinispan.commands.module.ModuleCommandFactory;
|
||||||
import org.infinispan.configuration.cache.CacheMode;
|
import org.infinispan.configuration.cache.CacheMode;
|
||||||
|
@ -26,36 +49,11 @@ import org.infinispan.manager.DefaultCacheManager;
|
||||||
import org.infinispan.manager.EmbeddedCacheManager;
|
import org.infinispan.manager.EmbeddedCacheManager;
|
||||||
import org.infinispan.transaction.TransactionMode;
|
import org.infinispan.transaction.TransactionMode;
|
||||||
import org.infinispan.transaction.lookup.GenericTransactionManagerLookup;
|
import org.infinispan.transaction.lookup.GenericTransactionManagerLookup;
|
||||||
import org.infinispan.util.concurrent.IsolationLevel;
|
|
||||||
import org.infinispan.util.FileLookupFactory;
|
import org.infinispan.util.FileLookupFactory;
|
||||||
|
import org.infinispan.util.concurrent.IsolationLevel;
|
||||||
import org.infinispan.util.logging.Log;
|
import org.infinispan.util.logging.Log;
|
||||||
import org.infinispan.util.logging.LogFactory;
|
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 <a href="http://www.jboss.org/infinispan">Infinispan</a>-backed cache
|
* A {@link RegionFactory} for <a href="http://www.jboss.org/infinispan">Infinispan</a>-backed cache
|
||||||
* regions.
|
* regions.
|
||||||
|
@ -396,10 +394,10 @@ public class InfinispanRegionFactory extends AbstractRegionFactory {
|
||||||
try {
|
try {
|
||||||
String configLoc = ConfigurationHelper.getString(
|
String configLoc = ConfigurationHelper.getString(
|
||||||
INFINISPAN_CONFIG_RESOURCE_PROP, properties, DEF_INFINISPAN_CONFIG_RESOURCE);
|
INFINISPAN_CONFIG_RESOURCE_PROP, properties, DEF_INFINISPAN_CONFIG_RESOURCE);
|
||||||
ClassLoader classLoader = ClassLoaderHelper.getContextClassLoader();
|
ClassLoaderService classLoaderService = getServiceRegistry().getService( ClassLoaderService.class );
|
||||||
InputStream is = FileLookupFactory.newInstance().lookupFileStrict(
|
InputStream is = FileLookupFactory.newInstance().lookupFileStrict(
|
||||||
configLoc, classLoader);
|
configLoc, classLoaderService.getAggregatedClassLoader());
|
||||||
ParserRegistry parserRegistry = new ParserRegistry(classLoader);
|
ParserRegistry parserRegistry = new ParserRegistry(classLoaderService.getAggregatedClassLoader());
|
||||||
ConfigurationBuilderHolder holder = parserRegistry.parse(is);
|
ConfigurationBuilderHolder holder = parserRegistry.parse(is);
|
||||||
|
|
||||||
// Override global jmx statistics exposure
|
// Override global jmx statistics exposure
|
||||||
|
|
|
@ -72,6 +72,8 @@ public class HibernateBundleActivator implements BundleActivator {
|
||||||
final OsgiClassLoader osgiClassLoader = new OsgiClassLoader();
|
final OsgiClassLoader osgiClassLoader = new OsgiClassLoader();
|
||||||
osgiClassLoader.addBundle( FrameworkUtil.getBundle( Session.class ) );
|
osgiClassLoader.addBundle( FrameworkUtil.getBundle( Session.class ) );
|
||||||
osgiClassLoader.addBundle( FrameworkUtil.getBundle( HibernatePersistenceProvider.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;
|
ClassLoaderHelper.overridenClassLoader = osgiClassLoader;
|
||||||
|
|
||||||
// Build a JtaPlatform specific for this OSGi context
|
// Build a JtaPlatform specific for this OSGi context
|
||||||
|
|
|
@ -28,14 +28,8 @@ import java.sql.DriverManager;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.Map;
|
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.HibernateException;
|
||||||
|
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
|
||||||
import org.hibernate.cfg.Environment;
|
import org.hibernate.cfg.Environment;
|
||||||
import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider;
|
import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider;
|
||||||
import org.hibernate.internal.util.ConfigHelper;
|
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.internal.util.config.ConfigurationHelper;
|
||||||
import org.hibernate.service.UnknownUnwrapTypeException;
|
import org.hibernate.service.UnknownUnwrapTypeException;
|
||||||
import org.hibernate.service.spi.Configurable;
|
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.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
|
* 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
|
* @see ConnectionProvider
|
||||||
*/
|
*/
|
||||||
public class ProxoolConnectionProvider implements ConnectionProvider, Configurable, Stoppable {
|
public class ProxoolConnectionProvider implements ConnectionProvider, Configurable, Stoppable, ServiceRegistryAwareService {
|
||||||
private static final ProxoolMessageLogger LOG = Logger.getMessageLogger(
|
private static final ProxoolMessageLogger LOG = Logger.getMessageLogger(
|
||||||
ProxoolMessageLogger.class,
|
ProxoolMessageLogger.class,
|
||||||
ProxoolConnectionProvider.class.getName()
|
ProxoolConnectionProvider.class.getName()
|
||||||
|
@ -70,6 +71,8 @@ public class ProxoolConnectionProvider implements ConnectionProvider, Configurab
|
||||||
|
|
||||||
private boolean autocommit;
|
private boolean autocommit;
|
||||||
|
|
||||||
|
private ServiceRegistryImplementor serviceRegistry;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Connection getConnection() throws SQLException {
|
public Connection getConnection() throws SQLException {
|
||||||
// get a connection from the pool (thru DriverManager, cfr. Proxool doc)
|
// get a connection from the pool (thru DriverManager, cfr. Proxool doc)
|
||||||
|
@ -114,6 +117,8 @@ public class ProxoolConnectionProvider implements ConnectionProvider, Configurab
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void configure(Map props) {
|
public void configure(Map props) {
|
||||||
|
final ClassLoaderService classLoaderService = serviceRegistry.getService( ClassLoaderService.class );
|
||||||
|
|
||||||
// Get the configurator files (if available)
|
// Get the configurator files (if available)
|
||||||
final String jaxpFile = (String) props.get( Environment.PROXOOL_XML );
|
final String jaxpFile = (String) props.get( Environment.PROXOOL_XML );
|
||||||
final String propFile = (String) props.get( Environment.PROXOOL_PROPERTIES );
|
final String propFile = (String) props.get( Environment.PROXOOL_PROPERTIES );
|
||||||
|
@ -152,7 +157,7 @@ public class ProxoolConnectionProvider implements ConnectionProvider, Configurab
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
JAXPConfigurator.configure( ConfigHelper.getConfigStreamReader( jaxpFile ), false );
|
JAXPConfigurator.configure( ConfigHelper.getConfigStreamReader( jaxpFile, classLoaderService ), false );
|
||||||
}
|
}
|
||||||
catch (ProxoolException e) {
|
catch (ProxoolException e) {
|
||||||
final String msg = LOG.unableToLoadJaxpConfiguratorFile( jaxpFile );
|
final String msg = LOG.unableToLoadJaxpConfiguratorFile( jaxpFile );
|
||||||
|
@ -177,7 +182,7 @@ public class ProxoolConnectionProvider implements ConnectionProvider, Configurab
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
PropertyConfigurator.configure( ConfigHelper.getConfigProperties( propFile ) );
|
PropertyConfigurator.configure( ConfigHelper.getConfigProperties( propFile, classLoaderService ) );
|
||||||
}
|
}
|
||||||
catch (ProxoolException e) {
|
catch (ProxoolException e) {
|
||||||
final String msg = LOG.unableToLoadPropertyConfiguratorFile( propFile );
|
final String msg = LOG.unableToLoadPropertyConfiguratorFile( propFile );
|
||||||
|
@ -243,4 +248,9 @@ public class ProxoolConnectionProvider implements ConnectionProvider, Configurab
|
||||||
stop();
|
stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void injectServices(ServiceRegistryImplementor serviceRegistry) {
|
||||||
|
this.serviceRegistry = serviceRegistry;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue