geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hanhongf...@apache.org
Subject svn commit: r1140502 - in /geronimo/server/trunk/plugins/openjpa2/geronimo-persistence-jpa20-builder/src/main/java/org/apache/geronimo/persistence/builder: PersistenceRefBuilder.java PersistenceUnitBuilder.java
Date Tue, 28 Jun 2011 09:42:02 GMT
Author: hanhongfang
Date: Tue Jun 28 09:42:01 2011
New Revision: 1140502

URL: http://svn.apache.org/viewvc?rev=1140502&view=rev
Log:
make META-INF/persistence.xml in web module processed, and also update the persistence ref
search process to select correct one when several persistence units exist in the same ear
module

Modified:
    geronimo/server/trunk/plugins/openjpa2/geronimo-persistence-jpa20-builder/src/main/java/org/apache/geronimo/persistence/builder/PersistenceRefBuilder.java
    geronimo/server/trunk/plugins/openjpa2/geronimo-persistence-jpa20-builder/src/main/java/org/apache/geronimo/persistence/builder/PersistenceUnitBuilder.java

Modified: geronimo/server/trunk/plugins/openjpa2/geronimo-persistence-jpa20-builder/src/main/java/org/apache/geronimo/persistence/builder/PersistenceRefBuilder.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/openjpa2/geronimo-persistence-jpa20-builder/src/main/java/org/apache/geronimo/persistence/builder/PersistenceRefBuilder.java?rev=1140502&r1=1140501&r2=1140502&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/openjpa2/geronimo-persistence-jpa20-builder/src/main/java/org/apache/geronimo/persistence/builder/PersistenceRefBuilder.java
(original)
+++ geronimo/server/trunk/plugins/openjpa2/geronimo-persistence-jpa20-builder/src/main/java/org/apache/geronimo/persistence/builder/PersistenceRefBuilder.java
Tue Jun 28 09:42:01 2011
@@ -20,6 +20,8 @@ import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
 import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Map;
@@ -218,7 +220,7 @@ public class PersistenceRefBuilder exten
                     persistenceUnitNameQuery = defaultPersistenceUnitAbstractNameQuery;
                 }
             }
-            checkForGBean(localConfiguration, persistenceUnitNameQuery, false, false);
+            checkForGBean(localConfiguration, persistenceUnitNameQuery, false, false, new
HashSet<AbstractName>());
         }
         return persistenceUnitNameQuery;
     }
