From acafe63eaddb33b98f2d1564ea8a944a31cda900 Mon Sep 17 00:00:00 2001 From: Brett Meyer Date: Wed, 24 Jul 2013 11:47:55 -0400 Subject: [PATCH] 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 --- .../osgi/HibernateBundleActivator.java | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/hibernate-osgi/src/main/java/org/hibernate/osgi/HibernateBundleActivator.java b/hibernate-osgi/src/main/java/org/hibernate/osgi/HibernateBundleActivator.java index e6614c97fe..bbe6089365 100644 --- a/hibernate-osgi/src/main/java/org/hibernate/osgi/HibernateBundleActivator.java +++ b/hibernate-osgi/src/main/java/org/hibernate/osgi/HibernateBundleActivator.java @@ -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 @@ -58,34 +59,38 @@ import org.osgi.framework.FrameworkUtil; * @author Tim Ward */ 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; } }