HHH-8378 Cleanup during Bundle#stop. Added shutdown unit test.
Conflicts: hibernate-osgi/src/main/java/org/hibernate/osgi/HibernateBundleActivator.java hibernate-osgi/src/test/java/org/hibernate/osgi/test/OsgiTestCase.java
This commit is contained in:
parent
2cd2c3955f
commit
acafe63ead
|
@ -35,6 +35,7 @@ import org.hibernate.internal.util.ClassLoaderHelper;
|
|||
import org.osgi.framework.BundleActivator;
|
||||
import org.osgi.framework.BundleContext;
|
||||
import org.osgi.framework.FrameworkUtil;
|
||||
import org.osgi.framework.ServiceRegistration;
|
||||
|
||||
/**
|
||||
* This BundleActivator provides three different uses of Hibernate in OSGi
|
||||
|
@ -59,33 +60,37 @@ import org.osgi.framework.FrameworkUtil;
|
|||
*/
|
||||
public class HibernateBundleActivator implements BundleActivator {
|
||||
|
||||
private OsgiClassLoader osgiClassLoader;
|
||||
|
||||
private OsgiJtaPlatform osgiJtaPlatform;
|
||||
private ServiceRegistration<?> persistenceProviderService;
|
||||
private ServiceRegistration<?> sessionFactoryService;
|
||||
|
||||
@Override
|
||||
public void start(BundleContext context) throws Exception {
|
||||
|
||||
osgiClassLoader = new OsgiClassLoader();
|
||||
OsgiClassLoader osgiClassLoader = new OsgiClassLoader();
|
||||
osgiClassLoader.addBundle( FrameworkUtil.getBundle( Session.class ) );
|
||||
osgiClassLoader.addBundle( FrameworkUtil.getBundle( HibernatePersistence.class ) );
|
||||
ClassLoaderHelper.overridenClassLoader = osgiClassLoader;
|
||||
|
||||
osgiJtaPlatform = new OsgiJtaPlatform( context );
|
||||
OsgiJtaPlatform osgiJtaPlatform = new OsgiJtaPlatform( context );
|
||||
|
||||
Dictionary properties = new Hashtable();
|
||||
// In order to support existing persistence.xml files, register
|
||||
// using the legacy provider name.
|
||||
properties.put( "javax.persistence.provider", HibernatePersistence.class.getName() );
|
||||
context.registerService( PersistenceProvider.class.getName(),
|
||||
persistenceProviderService = context.registerService( PersistenceProvider.class.getName(),
|
||||
new OsgiPersistenceProviderService( osgiClassLoader, osgiJtaPlatform, context ), properties );
|
||||
|
||||
context.registerService( SessionFactory.class.getName(),
|
||||
sessionFactoryService = context.registerService( SessionFactory.class.getName(),
|
||||
new OsgiSessionFactoryService( osgiClassLoader, osgiJtaPlatform, context ), new Hashtable());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop(BundleContext context) throws Exception {
|
||||
// Nothing else to do?
|
||||
persistenceProviderService.unregister();
|
||||
persistenceProviderService = null;
|
||||
sessionFactoryService.unregister();
|
||||
sessionFactoryService = null;
|
||||
|
||||
ClassLoaderHelper.overridenClassLoader = null;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue