incubator-aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mahrw...@apache.org
Subject svn commit: r906408 - in /incubator/aries/trunk/jpa/jpa-container-context/src: main/java/org/apache/aries/jpa/container/context/ main/java/org/apache/aries/jpa/container/context/impl/ main/java/org/apache/aries/jpa/container/context/namespace/ main/jav...
Date Thu, 04 Feb 2010 09:06:11 GMT
Author: mahrwald
Date: Thu Feb  4 09:06:11 2010
New Revision: 906408

URL: http://svn.apache.org/viewvc?rev=906408&view=rev
Log:
ARIES-131 Improve cleanup

Modified:
    incubator/aries/trunk/jpa/jpa-container-context/src/main/java/org/apache/aries/jpa/container/context/GlobalPersistenceManager.java
    incubator/aries/trunk/jpa/jpa-container-context/src/main/java/org/apache/aries/jpa/container/context/impl/PersistenceContextManager.java
    incubator/aries/trunk/jpa/jpa-container-context/src/main/java/org/apache/aries/jpa/container/context/namespace/NSHandler.java
    incubator/aries/trunk/jpa/jpa-container-context/src/main/java/org/apache/aries/jpa/container/context/transaction/impl/JTAEntityManager.java
    incubator/aries/trunk/jpa/jpa-container-context/src/test/java/org/apache/aries/jpa/container/context/namespace/NSHandlerTest.java

Modified: incubator/aries/trunk/jpa/jpa-container-context/src/main/java/org/apache/aries/jpa/container/context/GlobalPersistenceManager.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/jpa/jpa-container-context/src/main/java/org/apache/aries/jpa/container/context/GlobalPersistenceManager.java?rev=906408&r1=906407&r2=906408&view=diff
==============================================================================
--- incubator/aries/trunk/jpa/jpa-container-context/src/main/java/org/apache/aries/jpa/container/context/GlobalPersistenceManager.java
(original)
+++ incubator/aries/trunk/jpa/jpa-container-context/src/main/java/org/apache/aries/jpa/container/context/GlobalPersistenceManager.java
Thu Feb  4 09:06:11 2010
@@ -88,6 +88,7 @@
       Set<String> contextsToBeRemoved = Collections.emptySet();
       Bundle frameworkBundle = bundle.getBundleContext().getBundle(0);
       PersistenceContextManager manager = null;
+      boolean removeManager = false;
       
       synchronized (this) {
         if (persistenceContexts.containsKey(bundle)) {
@@ -98,13 +99,18 @@
           if (manager == null)
             throw new IllegalStateException();
         } else if (managers.containsKey(bundle)) {
-          managers.remove(bundle);
+          removeManager = true;
+          manager = managers.remove(bundle);
           bundle.getBundleContext().removeBundleListener(this);
         }
       }
       
-      for (String context : contextsToBeRemoved) {
-        manager.unregisterContext(context, bundle);
+      if (removeManager) {
+        manager.close();
+      } else {
+        for (String context : contextsToBeRemoved) {
+          manager.unregisterContext(context, bundle);
+        }
       }
     }
   }

Modified: incubator/aries/trunk/jpa/jpa-container-context/src/main/java/org/apache/aries/jpa/container/context/impl/PersistenceContextManager.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/jpa/jpa-container-context/src/main/java/org/apache/aries/jpa/container/context/impl/PersistenceContextManager.java?rev=906408&r1=906407&r2=906408&view=diff
==============================================================================
--- incubator/aries/trunk/jpa/jpa-container-context/src/main/java/org/apache/aries/jpa/container/context/impl/PersistenceContextManager.java
(original)
+++ incubator/aries/trunk/jpa/jpa-container-context/src/main/java/org/apache/aries/jpa/container/context/impl/PersistenceContextManager.java
Thu Feb  4 09:06:11 2010
@@ -85,6 +85,18 @@
     super(ctx, filter, null);
     persistenceContextRegistry = registry;
   }
+  
+  @Override
+  public void close() {
+    super.close();
+    for (ServiceRegistration reg : entityManagerRegistrations.values()) {
+      try {
+        reg.unregister();
+      } catch (IllegalStateException ise) {
+        //This is no worry, the framework has done our job for us
+      }
+    }
+  }
 
   @Override
   public Object addingService(ServiceReference reference) {

Modified: incubator/aries/trunk/jpa/jpa-container-context/src/main/java/org/apache/aries/jpa/container/context/namespace/NSHandler.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/jpa/jpa-container-context/src/main/java/org/apache/aries/jpa/container/context/namespace/NSHandler.java?rev=906408&r1=906407&r2=906408&view=diff
==============================================================================
--- incubator/aries/trunk/jpa/jpa-container-context/src/main/java/org/apache/aries/jpa/container/context/namespace/NSHandler.java
(original)
+++ incubator/aries/trunk/jpa/jpa-container-context/src/main/java/org/apache/aries/jpa/container/context/namespace/NSHandler.java
Thu Feb  4 09:06:11 2010
@@ -232,6 +232,7 @@
     meta.setActivation(factory.getActivation());
     meta.setFactoryMethod("createEntityManager");
     meta.setScope(BeanMetadata.SCOPE_PROTOTYPE);
+    meta.setDestroyMethod("internalClose");
     
     return meta;
   }

Modified: incubator/aries/trunk/jpa/jpa-container-context/src/main/java/org/apache/aries/jpa/container/context/transaction/impl/JTAEntityManager.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/jpa/jpa-container-context/src/main/java/org/apache/aries/jpa/container/context/transaction/impl/JTAEntityManager.java?rev=906408&r1=906407&r2=906408&view=diff
==============================================================================
--- incubator/aries/trunk/jpa/jpa-container-context/src/main/java/org/apache/aries/jpa/container/context/transaction/impl/JTAEntityManager.java
(original)
+++ incubator/aries/trunk/jpa/jpa-container-context/src/main/java/org/apache/aries/jpa/container/context/transaction/impl/JTAEntityManager.java
Thu Feb  4 09:06:11 2010
@@ -82,6 +82,21 @@
     }
   }
   
+  /**
+   * Called reflectively by blueprint
+   */
+  public void internalClose() {
+    EntityManager temp = null;
+    
+    synchronized (this) {
+      temp = detachedManager;
+      detachedManager = null;
+    }
+    
+    if (temp != null)
+      temp.close();
+  }
+  
   public void clear()
   {
     getPersistenceContext(false).clear();

Modified: incubator/aries/trunk/jpa/jpa-container-context/src/test/java/org/apache/aries/jpa/container/context/namespace/NSHandlerTest.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/jpa/jpa-container-context/src/test/java/org/apache/aries/jpa/container/context/namespace/NSHandlerTest.java?rev=906408&r1=906407&r2=906408&view=diff
==============================================================================
--- incubator/aries/trunk/jpa/jpa-container-context/src/test/java/org/apache/aries/jpa/container/context/namespace/NSHandlerTest.java
(original)
+++ incubator/aries/trunk/jpa/jpa-container-context/src/test/java/org/apache/aries/jpa/container/context/namespace/NSHandlerTest.java
Thu Feb  4 09:06:11 2010
@@ -190,6 +190,7 @@
     BeanMetadata innerBean = (BeanMetadata) ((BeanProperty) bean.getProperties().get(0)).getValue();
 
     assertEquals("createEntityManager", innerBean.getFactoryMethod());
+    assertEquals("internalClose", innerBean.getDestroyMethod());
 
     assertEquals(1, registeredComponents.size());
     ReferenceMetadata reference = (ReferenceMetadata) registeredComponents.get(0);



Mime
View raw message