aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cschnei...@apache.org
Subject svn commit: r1689634 - in /aries/trunk/jpa: jpa-blueprint/src/main/java/org/apache/aries/jpa/blueprint/supplier/impl/EmfProxy.java jpa-container/src/main/java/org/apache/aries/jpa/container/impl/PersistenceBundleTracker.java
Date Tue, 07 Jul 2015 12:11:16 GMT
Author: cschneider
Date: Tue Jul  7 12:11:16 2015
New Revision: 1689634

URL: http://svn.apache.org/r1689634
Log:
[ARIES-1349] Fix EmfProxy

Modified:
    aries/trunk/jpa/jpa-blueprint/src/main/java/org/apache/aries/jpa/blueprint/supplier/impl/EmfProxy.java
    aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/impl/PersistenceBundleTracker.java

Modified: aries/trunk/jpa/jpa-blueprint/src/main/java/org/apache/aries/jpa/blueprint/supplier/impl/EmfProxy.java
URL: http://svn.apache.org/viewvc/aries/trunk/jpa/jpa-blueprint/src/main/java/org/apache/aries/jpa/blueprint/supplier/impl/EmfProxy.java?rev=1689634&r1=1689633&r2=1689634&view=diff
==============================================================================
--- aries/trunk/jpa/jpa-blueprint/src/main/java/org/apache/aries/jpa/blueprint/supplier/impl/EmfProxy.java
(original)
+++ aries/trunk/jpa/jpa-blueprint/src/main/java/org/apache/aries/jpa/blueprint/supplier/impl/EmfProxy.java
Tue Jul  7 12:11:16 2015
@@ -33,43 +33,41 @@ import org.osgi.framework.InvalidSyntaxE
 import org.osgi.util.tracker.ServiceTracker;
 
 public class EmfProxy implements InvocationHandler {
-	private ServiceTracker<EntityManagerFactory, EntityManagerFactory> tracker;
+    private ServiceTracker<EntityManagerFactory, EntityManagerFactory> tracker;
 
-	public EmfProxy(BundleContext context, String unitName) {
-		String filterS = String.format("(&(objectClass=%s)(%s=%s))",
-				EntityManagerFactory.class.getName(), JPA_UNIT_NAME, unitName);
-		Filter filter;
-		try {
-			filter = FrameworkUtil.createFilter(filterS);
-		} catch (InvalidSyntaxException e) {
-			throw new IllegalStateException(e);
-		}
-		tracker = new ServiceTracker<>(context, filter, null);
-		tracker.open();
-	}
-
-	private EntityManagerFactory getEntityManagerFactory() {
-		try {
-			return tracker.waitForService(10000);
-		} catch (InterruptedException e) {
-			throw new IllegalStateException(e);
-		}
-	}
-
-	@Override
-	public Object invoke(Object proxy, Method method, Object[] args)
-			throws Throwable {
-		Object res = null;
-
-		EntityManagerFactory delegate = getEntityManagerFactory();
-
-		try {
-			res = method.invoke(delegate, args);
-		} catch (IllegalArgumentException e) {
-			new IllegalStateException(e);
-		} catch (InvocationTargetException e) {
-			new IllegalStateException(e);
-		}
-		return res;
-	}
+    public EmfProxy(BundleContext context, String unitName) {
+        String filterS = String.format("(&(objectClass=%s)(%s=%s))", EntityManagerFactory.class.getName(),
+                                       JPA_UNIT_NAME, unitName);
+        Filter filter;
+        try {
+            filter = FrameworkUtil.createFilter(filterS);
+        } catch (InvalidSyntaxException e) {
+            throw new IllegalStateException(e);
+        }
+        tracker = new ServiceTracker<>(context, filter, null);
+        tracker.open();
+    }
+
+    private EntityManagerFactory getEntityManagerFactory() {
+        try {
+            return tracker.waitForService(10000);
+        } catch (InterruptedException e) {
+            throw new IllegalStateException(e);
+        }
+    }
+
+    @Override
+    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
+        if ("close".equals(method.getName())) {
+            tracker.close();
+            return null;
+        }
+        try {
+            return method.invoke(getEntityManagerFactory(), args);
+        } catch (IllegalArgumentException e) {
+            throw new IllegalStateException(e);
+        } catch (InvocationTargetException e) {
+            throw new IllegalStateException(e);
+        }
+    }
 }

Modified: aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/impl/PersistenceBundleTracker.java
URL: http://svn.apache.org/viewvc/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/impl/PersistenceBundleTracker.java?rev=1689634&r1=1689633&r2=1689634&view=diff
==============================================================================
--- aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/impl/PersistenceBundleTracker.java
(original)
+++ aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/impl/PersistenceBundleTracker.java
Tue Jul  7 12:11:16 2015
@@ -50,25 +50,23 @@ public class PersistenceBundleTracker im
         trackers = new HashMap<Bundle, Collection<PersistenceProviderTracker>>();
     }
 
-    public Bundle addingBundle(Bundle bundle, BundleEvent event) {
+    public synchronized Bundle addingBundle(Bundle bundle, BundleEvent event) {
         if (getTrackers(bundle).size() == 0) {
             findPersistenceUnits(bundle);
         }
         return bundle;
     }
 
-    public void removedBundle(Bundle bundle, BundleEvent event, Bundle object) {
-        Collection<PersistenceProviderTracker> providerTrackers = trackers.get(bundle);
-        if (providerTrackers != null) {
-            if (providerTrackers.size() > 0)  {
-                LOGGER.info("removing persistence units for " + bundle.getSymbolicName()
+ " " + getType(event));
-            }
-            for (PersistenceProviderTracker providerTracker : providerTrackers) {
-                providerTracker.close();
-            }
-            providerTrackers.clear();
-            trackers.remove(bundle);
+    public synchronized void removedBundle(Bundle bundle, BundleEvent event, Bundle object)
{
+        Collection<PersistenceProviderTracker> providerTrackers = trackers.remove(bundle);
+        if (providerTrackers == null || providerTrackers.size() > 0) {
+            return;
         }
+        LOGGER.info("removing persistence units for " + bundle.getSymbolicName() + " " +
getType(event));
+        for (PersistenceProviderTracker providerTracker : providerTrackers) {
+            providerTracker.close();
+        }
+        providerTrackers.clear();
     }
 
     private void findPersistenceUnits(Bundle bundle) {



Mime
View raw message