HHH-8363 ClassLoaderServiceImpl should be defined as Stoppable
- also fix problem with JpaIntegrator holding references to beanmanager
This commit is contained in:
parent
8a0d301ba5
commit
5011b4a30e
|
@ -33,6 +33,7 @@ import java.util.Enumeration;
|
|||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.ServiceLoader;
|
||||
|
@ -52,6 +53,7 @@ public class ClassLoaderServiceImpl implements ClassLoaderService {
|
|||
private static final Logger log = Logger.getLogger( ClassLoaderServiceImpl.class );
|
||||
|
||||
private final ClassLoader aggregatedClassLoader;
|
||||
private final LinkedList<ServiceLoader> loaders = new LinkedList<ServiceLoader>();
|
||||
|
||||
/**
|
||||
* Constructs a ClassLoaderServiceImpl with standard set-up
|
||||
|
@ -318,15 +320,23 @@ public class ClassLoaderServiceImpl implements ClassLoaderService {
|
|||
|
||||
@Override
|
||||
public <S> LinkedHashSet<S> loadJavaServices(Class<S> serviceContract) {
|
||||
final ServiceLoader<S> loader = ServiceLoader.load( serviceContract, aggregatedClassLoader );
|
||||
ServiceLoader<S> serviceLoader = ServiceLoader.load( serviceContract, aggregatedClassLoader );
|
||||
final LinkedHashSet<S> services = new LinkedHashSet<S>();
|
||||
for ( S service : loader ) {
|
||||
for ( S service : serviceLoader) {
|
||||
services.add( service );
|
||||
}
|
||||
|
||||
loaders.add(serviceLoader);
|
||||
return services;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop() {
|
||||
while (!loaders.isEmpty()){
|
||||
ServiceLoader loader = loaders.removeLast();
|
||||
loader.reload();//clear service loader providers
|
||||
}
|
||||
}
|
||||
|
||||
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
// completely temporary !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
|
|
|
@ -29,13 +29,14 @@ import java.util.LinkedHashSet;
|
|||
import java.util.List;
|
||||
|
||||
import org.hibernate.service.Service;
|
||||
import org.hibernate.service.spi.Stoppable;
|
||||
|
||||
/**
|
||||
* A service for interacting with class loaders.
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public interface ClassLoaderService extends Service {
|
||||
public interface ClassLoaderService extends Service, Stoppable {
|
||||
/**
|
||||
* Locate a class by name.
|
||||
*
|
||||
|
|
|
@ -300,6 +300,7 @@ public final class SessionFactoryImpl
|
|||
for ( Integrator integrator : integrators ) {
|
||||
integrator.disintegrate( SessionFactoryImpl.this, SessionFactoryImpl.this.serviceRegistry );
|
||||
}
|
||||
integrators.clear();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -736,6 +737,7 @@ public final class SessionFactoryImpl
|
|||
for ( Integrator integrator : integrators ) {
|
||||
integrator.disintegrate( SessionFactoryImpl.this, SessionFactoryImpl.this.serviceRegistry );
|
||||
}
|
||||
integrators.clear();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -78,18 +78,7 @@ public class JpaIntegrator implements Integrator {
|
|||
private CallbackProcessor callbackProcessor;
|
||||
private CallbackRegistryImpl callbackRegistry;
|
||||
|
||||
private static final DuplicationStrategy JPA_DUPLICATION_STRATEGY = new DuplicationStrategy() {
|
||||
@Override
|
||||
public boolean areMatch(Object listener, Object original) {
|
||||
return listener.getClass().equals( original.getClass() ) &&
|
||||
HibernateEntityManagerEventListener.class.isInstance( original );
|
||||
}
|
||||
|
||||
@Override
|
||||
public Action getAction() {
|
||||
return Action.KEEP_ORIGINAL;
|
||||
}
|
||||
};
|
||||
private static final DuplicationStrategy JPA_DUPLICATION_STRATEGY = new JPADuplicationStrategy();
|
||||
|
||||
@Override
|
||||
@SuppressWarnings( {"unchecked"})
|
||||
|
@ -100,18 +89,7 @@ public class JpaIntegrator implements Integrator {
|
|||
// first, register the JPA-specific persist cascade style
|
||||
CascadeStyles.registerCascadeStyle(
|
||||
"persist",
|
||||
new CascadeStyles.BaseCascadeStyle() {
|
||||
@Override
|
||||
public boolean doCascade(CascadingAction action) {
|
||||
return action == JpaPersistEventListener.PERSIST_SKIPLAZY
|
||||
|| action == CascadingActions.PERSIST_ON_FLUSH;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "STYLE_PERSIST_SKIPLAZY";
|
||||
}
|
||||
}
|
||||
new PersistCascadeStyle()
|
||||
);
|
||||
|
||||
|
||||
|
@ -220,18 +198,7 @@ public class JpaIntegrator implements Integrator {
|
|||
// first, register the JPA-specific persist cascade style
|
||||
CascadeStyles.registerCascadeStyle(
|
||||
"persist",
|
||||
new CascadeStyles.BaseCascadeStyle() {
|
||||
@Override
|
||||
public boolean doCascade(CascadingAction action) {
|
||||
return action == JpaPersistEventListener.PERSIST_SKIPLAZY
|
||||
|| action == CascadingActions.PERSIST_ON_FLUSH;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "STYLE_PERSIST_SKIPLAZY";
|
||||
}
|
||||
}
|
||||
new PersistCascadeStyle()
|
||||
);
|
||||
|
||||
// then prepare listeners
|
||||
|
@ -316,4 +283,30 @@ public class JpaIntegrator implements Integrator {
|
|||
throw new HibernateException( "Could not instantiate requested listener [" + listenerImpl + "]", e );
|
||||
}
|
||||
}
|
||||
|
||||
private static class PersistCascadeStyle extends CascadeStyles.BaseCascadeStyle {
|
||||
@Override
|
||||
public boolean doCascade(CascadingAction action) {
|
||||
return action == JpaPersistEventListener.PERSIST_SKIPLAZY
|
||||
|| action == CascadingActions.PERSIST_ON_FLUSH;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "STYLE_PERSIST_SKIPLAZY";
|
||||
}
|
||||
}
|
||||
|
||||
private static class JPADuplicationStrategy implements DuplicationStrategy {
|
||||
@Override
|
||||
public boolean areMatch(Object listener, Object original) {
|
||||
return listener.getClass().equals( original.getClass() ) &&
|
||||
HibernateEntityManagerEventListener.class.isInstance( original );
|
||||
}
|
||||
|
||||
@Override
|
||||
public Action getAction() {
|
||||
return Action.KEEP_ORIGINAL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue