incubator-aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mnutt...@apache.org
Subject svn commit: r1044342 - in /incubator/aries/trunk: jndi/jndi-url/src/main/java/org/apache/aries/jndi/url/ jpa/jpa-container-context/src/main/java/org/apache/aries/jpa/container/context/impl/ jpa/jpa-container-itest/src/test/java/org/apache/aries/jpa/con...
Date Fri, 10 Dec 2010 13:09:44 GMT
Author: mnuttall
Date: Fri Dec 10 13:09:43 2010
New Revision: 1044342

URL: http://svn.apache.org/viewvc?rev=1044342&view=rev
Log:
ARIES-512: JPA itests: use blueprint:comp/ to reference a datasource declared in blueprint
from persistence.xml. Includes a fix to PersistenceContextManager by Tim Ward. 

Added:
    incubator/aries/trunk/jpa/jpa-container-testbundle/src/main/resources/OSGI-INF/
    incubator/aries/trunk/jpa/jpa-container-testbundle/src/main/resources/OSGI-INF/blueprint/
    incubator/aries/trunk/jpa/jpa-container-testbundle/src/main/resources/OSGI-INF/blueprint/config.xml
Modified:
    incubator/aries/trunk/jndi/jndi-url/src/main/java/org/apache/aries/jndi/url/BlueprintURLContext.java
    incubator/aries/trunk/jndi/jndi-url/src/main/java/org/apache/aries/jndi/url/BlueprintURLContextFactory.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-itest/src/test/java/org/apache/aries/jpa/container/itest/JPAContainerTest.java
    incubator/aries/trunk/jpa/jpa-container-itest/src/test/java/org/apache/aries/jpa/context/itest/JPAContextTest.java
    incubator/aries/trunk/jpa/jpa-container-testbundle/pom.xml
    incubator/aries/trunk/jpa/jpa-container-testbundle/src/main/resources/META-INF/persistence.xml
    incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/unit/impl/DelayedLookupDataSource.java
    incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/unit/impl/PersistenceUnitInfoImpl.java

Modified: incubator/aries/trunk/jndi/jndi-url/src/main/java/org/apache/aries/jndi/url/BlueprintURLContext.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/jndi/jndi-url/src/main/java/org/apache/aries/jndi/url/BlueprintURLContext.java?rev=1044342&r1=1044341&r2=1044342&view=diff
==============================================================================
--- incubator/aries/trunk/jndi/jndi-url/src/main/java/org/apache/aries/jndi/url/BlueprintURLContext.java
(original)
+++ incubator/aries/trunk/jndi/jndi-url/src/main/java/org/apache/aries/jndi/url/BlueprintURLContext.java
Fri Dec 10 13:09:43 2010
@@ -131,7 +131,7 @@ public class BlueprintURLContext impleme
     }
   }
   