@@ -230,7 +232,8 @@ public class PersistenceRefBuilder exten
         nameMap.put("j2eeType", NameFactory.PERSISTENCE_UNIT);
         nameMap.put("name", persistenceUnitName);
         persistenceUnitNameQuery = new AbstractNameQuery(localConfiguration.getId(), nameMap,
PERSISTENCE_UNIT_INTERFACE_TYPES);
-        switch (checkForGBean(localConfiguration, persistenceUnitNameQuery, strictMatching,
true)) {
+        Set<AbstractName> matches = new HashSet<AbstractName>();
+        switch (checkForGBean(localConfiguration, persistenceUnitNameQuery, strictMatching,
true, matches)) {
             case 1:
                 return persistenceUnitNameQuery;
             case 0:
@@ -238,26 +241,62 @@ public class PersistenceRefBuilder exten
                 persistenceUnitName = "persistence/" + persistenceUnitName;
                 nameMap.put("name", persistenceUnitName);
                 persistenceUnitNameQuery = new AbstractNameQuery(localConfiguration.getId(),
nameMap, PERSISTENCE_UNIT_INTERFACE_TYPES);
-                if (1 == checkForGBean(localConfiguration, persistenceUnitNameQuery, false,
true)) {
+                if (1 == checkForGBean(localConfiguration, persistenceUnitNameQuery, false,
true, new HashSet<AbstractName>())) {
                     return persistenceUnitNameQuery;
                 }
-
             case 2:
         }
         //there was more than one match, and if necessary persistence/ was prepended to the
name.
         AbstractName childName = module.getEarContext().getNaming().createChildName(module.getModuleName(),
persistenceUnitName, NameFactory.PERSISTENCE_UNIT);
         persistenceUnitNameQuery = new AbstractNameQuery(localConfiguration.getId(), childName.getName(),
PERSISTENCE_UNIT_INTERFACE_TYPES);
-        checkForGBean(localConfiguration, persistenceUnitNameQuery, false, false);
-        return persistenceUnitNameQuery;
+        try {
+            checkForGBean(localConfiguration, persistenceUnitNameQuery, false, false, new
HashSet<AbstractName>());
+            return persistenceUnitNameQuery;
+        } catch (DeploymentException e) {
+            // 
+            for (Iterator<AbstractName> i = matches.iterator(); i.hasNext();) {
+                AbstractName abstractName = i.next();
+                if (isParentModule(abstractName.getName(), childName.getName())) {
+                    return new AbstractNameQuery(abstractName.getArtifact(), abstractName.getName(),
PERSISTENCE_UNIT_INTERFACE_TYPES);
+                }
+            }            
+            throw e;
+        }
+    }
+
+    private static String getModuleType(Map name) {
+        if (name.containsKey(NameFactory.WEB_MODULE))  {
+            return NameFactory.WEB_MODULE;
+        } else if (name.containsKey(NameFactory.EJB_MODULE)) {
+            return NameFactory.EJB_MODULE;
+        } else if (name.containsKey(NameFactory.APP_CLIENT_MODULE)) {
+            return NameFactory.APP_CLIENT_MODULE;
+        } else if (name.containsKey(NameFactory.APP_CLIENT_MODULE)) {
+            return NameFactory.APP_CLIENT_MODULE;
+        } else {
+            return null;
+        }            
+    }    
+    
+    private boolean isParentModule(Map parent, Map child) {
+        String parentModuleType = getModuleType(parent);
+        String childModuleType = getModuleType(child);
+        if (parentModuleType == null && childModuleType != null) {
+            return true;
+        } else {
+            return false;
+        }
     }
+    
 
-    private static int checkForGBean(Configuration localConfiguration, AbstractNameQuery
persistenceQuery, boolean allowNone, boolean allowMultiple) throws DeploymentException {
+    private static int checkForGBean(Configuration localConfiguration, AbstractNameQuery
persistenceQuery, boolean allowNone, boolean allowMultiple, Set<AbstractName> matches)
throws DeploymentException {
         try {
             localConfiguration.findGBeanData(persistenceQuery);
             return 1;
         } catch (GBeanNotFoundException e) {
             if (e.hasMatches()) {
                 if (allowMultiple) {
+                    matches.addAll(e.getMatches());
                     return 2;
                 }
                 throw new DeploymentException("More than one reference at deploy time for
query " + persistenceQuery + ". " + e.getMatches(), e);
@@ -302,7 +341,7 @@ public class PersistenceRefBuilder exten
 
             persistenceUnitNameQuery = buildAbstractNameQuery(gbeanLocator, null, null, PERSISTENCE_UNIT_INTERFACE_TYPES);
         }
-        checkForGBean(localConfiguration, persistenceUnitNameQuery, false, false);
+        checkForGBean(localConfiguration, persistenceUnitNameQuery, false, false, new HashSet<AbstractName>());
         return persistenceUnitNameQuery;
     }
 
@@ -316,7 +355,7 @@ public class PersistenceRefBuilder exten
 
             persistenceUnitNameQuery = buildAbstractNameQuery(gbeanLocator, null, null, PERSISTENCE_UNIT_INTERFACE_TYPES);
         }
-        checkForGBean(localConfiguration, persistenceUnitNameQuery, false, false);
+        checkForGBean(localConfiguration, persistenceUnitNameQuery, false, false, new HashSet<AbstractName>());
         return persistenceUnitNameQuery;
     }
 

Modified: geronimo/server/trunk/plugins/openjpa2/geronimo-persistence-jpa20-builder/src/main/java/org/apache/geronimo/persistence/builder/PersistenceUnitBuilder.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/openjpa2/geronimo-persistence-jpa20-builder/src/main/java/org/apache/geronimo/persistence/builder/PersistenceUnitBuilder.java?rev=1140502&r1=1140501&r2=1140502&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/openjpa2/geronimo-persistence-jpa20-builder/src/main/java/org/apache/geronimo/persistence/builder/PersistenceUnitBuilder.java
(original)
+++ geronimo/server/trunk/plugins/openjpa2/geronimo-persistence-jpa20-builder/src/main/java/org/apache/geronimo/persistence/builder/PersistenceUnitBuilder.java
Tue Jun 28 09:42:01 2011
@@ -23,6 +23,7 @@ import java.net.URL;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashMap;
+import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Properties;
@@ -137,11 +138,27 @@ public class PersistenceUnitBuilder impl
         }
         try {
 
+            final Collection<String> manifestcpCopy = new LinkedHashSet<String>
();
+            boolean resolveWARcp = false;
+            
+            // resolve the classpath for non-standalone war file since module.getClassPath

+            // returns the classpath relative to the war file
+            if (!module.isStandAlone() && module.getType() == ConfigurationModuleType.WAR)
{
+                resolveWARcp = true;
+            } 
+            
             final Collection<String> manifestcp = module.getClassPath();
+            for (String classpath : manifestcp) {
+                if (resolveWARcp) {
+                    manifestcpCopy.add(module.resolve(classpath).toString());           
        
+                } else {
+                    manifestcpCopy.add(classpath);
+                }
+            }
             
-            // add "" into manifestcp to make META-INF/persistence.xml in standalone ejb
be processed
+            // add "" into manifestcpCopy to make META-INF/persistence.xml in standalone
ejb be processed
             if (module.isStandAlone() && module.getType() == ConfigurationModuleType.EJB)
{
-                manifestcp.add("");
+                manifestcpCopy.add("");
             }
             
             BundleResourceFinder finder = new BundleResourceFinder(packageAdmin, bundle,
"", "META-INF/persistence.xml", new ResourceDiscoveryFilter() {
@@ -153,16 +170,16 @@ public class PersistenceUnitBuilder impl
 
                 @Override
                 public boolean zipFileDiscoveryRequired(String s) {
-                    return manifestcp.contains(s);
+                    return manifestcpCopy.contains(s);
                 }
 
                 @Override
                 public boolean directoryDiscoveryRequired(String s) {
                     
                     boolean found = false;
-                    if (manifestcp.contains(s)){
+                    if (manifestcpCopy.contains(s)){
                         found=true;
-                    } else if(s.endsWith("/") && manifestcp.contains(s.substring(0,s.length()-1))){
+                    } else if(s.endsWith("/") && manifestcpCopy.contains(s.substring(0,s.length()-1))){
                         found=true;
                     }
                     



Mime
View raw message