You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@aries.apache.org by ma...@apache.org on 2010/01/21 14:16:13 UTC
svn commit: r901694 - in /incubator/aries/trunk/jpa/jpa-container: pom.xml
src/main/java/org/apache/aries/jpa/container/impl/PersistenceBundleManager.java
src/test/java/org/apache/aries/jpa/container/PersistenceBundleLifecycleTest.java
Author: mahrwald
Date: Thu Jan 21 13:16:13 2010
New Revision: 901694
URL: http://svn.apache.org/viewvc?rev=901694&view=rev
Log:
ARIES-118 Enable multiple frameworks to work
Modified:
incubator/aries/trunk/jpa/jpa-container/pom.xml
incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/impl/PersistenceBundleManager.java
incubator/aries/trunk/jpa/jpa-container/src/test/java/org/apache/aries/jpa/container/PersistenceBundleLifecycleTest.java
Modified: incubator/aries/trunk/jpa/jpa-container/pom.xml
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/jpa/jpa-container/pom.xml?rev=901694&r1=901693&r2=901694&view=diff
==============================================================================
--- incubator/aries/trunk/jpa/jpa-container/pom.xml (original)
+++ incubator/aries/trunk/jpa/jpa-container/pom.xml Thu Jan 21 13:16:13 2010
@@ -51,9 +51,14 @@
<version>1.0.0-incubating-SNAPSHOT</version>
</dependency>
<dependency>
+ <artifactId>org.apache.aries.util</artifactId>
+ <groupId>org.apache.aries</groupId>
+ <version>1.0.0-incubating-SNAPSHOT</version>
+ </dependency>
+ <dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-jpa_2.0_spec</artifactId>
- </dependency>
+ </dependency>
<dependency>
<groupId>org.apache.aries.testsupport</groupId>
<artifactId>org.apache.aries.testsupport.unit</artifactId>
Modified: incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/impl/PersistenceBundleManager.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/impl/PersistenceBundleManager.java?rev=901694&r1=901693&r2=901694&view=diff
==============================================================================
--- incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/impl/PersistenceBundleManager.java (original)
+++ incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/impl/PersistenceBundleManager.java Thu Jan 21 13:16:13 2010
@@ -42,19 +42,19 @@
import org.apache.aries.jpa.container.parsing.PersistenceDescriptorParser;
import org.apache.aries.jpa.container.parsing.PersistenceDescriptorParserException;
import org.apache.aries.jpa.container.unit.impl.ManagedPersistenceUnitInfoFactoryImpl;
+import org.apache.aries.util.tracker.MultiBundleTracker;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleEvent;
import org.osgi.framework.Constants;
import org.osgi.framework.ServiceReference;
import org.osgi.framework.Version;
-import org.osgi.util.tracker.BundleTracker;
/**
* This class locates, parses and manages persistence units defined in OSGi bundles.
*/
-public class PersistenceBundleManager extends BundleTracker
+public class PersistenceBundleManager extends MultiBundleTracker
{
/** The bundle context for this bundle */
private BundleContext ctx = null;
@@ -83,7 +83,7 @@
public PersistenceBundleManager(BundleContext ctx)
{
super(ctx, Bundle.INSTALLED | Bundle.RESOLVED | Bundle.STARTING |
- Bundle.ACTIVE | Bundle.STOPPING, null);
+ Bundle.ACTIVE | Bundle.STOPPING);
this.ctx = ctx;
}
Modified: incubator/aries/trunk/jpa/jpa-container/src/test/java/org/apache/aries/jpa/container/PersistenceBundleLifecycleTest.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/jpa/jpa-container/src/test/java/org/apache/aries/jpa/container/PersistenceBundleLifecycleTest.java?rev=901694&r1=901693&r2=901694&view=diff
==============================================================================
--- incubator/aries/trunk/jpa/jpa-container/src/test/java/org/apache/aries/jpa/container/PersistenceBundleLifecycleTest.java (original)
+++ incubator/aries/trunk/jpa/jpa-container/src/test/java/org/apache/aries/jpa/container/PersistenceBundleLifecycleTest.java Thu Jan 21 13:16:13 2010
@@ -29,6 +29,7 @@
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStreamWriter;
+import java.lang.reflect.Field;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Dictionary;
@@ -42,6 +43,7 @@
import javax.persistence.spi.PersistenceProvider;
import javax.persistence.spi.PersistenceUnitInfo;
+import org.apache.aries.jpa.container.impl.EntityManagerFactoryManager;
import org.apache.aries.jpa.container.impl.PersistenceBundleManager;
import org.apache.aries.jpa.container.util.FakeManagedPersistenceUnitFactory;
import org.apache.aries.mocks.BundleContextMock;
@@ -143,7 +145,7 @@
//Check we don't have an EMF
BundleContextMock.assertNoServiceExists(EntityManagerFactory.class.getName());
- assertNull("We should not have an EntityManagerFactoryManager", mgr.getObject(persistenceBundle));
+ assertNull("We should not have an EntityManagerFactoryManager", getTrackedObject());
}
@@ -164,7 +166,7 @@
//Check we don't have an EMF
BundleContextMock.assertNoServiceExists(EntityManagerFactory.class.getName());
- assertNull("We should not have an EntityManagerFactoryManager", mgr.getObject(persistenceBundle));
+ assertNull("We should not have an EntityManagerFactoryManager", getTrackedObject());
}
@Test
@@ -310,9 +312,10 @@
//Clear the extender context to remove the previous get for the PersistenceProvider.
Skeleton.getSkeleton(extenderContext).clearMethodCalls();
+ System.out.println(getTrackedObject());
//Update the bundle
Skeleton.getSkeleton(persistenceBundle).setReturnValue(new MethodCall(Bundle.class, "getState"), Bundle.INSTALLED);
- mgr.modifiedBundle(persistenceBundle, new BundleEvent(BundleEvent.UPDATED, persistenceBundle), mgr.getObject(persistenceBundle));
+ mgr.modifiedBundle(persistenceBundle, new BundleEvent(BundleEvent.UPDATED, persistenceBundle), getTrackedObject());
//Check the persistence.xml was looked for
Skeleton.getSkeleton(persistenceBundle).assertCalled(new MethodCall(Bundle.class, "getEntry", "META-INF/persistence.xml"));
@@ -326,7 +329,7 @@
//Now resolve the bundle again and check we get another EMF created
Skeleton.getSkeleton(persistenceBundle).setReturnValue(new MethodCall(Bundle.class, "getState"), Bundle.RESOLVED);
- mgr.modifiedBundle(persistenceBundle, new BundleEvent(BundleEvent.RESOLVED, persistenceBundle), mgr.getObject(persistenceBundle));
+ mgr.modifiedBundle(persistenceBundle, new BundleEvent(BundleEvent.RESOLVED, persistenceBundle), getTrackedObject());
//We will have created the EMF a total of 2 times
testSuccessfulCreationEvent(ref, extenderContext, 2);
@@ -355,7 +358,7 @@
Skeleton.getSkeleton(persistenceBundle).clearMethodCalls();
Skeleton.getSkeleton(persistenceBundle).setReturnValue(new MethodCall(Bundle.class, "getState"), Bundle.INSTALLED);
- mgr.modifiedBundle(persistenceBundle, new BundleEvent(BundleEvent.UNRESOLVED, persistenceBundle), mgr.getObject(persistenceBundle));
+ mgr.modifiedBundle(persistenceBundle, new BundleEvent(BundleEvent.UNRESOLVED, persistenceBundle), getTrackedObject());
//Check we don't re-parse the xml
Skeleton.getSkeleton(persistenceBundle).assertNotCalled(new MethodCall(Bundle.class, "getEntry", "META-INF/persistence.xml"));
@@ -392,7 +395,7 @@
Skeleton.getSkeleton(pp).assertCalled(new MethodCall(EntityManagerFactory.class, "close"));
BundleContextMock.assertNoServiceExists(EntityManagerFactory.class.getName());
- mgr.modifiedBundle(persistenceBundle, null, mgr.getObject(persistenceBundle));
+ mgr.modifiedBundle(persistenceBundle, null, getTrackedObject());
}
@Test
@@ -974,5 +977,13 @@
{
assertCorrectPersistenceProviderUsed(extenderContext, provider, 1);
}
+
+ private EntityManagerFactoryManager getTrackedObject() throws Exception {
+ Field f = mgr.getClass().getDeclaredField("bundleToManagerMap");
+ f.setAccessible(true);
+ Map<Bundle, EntityManagerFactoryManager> map = (Map<Bundle, EntityManagerFactoryManager>) f.get(mgr);
+
+ return map.get(persistenceBundle);
+ }
}