HHH-8010 Moved OsgiClassLoader handling into
BootstrapServiceRegistryBuilder
This commit is contained in:
parent
394458f6a6
commit
7f52b476c9
|
@ -24,17 +24,20 @@
|
||||||
package org.hibernate.boot.registry;
|
package org.hibernate.boot.registry;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.LinkedHashSet;
|
import java.util.LinkedHashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl;
|
||||||
|
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
|
||||||
import org.hibernate.boot.registry.internal.BootstrapServiceRegistryImpl;
|
import org.hibernate.boot.registry.internal.BootstrapServiceRegistryImpl;
|
||||||
import org.hibernate.boot.registry.selector.Availability;
|
import org.hibernate.boot.registry.selector.Availability;
|
||||||
import org.hibernate.boot.registry.selector.AvailabilityAnnouncer;
|
import org.hibernate.boot.registry.selector.AvailabilityAnnouncer;
|
||||||
|
import org.hibernate.boot.registry.selector.internal.StrategySelectorBuilder;
|
||||||
import org.hibernate.integrator.internal.IntegratorServiceImpl;
|
import org.hibernate.integrator.internal.IntegratorServiceImpl;
|
||||||
import org.hibernate.integrator.spi.Integrator;
|
import org.hibernate.integrator.spi.Integrator;
|
||||||
import org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl;
|
import org.hibernate.internal.util.ClassLoaderHelper;
|
||||||
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
|
|
||||||
import org.hibernate.boot.registry.selector.internal.StrategySelectorBuilder;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Builder for bootstrap {@link org.hibernate.service.ServiceRegistry} instances.
|
* Builder for bootstrap {@link org.hibernate.service.ServiceRegistry} instances.
|
||||||
|
@ -189,7 +192,18 @@ public class BootstrapServiceRegistryBuilder {
|
||||||
public BootstrapServiceRegistry build() {
|
public BootstrapServiceRegistry build() {
|
||||||
final ClassLoaderService classLoaderService;
|
final ClassLoaderService classLoaderService;
|
||||||
if ( providedClassLoaderService == null ) {
|
if ( providedClassLoaderService == null ) {
|
||||||
classLoaderService = new ClassLoaderServiceImpl( providedClassLoaders );
|
// Use a set. As an example, in JPA, OsgiClassLoader may be in both
|
||||||
|
// the providedClassLoaders and the overridenClassLoader.
|
||||||
|
final Set<ClassLoader> classLoaders = new HashSet<ClassLoader>();
|
||||||
|
|
||||||
|
if ( providedClassLoaders != null ) {
|
||||||
|
classLoaders.addAll( providedClassLoaders );
|
||||||
|
}
|
||||||
|
if ( ClassLoaderHelper.overridenClassLoader != null ) {
|
||||||
|
classLoaders.add( ClassLoaderHelper.overridenClassLoader );
|
||||||
|
}
|
||||||
|
|
||||||
|
classLoaderService = new ClassLoaderServiceImpl( classLoaders );
|
||||||
} else {
|
} else {
|
||||||
classLoaderService = providedClassLoaderService;
|
classLoaderService = providedClassLoaderService;
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,7 +40,6 @@ import java.util.ServiceLoader;
|
||||||
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
|
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
|
||||||
import org.hibernate.boot.registry.classloading.spi.ClassLoadingException;
|
import org.hibernate.boot.registry.classloading.spi.ClassLoadingException;
|
||||||
import org.hibernate.cfg.AvailableSettings;
|
import org.hibernate.cfg.AvailableSettings;
|
||||||
import org.hibernate.internal.util.ClassLoaderHelper;
|
|
||||||
import org.jboss.logging.Logger;
|
import org.jboss.logging.Logger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -61,7 +60,7 @@ public class ClassLoaderServiceImpl implements ClassLoaderService {
|
||||||
this( Collections.singletonList( classLoader ) );
|
this( Collections.singletonList( classLoader ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
public ClassLoaderServiceImpl(List<ClassLoader> providedClassLoaders) {
|
public ClassLoaderServiceImpl(Collection<ClassLoader> providedClassLoaders) {
|
||||||
final LinkedHashSet<ClassLoader> orderedClassLoaderSet = new LinkedHashSet<ClassLoader>();
|
final LinkedHashSet<ClassLoader> orderedClassLoaderSet = new LinkedHashSet<ClassLoader>();
|
||||||
|
|
||||||
// first add all provided class loaders, if any
|
// first add all provided class loaders, if any
|
||||||
|
@ -74,14 +73,7 @@ public class ClassLoaderServiceImpl implements ClassLoaderService {
|
||||||
}
|
}
|
||||||
|
|
||||||
// normalize adding known class-loaders...
|
// normalize adding known class-loaders...
|
||||||
// first, the "overridden" classloader provided by an environment (OSGi, etc.)
|
// first, the Hibernate class loader
|
||||||
// TODO: This should probably be wired into BootstrapServiceRegistryBuilder
|
|
||||||
// instead, however that wasn't available in 4.2. Once JPA 2.1 is testable
|
|
||||||
// in an OSGi container, move this and re-work.
|
|
||||||
if ( ClassLoaderHelper.overridenClassLoader != null ) {
|
|
||||||
orderedClassLoaderSet.add( ClassLoaderHelper.overridenClassLoader );
|
|
||||||
}
|
|
||||||
// then the Hibernate class loader
|
|
||||||
orderedClassLoaderSet.add( ClassLoaderServiceImpl.class.getClassLoader() );
|
orderedClassLoaderSet.add( ClassLoaderServiceImpl.class.getClassLoader() );
|
||||||
// then the TCCL, if one...
|
// then the TCCL, if one...
|
||||||
final ClassLoader tccl = locateTCCL();
|
final ClassLoader tccl = locateTCCL();
|
||||||
|
|
Loading…
Reference in New Issue