geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From xuhaih...@apache.org
Subject svn commit: r1143864 - in /geronimo/server/trunk: framework/modules/geronimo-naming/src/main/java/org/apache/geronimo/naming/reference/ plugins/openjpa2/geronimo-persistence-jpa20-builder/src/main/java/org/apache/geronimo/persistence/builder/
Date Thu, 07 Jul 2011 15:04:26 GMT
Author: xuhaihong
Date: Thu Jul  7 15:04:25 2011
New Revision: 1143864

URL: http://svn.apache.org/viewvc?rev=1143864&view=rev
Log:
a. Make the persistence unit/context query be compatible for both client and server side
b. ConfigurationAwareReference could work without no artifact id

Modified:
    geronimo/server/trunk/framework/modules/geronimo-naming/src/main/java/org/apache/geronimo/naming/reference/ConfigurationAwareReference.java
    geronimo/server/trunk/plugins/openjpa2/geronimo-persistence-jpa20-builder/src/main/java/org/apache/geronimo/persistence/builder/PersistenceRefBuilder.java

Modified: geronimo/server/trunk/framework/modules/geronimo-naming/src/main/java/org/apache/geronimo/naming/reference/ConfigurationAwareReference.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-naming/src/main/java/org/apache/geronimo/naming/reference/ConfigurationAwareReference.java?rev=1143864&r1=1143863&r2=1143864&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-naming/src/main/java/org/apache/geronimo/naming/reference/ConfigurationAwareReference.java
(original)
+++ geronimo/server/trunk/framework/modules/geronimo-naming/src/main/java/org/apache/geronimo/naming/reference/ConfigurationAwareReference.java
Thu Jul  7 15:04:25 2011
@@ -48,14 +48,14 @@ public abstract class ConfigurationAware
     }
 
     protected ConfigurationAwareReference(Artifact[] configId, Set<AbstractNameQuery>
abstractNameQueries) {
-        if (configId == null || configId.length == 0) {
-            throw new NullPointerException("No configId");
-        }
         this.configId = configId;
         this.abstractNameQueries = abstractNameQueries;
     }
 
     public Configuration getConfiguration() throws GBeanNotFoundException {
+        if(configId == null || configId.length == 0) {
+            return null;
+        }
         Kernel kernel = getKernel();
         ConfigurationManager configurationManager = ConfigurationUtil.getConfigurationManager(kernel);
         Configuration configuration =  configurationManager.getConfiguration(configId[0]);
@@ -66,7 +66,7 @@ public abstract class ConfigurationAware
                     return configuration;
                 }
             }
-            throw new IllegalStateException("No configuration found for id: " + configId[0]);
+            return null;
         }
         next: for (int i = 1; i < configId.length; i++) {
             List<Configuration> children = configuration.getChildren();
@@ -76,22 +76,30 @@ public abstract class ConfigurationAware
                     break next;
                 }
             }
-            throw new GBeanNotFoundException("No configuration found for id: " + configId[i],
null);
+            return null;
         }
         return configuration;
     }
 
     public AbstractName resolveTargetName() throws GBeanNotFoundException {
+        AbstractName gbeanAbName = null;
         Configuration configuration = getConfiguration();
         try {
-            return configuration.findGBean(abstractNameQueries);
+            if (configuration != null) {
+                gbeanAbName = configuration.findGBean(abstractNameQueries);
+            }
         } catch (GBeanNotFoundException e) {
-            Set results = getKernel().listGBeans(abstractNameQueries);
+            //Ignore this
+        }
+        if (gbeanAbName == null) {
+            Set<AbstractName> results = getKernel().listGBeans(abstractNameQueries);
             if (results.size() == 1) {
-                return (AbstractName) results.iterator().next();
+                return results.iterator().next();
+            } else {
+                throw new GBeanNotFoundException("ConfigurationAwareReference", abstractNameQueries,
results);
             }
-            throw new GBeanNotFoundException("Name query " + abstractNameQueries + " not
satisfied in kernel, matches: " + results, e);
         }
+        return gbeanAbName;
     }
 
 }

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=1143864&r1=1143863&r2=1143864&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
Thu Jul  7 15:04:25 2011
@@ -231,7 +231,8 @@ public class PersistenceRefBuilder exten
         Map<String, String> nameMap = new HashMap<String, String>();
         nameMap.put("j2eeType", NameFactory.PERSISTENCE_UNIT);
         nameMap.put("name", persistenceUnitName);
-        persistenceUnitNameQuery = new AbstractNameQuery(localConfiguration.getId(), nameMap,
PERSISTENCE_UNIT_INTERFACE_TYPES);
+        //Do not set configId, so the query will work on both server and application client
sides
+        persistenceUnitNameQuery = new AbstractNameQuery(null, nameMap, PERSISTENCE_UNIT_INTERFACE_TYPES);
         Set<AbstractName> matches = new HashSet<AbstractName>();
         switch (checkForGBean(localConfiguration, persistenceUnitNameQuery, strictMatching,
true, matches)) {
             case 1:
@@ -240,7 +241,7 @@ public class PersistenceRefBuilder exten
                 //try unrestricted search on name persistence/<name>
                 persistenceUnitName = "persistence/" + persistenceUnitName;
                 nameMap.put("name", persistenceUnitName);
-                persistenceUnitNameQuery = new AbstractNameQuery(localConfiguration.getId(),
nameMap, PERSISTENCE_UNIT_INTERFACE_TYPES);
+                persistenceUnitNameQuery = new AbstractNameQuery(null, nameMap, PERSISTENCE_UNIT_INTERFACE_TYPES);
                 if (1 == checkForGBean(localConfiguration, persistenceUnitNameQuery, false,
true, new HashSet<AbstractName>())) {
                     return persistenceUnitNameQuery;
                 }
@@ -248,18 +249,18 @@ public class PersistenceRefBuilder exten
         }
         //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);
+        persistenceUnitNameQuery = new AbstractNameQuery(null, childName.getName(), PERSISTENCE_UNIT_INTERFACE_TYPES);
         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;
         }
     }
@@ -275,9 +276,9 @@ public class PersistenceRefBuilder exten
             return NameFactory.APP_CLIENT_MODULE;
         } else {
             return null;
-        }            
-    }    
-    
+        }
+    }
+
     private boolean isParentModule(Map parent, Map child) {
         String parentModuleType = getModuleType(parent);
         String childModuleType = getModuleType(child);
@@ -287,7 +288,7 @@ public class PersistenceRefBuilder exten
             return false;
         }
     }
-    
+
 
     private static int checkForGBean(Configuration localConfiguration, AbstractNameQuery
persistenceQuery, boolean allowNone, boolean allowMultiple, Set<AbstractName> matches)
throws DeploymentException {
         try {
@@ -316,7 +317,7 @@ public class PersistenceRefBuilder exten
             if ("cmp".equals(nameMap.get("name"))) {
                 it.remove();
             } else {
-                persistenceUnitNameQuery = new AbstractNameQuery(name);
+                persistenceUnitNameQuery = new AbstractNameQuery(null, name.getName());
             }
         }
         if (gbeans.size() > 1) {



Mime
View raw message