geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ga...@apache.org
Subject svn commit: r997073 - in /geronimo/server/trunk/plugins/openjpa2: geronimo-persistence-jpa20/src/main/java/org/apache/geronimo/persistence/ geronimo-persistence-jpa20/src/test/java/org/apache/geronimo/persistence/ persistence-jpa20-deployer/src/main/plan/
Date Tue, 14 Sep 2010 20:16:47 GMT
Author: gawor
Date: Tue Sep 14 20:16:47 2010
New Revision: 997073

URL: http://svn.apache.org/viewvc?rev=997073&view=rev
Log:
GERONIMO-5606: An attempt to generate a proper persistenceUnitRoot for a PU. The PU relies
on BundleResourceClassLoader which returns 'jar' urls for resources embedded in jars.

Modified:
    geronimo/server/trunk/plugins/openjpa2/geronimo-persistence-jpa20/src/main/java/org/apache/geronimo/persistence/PersistenceUnitGBean.java
    geronimo/server/trunk/plugins/openjpa2/geronimo-persistence-jpa20/src/test/java/org/apache/geronimo/persistence/PersistenceUnitGBeanTest.java
    geronimo/server/trunk/plugins/openjpa2/persistence-jpa20-deployer/src/main/plan/plan.xml

Modified: geronimo/server/trunk/plugins/openjpa2/geronimo-persistence-jpa20/src/main/java/org/apache/geronimo/persistence/PersistenceUnitGBean.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/openjpa2/geronimo-persistence-jpa20/src/main/java/org/apache/geronimo/persistence/PersistenceUnitGBean.java?rev=997073&r1=997072&r2=997073&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/openjpa2/geronimo-persistence-jpa20/src/main/java/org/apache/geronimo/persistence/PersistenceUnitGBean.java
(original)
+++ geronimo/server/trunk/plugins/openjpa2/geronimo-persistence-jpa20/src/main/java/org/apache/geronimo/persistence/PersistenceUnitGBean.java
Tue Sep 14 20:16:47 2010
@@ -17,6 +17,7 @@
 
 package org.apache.geronimo.persistence;
 
+import java.io.IOException;
 import java.net.MalformedURLException;
 import java.net.URI;
 import java.net.URISyntaxException;
@@ -53,6 +54,7 @@ import org.apache.geronimo.kernel.classl
 import org.apache.geronimo.naming.ResourceSource;
 import org.apache.geronimo.transaction.manager.TransactionManagerImpl;
 import org.apache.geronimo.transformer.TransformerAgent;
+import org.apache.xbean.osgi.bundle.util.BundleResourceClassLoader;
 import org.osgi.framework.Bundle;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -90,17 +92,19 @@ public class PersistenceUnitGBean implem
                                 @ParamAttribute(name = "validationMode") ValidationMode validationMode,
                                 @ParamReference(name = "ValidatorFactory", namingType = NameFactory.VALIDATOR_FACTORY)
ValidatorFactoryGBean validatorFactory,
                                 @ParamSpecial(type = SpecialAttributeType.bundle) Bundle
bundle,
-                                @ParamSpecial(type = SpecialAttributeType.classLoader) ClassLoader
classLoader) throws URISyntaxException, MalformedURLException, ResourceException {
+                                @ParamSpecial(type = SpecialAttributeType.classLoader) ClassLoader
classLoader) throws URISyntaxException, IOException, ResourceException {
         List<String> mappingFileNames = mappingFileNamesUntyped == null ? NO_STRINGS
: new ArrayList<String>(mappingFileNamesUntyped);
         this.persistenceUnitRoot = persistenceUnitRoot;
-        URI rootUri = new URI(persistenceUnitRoot);
-        URL rootURL = bundle.getResource(persistenceUnitRoot);
+        
+        URL rootURL = getPersistenceUnitRoot(bundle, persistenceUnitRoot);
+        URI rootUri = rootURL.toURI();
+        
         List<URL> jarFileUrls = NO_URLS;
         if (!excludeUnlistedClassesValue) {
             jarFileUrls = new ArrayList<URL>();
             //Per the EJB3.0 Persistence Specification section 6.2, the jar-file should be
related to the Persistence Unit Root, which is the jar or directory where the persistence.xml
is found             
             for (String urlString : jarFileUrlsUntyped) {
-                URL url = bundle.getResource(rootUri.resolve(urlString).toString());
+                URL url = rootUri.resolve(urlString).toURL();
                 if (url != null) {
                     jarFileUrls.add(url);
                 } else {
@@ -108,6 +112,9 @@ public class PersistenceUnitGBean implem
                 }
             }
         }
+        
+        classLoader = new BundleResourceClassLoader(bundle);
+        
         if (managedClassNames == null) {
             managedClassNames = NO_STRINGS;
         }
@@ -118,8 +125,10 @@ public class PersistenceUnitGBean implem
         properties.put("javax.persistence.validation.factory", validatorFactory.getFactory());
         PersistenceUnitTransactionType persistenceUnitTransactionType = persistenceUnitTransactionTypeString
== null ? PersistenceUnitTransactionType.JTA : PersistenceUnitTransactionType.valueOf(persistenceUnitTransactionTypeString);
 
-        if (persistenceProviderClassName == null) persistenceProviderClassName = "org.apache.openjpa.persistence.PersistenceProviderImpl";
-
+        if (persistenceProviderClassName == null) {
+            persistenceProviderClassName = "org.apache.openjpa.persistence.PersistenceProviderImpl";
+        }
+        
         persistenceUnitInfo = new PersistenceUnitInfoImpl(persistenceUnitName,
                 persistenceProviderClassName,
                 persistenceUnitTransactionType,
@@ -152,7 +161,17 @@ public class PersistenceUnitGBean implem
         this.transactionManager = transactionManager;
         this.entityManagerRegistry = new SingleElementCollection<ExtendedEntityManagerRegistry>(entityManagerRegistry);
     }
-
+    
+    private static URL getPersistenceUnitRoot(Bundle bundle, String persistenceUnitRoot)
throws MalformedURLException {
+        if (persistenceUnitRoot == null || persistenceUnitRoot.equals(".")) {
+            return bundle.getEntry("/");
+        } else if (persistenceUnitRoot.endsWith("/")) {
+            return bundle.getEntry(persistenceUnitRoot);
+        } else {
+            return new URL("jar:" + bundle.getEntry(persistenceUnitRoot) + "!/");
+        }        
+    }
+    
     public EntityManagerFactory getEntityManagerFactory() {
         return entityManagerFactory;
     }
@@ -171,7 +190,6 @@ public class PersistenceUnitGBean implem
         return persistenceUnitInfo.getPersistenceUnitName();
     }
 