-  public BlueprintURLContext (Bundle callersBundle, BlueprintName parentName, Map<String,
Object> env, 
+  private BlueprintURLContext (Bundle callersBundle, BlueprintName parentName, Map<String,
Object> env, 
       BlueprintContainer bpc) { 
     _callersBundle = callersBundle;
     _parentName = parentName;

Modified: incubator/aries/trunk/jndi/jndi-url/src/main/java/org/apache/aries/jndi/url/BlueprintURLContextFactory.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/jndi/jndi-url/src/main/java/org/apache/aries/jndi/url/BlueprintURLContextFactory.java?rev=1044342&r1=1044341&r2=1044342&view=diff
==============================================================================
--- incubator/aries/trunk/jndi/jndi-url/src/main/java/org/apache/aries/jndi/url/BlueprintURLContextFactory.java
(original)
+++ incubator/aries/trunk/jndi/jndi-url/src/main/java/org/apache/aries/jndi/url/BlueprintURLContextFactory.java
Fri Dec 10 13:09:43 2010
@@ -26,6 +26,8 @@ import javax.naming.Name;
 import javax.naming.spi.ObjectFactory;
 
 import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.service.jndi.JNDIConstants;
 
 public class BlueprintURLContextFactory implements ObjectFactory {
 
@@ -37,13 +39,17 @@ public class BlueprintURLContextFactory 
 
   @Override
   public Object getObjectInstance(Object obj, Name name, Context callersCtx, Hashtable<?,
?> envmt) throws Exception {
+    BundleContext bc = (BundleContext) envmt.get(JNDIConstants.BUNDLE_CONTEXT);
+    Bundle b = (bc != null)? bc.getBundle() : null;
     Object result = null;
     if (obj == null) {
-      result = new BlueprintURLContext(_callersBundle, envmt);
+      result = new BlueprintURLContext((b == null) ? _callersBundle : b,
+          envmt);
     } else if (obj instanceof String) {
       Context ctx = null;
       try {
-        ctx = new BlueprintURLContext(_callersBundle, envmt);
+        ctx = new BlueprintURLContext((b == null) ? _callersBundle : b,
+            envmt);
         result = ctx.lookup((String) obj);
       } finally {
         if (ctx != null) {

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=1044342&r1=1044341&r2=1044342&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
Fri Dec 10 13:09:43 2010
@@ -26,8 +26,8 @@ import java.util.Hashtable;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
-import java.util.Set;
 import java.util.Map.Entry;
+import java.util.Set;
 
 import javax.persistence.EntityManagerFactory;
 import javax.persistence.PersistenceContextType;
@@ -434,12 +434,21 @@ public class PersistenceContextManager e
       //Find the ManagedFactories for the persistence unit
       List<ManagedPersistenceContextFactory> factoriesToQuiesce = new ArrayList<ManagedPersistenceContextFactory>();
       synchronized (this) {
-        for(String name : units) {
-          ServiceRegistration reg = entityManagerRegistrations.get(name);
+        Iterator<String> it = units.iterator();
+        while(it.hasNext()) {
+          ServiceRegistration reg = entityManagerRegistrations.get(it.next());
+          //If there's no managed factory then we don't need to quiesce this unit
+          boolean needsQuiesce = false;
           if(reg != null) {
             ManagedPersistenceContextFactory fact = (ManagedPersistenceContextFactory) bundleToQuiesce.getBundleContext().getService(reg.getReference());
-            if(fact != null)
+            if(fact != null) {
               factoriesToQuiesce.add(fact);
+              needsQuiesce = true;
+            }
+          }
+          //If the unit doesn't need quiescing then remove it from our check
+          if(!!!needsQuiesce) {
+            it.remove();
           }
         }
       }

Modified: incubator/aries/trunk/jpa/jpa-container-itest/src/test/java/org/apache/aries/jpa/container/itest/JPAContainerTest.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/jpa/jpa-container-itest/src/test/java/org/apache/aries/jpa/container/itest/JPAContainerTest.java?rev=1044342&r1=1044341&r2=1044342&view=diff
==============================================================================
--- incubator/aries/trunk/jpa/jpa-container-itest/src/test/java/org/apache/aries/jpa/container/itest/JPAContainerTest.java
(original)
+++ incubator/aries/trunk/jpa/jpa-container-itest/src/test/java/org/apache/aries/jpa/container/itest/JPAContainerTest.java
Fri Dec 10 13:09:43 2010
@@ -21,14 +21,9 @@ import static org.ops4j.pax.exam.CoreOpt
 import static org.ops4j.pax.exam.CoreOptions.wrappedBundle;
 import static org.ops4j.pax.exam.OptionUtils.combine;
 
-import java.util.Hashtable;
-
 import javax.persistence.EntityManagerFactory;
-import javax.persistence.spi.PersistenceProvider;
 
 import org.apache.aries.jpa.container.PersistenceUnitConstants;
-import org.junit.Before;
-import org.junit.Ignore;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.ops4j.pax.exam.CoreOptions;
@@ -44,7 +39,6 @@ import org.osgi.framework.Filter;
 import org.osgi.framework.FrameworkUtil;
 import org.osgi.framework.InvalidSyntaxException;
 import org.osgi.framework.Version;
-import org.osgi.service.packageadmin.PackageAdmin;
 import org.osgi.util.tracker.ServiceTracker;
 
 @RunWith(JUnit4TestRunner.class)
@@ -58,6 +52,23 @@ public class JPAContainerTest {
   public void findEntityManagerFactory() throws Exception {
     EntityManagerFactory emf = getOsgiService(EntityManagerFactory.class, "(&(osgi.unit.name=test-unit)("
+ PersistenceUnitConstants.CONTAINER_MANAGED_PERSISTENCE_UNIT + "=true))", DEFAULT_TIMEOUT);
   }
+  
+  @Test
+  public void findEntityManagerFactory2() throws Exception {
+    EntityManagerFactory emf = getOsgiService(EntityManagerFactory.class, "(&(osgi.unit.name=bp-test-unit)("
+ PersistenceUnitConstants.CONTAINER_MANAGED_PERSISTENCE_UNIT + "=true))", DEFAULT_TIMEOUT);
+  }
+  
+  @Test
+  public void findEntityManager() throws Exception {
+    EntityManagerFactory emf = getOsgiService(EntityManagerFactory.class, "(&(osgi.unit.name=test-unit)("
+ PersistenceUnitConstants.CONTAINER_MANAGED_PERSISTENCE_UNIT + "=true))", DEFAULT_TIMEOUT);
+    emf.createEntityManager();
+  }
+  
+  @Test
+  public void findEntityManager2() throws Exception {
+    EntityManagerFactory emf = getOsgiService(EntityManagerFactory.class, "(&(osgi.unit.name=bp-test-unit)("
+ PersistenceUnitConstants.CONTAINER_MANAGED_PERSISTENCE_UNIT + "=true))", DEFAULT_TIMEOUT);
+    emf.createEntityManager();
+  }
 
   @org.ops4j.pax.exam.junit.Configuration
   public static Option[] configuration() {
@@ -77,18 +88,27 @@ public class JPAContainerTest {
         systemProperty("org.ops4j.pax.logging.DefaultServiceLog.level").value("DEBUG"),
 
         // Bundles
-        mavenBundle("org.osgi", "org.osgi.compendium"),
+        mavenBundle("commons-lang", "commons-lang"),
+        mavenBundle("commons-collections", "commons-collections"),
+        mavenBundle("commons-pool", "commons-pool"),
         mavenBundle("org.apache.aries", "org.apache.aries.util"),
-        mavenBundle("org.apache.geronimo.specs", "geronimo-jpa_2.0_spec"),
+        mavenBundle("org.apache.aries.blueprint", "org.apache.aries.blueprint"),
+        mavenBundle("org.apache.aries.jndi", "org.apache.aries.jndi.api"),
+        mavenBundle("org.apache.aries.jndi", "org.apache.aries.jndi.core"),
+        mavenBundle("org.apache.aries.jndi", "org.apache.aries.jndi.url"),
         mavenBundle("org.apache.aries.jpa", "org.apache.aries.jpa.api"),
         mavenBundle("org.apache.aries.jpa", "org.apache.aries.jpa.container"),
+        mavenBundle("org.apache.derby", "derby"),
         mavenBundle("org.apache.geronimo.specs", "geronimo-jta_1.1_spec"),
-        mavenBundle("commons-lang", "commons-lang"),
-        mavenBundle("commons-collections", "commons-collections"),
-        mavenBundle("commons-pool", "commons-pool"),
-        mavenBundle("org.apache.servicemix.bundles", "org.apache.servicemix.bundles.serp"),
+        mavenBundle("org.apache.geronimo.specs", "geronimo-jpa_2.0_spec"),
         mavenBundle("org.apache.openjpa", "openjpa"),
+        mavenBundle("org.apache.servicemix.bundles", "org.apache.servicemix.bundles.serp"),
+        mavenBundle("org.osgi", "org.osgi.compendium"),
 
+        //vmOption ("-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5006"),
+        //waitForFrameworkStartup(),
+        
+       
 //        mavenBundle("org.eclipse.persistence", "org.eclipse.persistence.jpa"),
 //        mavenBundle("org.eclipse.persistence", "org.eclipse.persistence.core"),
 //        mavenBundle("org.eclipse.persistence", "org.eclipse.persistence.asm"),

Modified: incubator/aries/trunk/jpa/jpa-container-itest/src/test/java/org/apache/aries/jpa/context/itest/JPAContextTest.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/jpa/jpa-container-itest/src/test/java/org/apache/aries/jpa/context/itest/JPAContextTest.java?rev=1044342&r1=1044341&r2=1044342&view=diff
==============================================================================
--- incubator/aries/trunk/jpa/jpa-container-itest/src/test/java/org/apache/aries/jpa/context/itest/JPAContextTest.java
(original)
+++ incubator/aries/trunk/jpa/jpa-container-itest/src/test/java/org/apache/aries/jpa/context/itest/JPAContextTest.java
Fri Dec 10 13:09:43 2010
@@ -25,7 +25,6 @@ import static org.ops4j.pax.exam.CoreOpt
 import static org.ops4j.pax.exam.OptionUtils.combine;
 
 import java.util.HashMap;
-import java.util.Map;
 
 import javax.persistence.EntityManagerFactory;
 import javax.persistence.PersistenceContextType;
@@ -105,10 +104,13 @@ public class JPAContextTest {
         // Bundles
         mavenBundle("org.osgi", "org.osgi.compendium"),
         mavenBundle("org.apache.aries", "org.apache.aries.util"),
+        // Adding blueprint to the runtime is a hack to placate the maven bundle plugin.

+        mavenBundle("org.apache.aries.blueprint", "org.apache.aries.blueprint"),
         mavenBundle("org.apache.geronimo.specs", "geronimo-jpa_2.0_spec"),
         mavenBundle("org.apache.aries.jpa", "org.apache.aries.jpa.api"),
         mavenBundle("org.apache.aries.jpa", "org.apache.aries.jpa.container"),
         mavenBundle("org.apache.aries.jpa", "org.apache.aries.jpa.container.context"),
+        mavenBundle("org.apache.derby", "derby"),
         mavenBundle("org.apache.geronimo.specs", "geronimo-jta_1.1_spec"),
         mavenBundle("commons-lang", "commons-lang"),
         mavenBundle("commons-collections", "commons-collections"),

Modified: incubator/aries/trunk/jpa/jpa-container-testbundle/pom.xml
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/jpa/jpa-container-testbundle/pom.xml?rev=1044342&r1=1044341&r2=1044342&view=diff
==============================================================================
--- incubator/aries/trunk/jpa/jpa-container-testbundle/pom.xml (original)
+++ incubator/aries/trunk/jpa/jpa-container-testbundle/pom.xml Fri Dec 10 13:09:43 2010
@@ -55,6 +55,7 @@
                         <Export-Package>
                             org.apache.aries.jpa.container.itest.entities;version="${pom.version}",
                         </Export-Package>
+                        <Private-Package>org.apache.aries.jpa.container.itest</Private-Package>
                         <_versionpolicy>[$(version;==;$(@)),$(version;+;$(@)))</_versionpolicy>
                         <_removeheaders>Ignore-Package,Include-Resource,Private-Package,Bundle-DocURL</_removeheaders>
                         <Meta-Persistence>META-INF/persistence.xml</Meta-Persistence>

Modified: incubator/aries/trunk/jpa/jpa-container-testbundle/src/main/resources/META-INF/persistence.xml
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/jpa/jpa-container-testbundle/src/main/resources/META-INF/persistence.xml?rev=1044342&r1=1044341&r2=1044342&view=diff
==============================================================================
--- incubator/aries/trunk/jpa/jpa-container-testbundle/src/main/resources/META-INF/persistence.xml
(original)
+++ incubator/aries/trunk/jpa/jpa-container-testbundle/src/main/resources/META-INF/persistence.xml
Fri Dec 10 13:09:43 2010
@@ -32,4 +32,12 @@
       
     </properties>
   </persistence-unit>
+  
+  <persistence-unit name="bp-test-unit" transaction-type="RESOURCE_LOCAL">
+    <description>Test persistence unit for the JPA Container and Context iTests</description>
+    <jta-data-source>blueprint:comp/jta</jta-data-source>
+    <non-jta-data-source>blueprint:comp/nonjta</non-jta-data-source>
+    <class>org.apache.aries.jpa.container.itest.entities.Car</class>
+    <exclude-unlisted-classes>true</exclude-unlisted-classes>
+  </persistence-unit>
 </persistence>

Added: incubator/aries/trunk/jpa/jpa-container-testbundle/src/main/resources/OSGI-INF/blueprint/config.xml
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/jpa/jpa-container-testbundle/src/main/resources/OSGI-INF/blueprint/config.xml?rev=1044342&view=auto
==============================================================================
--- incubator/aries/trunk/jpa/jpa-container-testbundle/src/main/resources/OSGI-INF/blueprint/config.xml
(added)
+++ incubator/aries/trunk/jpa/jpa-container-testbundle/src/main/resources/OSGI-INF/blueprint/config.xml
Fri Dec 10 13:09:43 2010
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!--
+    Licensed to the Apache Software Foundation (ASF) under one or more
+    contributor license agreements.  See the NOTICE file distributed with
+    this work for additional information regarding copyright ownership.
+    The ASF licenses this file to You under the Apache License, Version 2.0
+    (the "License"); you may not use this file except in compliance with
+    the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+-->
+<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
+
+  <bean id="jta" class="org.apache.derby.jdbc.EmbeddedDataSource">
+    <property name="databaseName" value="memory:testDB"/>
+    <property name="createDatabase" value="create"/> 
+  </bean>
+  
+  <bean id="nonjta" class="org.apache.derby.jdbc.EmbeddedDataSource">
+    <property name="databaseName" value="memory:testDB"/> 
+    <property name="createDatabase" value="create"/>
+  </bean>
+  
+  
+  <service ref="jta" interface="javax.sql.DataSource"/>
+    
+</blueprint>
+

Modified: incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/unit/impl/DelayedLookupDataSource.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/unit/impl/DelayedLookupDataSource.java?rev=1044342&r1=1044341&r2=1044342&view=diff
==============================================================================
--- incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/unit/impl/DelayedLookupDataSource.java
(original)
+++ incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/unit/impl/DelayedLookupDataSource.java
Fri Dec 10 13:09:43 2010
@@ -21,11 +21,14 @@ package org.apache.aries.jpa.container.u
 import java.io.PrintWriter;
 import java.sql.Connection;
 import java.sql.SQLException;
+import java.util.Hashtable;
 
 import javax.naming.InitialContext;
 import javax.naming.NamingException;
 import javax.sql.DataSource;
 
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -39,7 +42,16 @@ public class DelayedLookupDataSource imp
   private DataSource getDs() {
     if(ds == null) {
       try {
-        InitialContext ctx = new InitialContext();
+        
+        Hashtable<String, Object> props = new Hashtable<String, Object>();
+        
+        BundleContext bCtx = persistenceBundle.getBundleContext();
+        if(bCtx == null)
+          throw new IllegalStateException("The bundle " + 
+              persistenceBundle.getSymbolicName() + "_" + persistenceBundle.getVersion()
+ 
+              " is not started.");
+        props.put("osgi.service.jndi.bundleContext", bCtx);
+        InitialContext ctx = new InitialContext(props);
         ds = (DataSource) ctx.lookup(jndiName);
       } catch (NamingException e) {
         _logger.error("No JTA datasource could be located using the JNDI name " + jndiName,
@@ -51,9 +63,11 @@ public class DelayedLookupDataSource imp
   }
 
   private final String jndiName;
+  private final Bundle persistenceBundle;
   
-  public DelayedLookupDataSource (String jndi) {
+  public DelayedLookupDataSource (String jndi, Bundle persistenceBundle) {
     jndiName = jndi;
+    this.persistenceBundle = persistenceBundle;
   }
   
   public Connection getConnection() throws SQLException {

Modified: incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/unit/impl/PersistenceUnitInfoImpl.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/unit/impl/PersistenceUnitInfoImpl.java?rev=1044342&r1=1044341&r2=1044342&view=diff
==============================================================================
--- incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/unit/impl/PersistenceUnitInfoImpl.java
(original)
+++ incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/unit/impl/PersistenceUnitInfoImpl.java
Fri Dec 10 13:09:43 2010
@@ -94,7 +94,7 @@ public class PersistenceUnitInfoImpl imp
     String jndiString = (String) unit.getPersistenceXmlMetadata().get(ParsedPersistenceUnit.JTA_DATASOURCE);
     DataSource toReturn = null;
     if(jndiString != null) {
-      toReturn = new DelayedLookupDataSource(jndiString);
+      toReturn = new DelayedLookupDataSource(jndiString, bundle);
     }
     return toReturn;
   }
@@ -126,7 +126,7 @@ public class PersistenceUnitInfoImpl imp
     String jndiString = (String) unit.getPersistenceXmlMetadata().get(ParsedPersistenceUnit.NON_JTA_DATASOURCE);
     DataSource toReturn = null;
     if(jndiString != null) {
-      toReturn = new DelayedLookupDataSource(jndiString);
+      toReturn = new DelayedLookupDataSource(jndiString, bundle);
     }
     return toReturn;
   }



Mime
View raw message