mirror of
https://github.com/hibernate/hibernate-orm
synced 2025-02-08 12:14:47 +00:00
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.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.LinkedHashSet;
|
import java.util.LinkedHashSet;
|
||||||
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.ServiceLoader;
|
import java.util.ServiceLoader;
|
||||||
@ -52,6 +53,7 @@ public class ClassLoaderServiceImpl implements ClassLoaderService {
|
|||||||
private static final Logger log = Logger.getLogger( ClassLoaderServiceImpl.class );
|
private static final Logger log = Logger.getLogger( ClassLoaderServiceImpl.class );
|
||||||
|
|
||||||
private final ClassLoader aggregatedClassLoader;
|
private final ClassLoader aggregatedClassLoader;
|
||||||
|
private final LinkedList<ServiceLoader> loaders = new LinkedList<ServiceLoader>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a ClassLoaderServiceImpl with standard set-up
|
* Constructs a ClassLoaderServiceImpl with standard set-up
|
||||||
@ -318,15 +320,23 @@ public List<URL> locateResources(String name) {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <S> LinkedHashSet<S> loadJavaServices(Class<S> serviceContract) {
|
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>();
|
final LinkedHashSet<S> services = new LinkedHashSet<S>();
|
||||||
for ( S service : loader ) {
|
for ( S service : serviceLoader) {
|
||||||
services.add( service );
|
services.add( service );
|
||||||
}
|
}
|
||||||
|
loaders.add(serviceLoader);
|
||||||
return services;
|
return services;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void stop() {
|
||||||
|
while (!loaders.isEmpty()){
|
||||||
|
ServiceLoader loader = loaders.removeLast();
|
||||||
|
loader.reload();//clear service loader providers
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||||
// completely temporary !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
// completely temporary !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||||
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||||
|
@ -29,13 +29,14 @@
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.hibernate.service.Service;
|
import org.hibernate.service.Service;
|
||||||
|
import org.hibernate.service.spi.Stoppable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A service for interacting with class loaders.
|
* A service for interacting with class loaders.
|
||||||
*
|
*
|
||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
*/
|
*/
|
||||||
public interface ClassLoaderService extends Service {
|
public interface ClassLoaderService extends Service, Stoppable {
|
||||||
/**
|
/**
|
||||||
* Locate a class by name.
|
* Locate a class by name.
|
||||||
*
|
*
|
||||||
|
@ -300,6 +300,7 @@ public void sessionFactoryClosed(SessionFactory factory) {
|
|||||||
for ( Integrator integrator : integrators ) {
|
for ( Integrator integrator : integrators ) {
|
||||||
integrator.disintegrate( SessionFactoryImpl.this, SessionFactoryImpl.this.serviceRegistry );
|
integrator.disintegrate( SessionFactoryImpl.this, SessionFactoryImpl.this.serviceRegistry );
|
||||||
}
|
}
|
||||||
|
integrators.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -736,6 +737,7 @@ public void sessionFactoryClosed(SessionFactory factory) {
|
|||||||
for ( Integrator integrator : integrators ) {
|
for ( Integrator integrator : integrators ) {
|
||||||
integrator.disintegrate( SessionFactoryImpl.this, SessionFactoryImpl.this.serviceRegistry );
|
integrator.disintegrate( SessionFactoryImpl.this, SessionFactoryImpl.this.serviceRegistry );
|
||||||
}
|
}
|
||||||
|
integrators.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,18 +78,7 @@ public class JpaIntegrator implements Integrator {
|
|||||||
private CallbackProcessor callbackProcessor;
|
private CallbackProcessor callbackProcessor;
|
||||||
private CallbackRegistryImpl callbackRegistry;
|
private CallbackRegistryImpl callbackRegistry;
|
||||||
|
|
||||||
private static final DuplicationStrategy JPA_DUPLICATION_STRATEGY = new DuplicationStrategy() {
|
private static final DuplicationStrategy JPA_DUPLICATION_STRATEGY = new JPADuplicationStrategy();
|
||||||
@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;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@SuppressWarnings( {"unchecked"})
|
@SuppressWarnings( {"unchecked"})
|
||||||
@ -100,18 +89,7 @@ public void integrate(
|
|||||||
// first, register the JPA-specific persist cascade style
|
// first, register the JPA-specific persist cascade style
|
||||||
CascadeStyles.registerCascadeStyle(
|
CascadeStyles.registerCascadeStyle(
|
||||||
"persist",
|
"persist",
|
||||||
new CascadeStyles.BaseCascadeStyle() {
|
new PersistCascadeStyle()
|
||||||
@Override
|
|
||||||
public boolean doCascade(CascadingAction action) {
|
|
||||||
return action == JpaPersistEventListener.PERSIST_SKIPLAZY
|
|
||||||
|| action == CascadingActions.PERSIST_ON_FLUSH;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "STYLE_PERSIST_SKIPLAZY";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
@ -220,18 +198,7 @@ public void integrate(
|
|||||||
// first, register the JPA-specific persist cascade style
|
// first, register the JPA-specific persist cascade style
|
||||||
CascadeStyles.registerCascadeStyle(
|
CascadeStyles.registerCascadeStyle(
|
||||||
"persist",
|
"persist",
|
||||||
new CascadeStyles.BaseCascadeStyle() {
|
new PersistCascadeStyle()
|
||||||
@Override
|
|
||||||
public boolean doCascade(CascadingAction action) {
|
|
||||||
return action == JpaPersistEventListener.PERSIST_SKIPLAZY
|
|
||||||
|| action == CascadingActions.PERSIST_ON_FLUSH;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "STYLE_PERSIST_SKIPLAZY";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
);
|
||||||
|
|
||||||
// then prepare listeners
|
// then prepare listeners
|
||||||
@ -316,4 +283,30 @@ private Object instantiate(String listenerImpl, ServiceRegistryImplementor servi
|
|||||||
throw new HibernateException( "Could not instantiate requested listener [" + listenerImpl + "]", e );
|
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…
x
Reference in New Issue
Block a user