incubator-aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mahrw...@apache.org
Subject svn commit: r907665 - in /incubator/aries/trunk/jpa/jpa-container/src: main/java/org/apache/aries/jpa/container/impl/PersistenceBundleHelper.java test/java/org/apache/aries/jpa/container/PersistenceBundleLifecycleTest.java
Date Mon, 08 Feb 2010 14:22:23 GMT
Author: mahrwald
Date: Mon Feb  8 14:22:22 2010
New Revision: 907665

URL: http://svn.apache.org/viewvc?rev=907665&view=rev
Log:
ARIES-147 Don't scan WABs

Modified:
    incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/impl/PersistenceBundleHelper.java
    incubator/aries/trunk/jpa/jpa-container/src/test/java/org/apache/aries/jpa/container/PersistenceBundleLifecycleTest.java

Modified: incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/impl/PersistenceBundleHelper.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/impl/PersistenceBundleHelper.java?rev=907665&r1=907664&r2=907665&view=diff
==============================================================================
--- incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/impl/PersistenceBundleHelper.java
(original)
+++ incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/impl/PersistenceBundleHelper.java
Mon Feb  8 14:22:22 2010
@@ -11,7 +11,7 @@
  *
  * Unless required by applicable law or agreed to in writing,
  * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIESOR CONDITIONS OF ANY
+ * "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.
@@ -45,6 +45,8 @@
   public static final String PERSISTENCE_XML = "META-INF/persistence.xml";
   /** The Meta-Persistence header */
   public static final String PERSISTENCE_UNIT_HEADER = "Meta-Persistence";
+  /** The Web-ContextPath header (as defined in the web application bundle spec) */
+  public static final String WEB_CONTEXT_PATH_HEADER = "Web-ContextPath";
 
   /**
    * This method locates persistence descriptor files based on a combination of
@@ -52,12 +54,13 @@
    * header.
    * 
    * Note that getEntry is used to ensure we do not alter the state of the bundle
+   * Note also that web application bundles will never return persistence descriptors
    * 
    * @param bundle The bundle to search
    * @return
    */
   public static Collection<PersistenceDescriptor> findPersistenceXmlFiles(Bundle bundle)
-  {
+  {    
     //The files we have found
     Collection<PersistenceDescriptor> persistenceXmlFiles = new ArrayList<PersistenceDescriptor>();
     
@@ -69,6 +72,15 @@
     String header = (String) bundle.getHeaders().get(PERSISTENCE_UNIT_HEADER);
     
     if(header != null) {
+      // Do not scan WABs
+      if (bundle.getHeaders().get(WEB_CONTEXT_PATH_HEADER) != null) {
+        _logger.warn("The bundle " + bundle.getSymbolicName() + " specifies both the " +

+                    PERSISTENCE_UNIT_HEADER + " and the " + WEB_CONTEXT_PATH_HEADER + " header.
WABs that use JPA " +
+            		"are not supported as part of the OSGi JPA specification. No persistence descriptors
will be processed" +
+            		"for this bundle.");
+        return Collections.emptySet();
+      }
+      
       //Split apart the header to get the individual entries
       for(String s : header.split(","))
         locations.add(s.trim());

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=907665&r1=907664&r2=907665&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
Mon Feb  8 14:22:22 2010
@@ -64,8 +64,6 @@
 
 public class PersistenceBundleLifecycleTest
 {
-  private static final String FRAGMENT_SYM_NAME = "scooby.doo.jpa.fragment";
-  
   private Bundle persistenceBundle;
   private BundleContext persistenceBundleContext;
   
@@ -168,6 +166,29 @@
     
     assertNull("We should not have an EntityManagerFactoryManager", getTrackedObject());
   }
+  
+  @Test
+  public void testManager_WABandJPABundle() throws Exception 
+  {
+    preExistingBundleSetup();
+    setupPersistenceBundle("file23", "");
+    persistenceBundle.getHeaders().put("Web-ContextPath", "/test");
+
+    // make sure we don't succeed because of not having a provider
+    Hashtable<String,Object> hash1 = new Hashtable<String, Object>();
+    hash1.put("javax.persistence.provider", "use.this.Provider");
+    hash1.put(Constants.SERVICE_RANKING, Integer.MAX_VALUE);
+    ServiceRegistration reg = persistenceBundle.getBundleContext().registerService(new String[]
{PersistenceProvider.class.getName()} ,
+        pp, hash1 );
+    ServiceReference ppRef = reg.getReference();
+        
+    mgr.addingProvider(ppRef);
+
+    mgr.open();
+    
+    BundleContextMock.assertNoServiceExists(EntityManagerFactory.class.getName());
+    assertNull("We should not have an EntityManagerFactoryManager", getTrackedObject());
+  }
 
   @Test
   public void testManager_OnePreExistingPersistenceBundle_OneExistingProvider() throws Exception



Mime
View raw message