-
     public String getPersistenceUnitRoot() {
         return persistenceUnitRoot;
     }

Modified: geronimo/server/trunk/plugins/openjpa2/geronimo-persistence-jpa20/src/test/java/org/apache/geronimo/persistence/PersistenceUnitGBeanTest.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/openjpa2/geronimo-persistence-jpa20/src/test/java/org/apache/geronimo/persistence/PersistenceUnitGBeanTest.java?rev=997073&r1=997072&r2=997073&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/openjpa2/geronimo-persistence-jpa20/src/test/java/org/apache/geronimo/persistence/PersistenceUnitGBeanTest.java
(original)
+++ geronimo/server/trunk/plugins/openjpa2/geronimo-persistence-jpa20/src/test/java/org/apache/geronimo/persistence/PersistenceUnitGBeanTest.java
Tue Sep 14 20:16:47 2010
@@ -18,6 +18,8 @@
 package org.apache.geronimo.persistence;
 
 import java.io.File;
+import java.net.URL;
+import java.util.Arrays;
 
 import javax.persistence.spi.PersistenceUnitInfo;
 import javax.persistence.SharedCacheMode;
@@ -37,29 +39,33 @@ public class PersistenceUnitGBeanTest ex
 //    }
     
     public void testNonNullJavaFileUrls() throws Exception {
+        URL url = getClass().getClassLoader().getResource(getClass().getName().replace('.',
'/') + ".class");
+        String base = url.toString().substring(0, url.toString().lastIndexOf('/')) + "/";
+        MockBundle bundle = new MockBundle(getClass().getClassLoader(), base, 0L);
         PersistenceUnitGBean gbean = new PersistenceUnitGBean("foo",
                 null,
                 "JTA",
                 null,
                 null,
                 null,
-                null,
+                Arrays.asList("foo.jar"),
                 "/",
                 null,
-                true,
+                false,
                 null,
                 null,
                 null,
                 "2.0",
                 SharedCacheMode.NONE,
                 ValidationMode.AUTO,
-                new ValidatorFactoryGBean("Dummy", new MockBundle(getClass().getClassLoader(),
"", 0L), getClass().getClassLoader(), null), 
-                new MockBundle(getClass().getClassLoader(), "", 0L),
+                new ValidatorFactoryGBean("Dummy", bundle, getClass().getClassLoader(), null),

+                bundle,
                 getClass().getClassLoader());
         assertNotNull(gbean.getManagedClassNames());
         assertNotNull(gbean.getProperties());
         assertNotNull(gbean.getJarFileUrls());
-//        assertNotNull(gbean.getPersistenceUnitRootUrl());
+        assertEquals(Arrays.asList(new URL(base + "foo.jar")), gbean.getJarFileUrls());
+        assertEquals(new URL(base), gbean.getPersistenceUnitRootUrl());
         assertNotNull(gbean.getPersistenceProviderClassName());
     }
 }

Modified: geronimo/server/trunk/plugins/openjpa2/persistence-jpa20-deployer/src/main/plan/plan.xml
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/openjpa2/persistence-jpa20-deployer/src/main/plan/plan.xml?rev=997073&r1=997072&r2=997073&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/openjpa2/persistence-jpa20-deployer/src/main/plan/plan.xml
(original)
+++ geronimo/server/trunk/plugins/openjpa2/persistence-jpa20-deployer/src/main/plan/plan.xml
Tue Sep 14 20:16:47 2010
@@ -27,7 +27,6 @@
             openjpa.Log=commons
             openjpa.jdbc.DBDictionary=org.apache.openjpa.jdbc.sql.DerbyDictionary
             openjpa.jdbc.SynchronizeMappings=buildSchema(ForeignKeys=true)
-            openjpa.jdbc.UpdateManager=operation-order
             openjpa.Sequence=table(Table=OPENJPASEQ, Increment=100)
         </attribute>
         <xml-attribute name="defaultEnvironment">



Mime
View raw message