Return-Path: X-Original-To: apmail-geronimo-scm-archive@www.apache.org Delivered-To: apmail-geronimo-scm-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 119264B7A for ; Thu, 7 Jul 2011 15:04:52 +0000 (UTC) Received: (qmail 91991 invoked by uid 500); 7 Jul 2011 15:04:51 -0000 Delivered-To: apmail-geronimo-scm-archive@geronimo.apache.org Received: (qmail 91940 invoked by uid 500); 7 Jul 2011 15:04:51 -0000 Mailing-List: contact scm-help@geronimo.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: dev@geronimo.apache.org List-Id: Delivered-To: mailing list scm@geronimo.apache.org Received: (qmail 91933 invoked by uid 99); 7 Jul 2011 15:04:50 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 07 Jul 2011 15:04:50 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 07 Jul 2011 15:04:47 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 5B85423888CB; Thu, 7 Jul 2011 15:04:26 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: scm@geronimo.apache.org From: xuhaihong@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20110707150426.5B85423888CB@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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 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 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 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 nameMap = new HashMap(); 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 matches = new HashSet(); switch (checkForGBean(localConfiguration, persistenceUnitNameQuery, strictMatching, true, matches)) { case 1: @@ -240,7 +241,7 @@ public class PersistenceRefBuilder exten //try unrestricted search on name persistence/ 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())) { 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()); return persistenceUnitNameQuery; } catch (DeploymentException e) { - // + // for (Iterator 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 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) {