[jboss-cvs] JBossAS SVN: r82832 - projects/jpa/trunk/deployers/src/main/java/org/jboss/jpa/resolvers.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Jan 13 16:55:35 EST 2009


Author: wolfc
Date: 2009-01-13 16:55:35 -0500 (Tue, 13 Jan 2009)
New Revision: 82832

Added:
   projects/jpa/trunk/deployers/src/main/java/org/jboss/jpa/resolvers/InterApplicationPersistenceUnitDependencyResolver.java
Modified:
   projects/jpa/trunk/deployers/src/main/java/org/jboss/jpa/resolvers/DefaultPersistenceUnitDependencyResolver.java
Log:
JBAS-6377: find persistence units in all top level deployments

Modified: projects/jpa/trunk/deployers/src/main/java/org/jboss/jpa/resolvers/DefaultPersistenceUnitDependencyResolver.java
===================================================================
--- projects/jpa/trunk/deployers/src/main/java/org/jboss/jpa/resolvers/DefaultPersistenceUnitDependencyResolver.java	2009-01-13 21:39:15 UTC (rev 82831)
+++ projects/jpa/trunk/deployers/src/main/java/org/jboss/jpa/resolvers/DefaultPersistenceUnitDependencyResolver.java	2009-01-13 21:55:35 UTC (rev 82832)
@@ -49,7 +49,7 @@
       return "persistence.unit:unitName=" + unitName;
    }
 
-   private String findWithinApplication(DeploymentUnit unit, String persistenceUnitName)
+   protected String findWithinApplication(DeploymentUnit unit, String persistenceUnitName)
    {
       String name = findWithinModule(unit, persistenceUnitName, false);
       if(name != null)
@@ -68,7 +68,7 @@
     * When finding the default persistence unit, the first persistence unit encountered is returned.
     * TODO: Maybe the name of unscoped persistence units should be changed, so only one can be deployed anyway.
     */
-   private String findWithinModule(DeploymentUnit unit, String persistenceUnitName, boolean allowScoped)
+   protected String findWithinModule(DeploymentUnit unit, String persistenceUnitName, boolean allowScoped)
    {
       if(!allowScoped && isScoped(unit))
          return null;
@@ -84,7 +84,7 @@
       return null;
    }
    
-   private static DeploymentUnit getDeploymentUnit(DeploymentUnit current, String path)
+   protected static DeploymentUnit getDeploymentUnit(DeploymentUnit current, String path)
    {
       if(path.startsWith("/"))
          return getDeploymentUnit(current.getTopLevel(), path.substring(1));

Added: projects/jpa/trunk/deployers/src/main/java/org/jboss/jpa/resolvers/InterApplicationPersistenceUnitDependencyResolver.java
===================================================================
--- projects/jpa/trunk/deployers/src/main/java/org/jboss/jpa/resolvers/InterApplicationPersistenceUnitDependencyResolver.java	                        (rev 0)
+++ projects/jpa/trunk/deployers/src/main/java/org/jboss/jpa/resolvers/InterApplicationPersistenceUnitDependencyResolver.java	2009-01-13 21:55:35 UTC (rev 82832)
@@ -0,0 +1,98 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.jpa.resolvers;
+
+import java.util.Collection;
+
+import org.jboss.beans.metadata.api.annotations.Inject;
+import org.jboss.deployers.client.spi.Deployment;
+import org.jboss.deployers.client.spi.main.MainDeployer;
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.deployers.structure.spi.main.MainDeployerStructure;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class InterApplicationPersistenceUnitDependencyResolver extends DefaultPersistenceUnitDependencyResolver
+{
+   private MainDeployer mainDeployer;
+   
+   private MainDeployerStructure mainDeployerStructure;
+   
+   protected String findWithinMainDeployer(String persistenceUnitName)
+   {
+      Collection<Deployment> topLevelDeployments = mainDeployer.getTopLevel();
+      if(topLevelDeployments == null)
+         return null;
+      
+      for(Deployment deployment : topLevelDeployments)
+      {
+         String name = deployment.getName();
+         DeploymentUnit deploymentUnit = mainDeployerStructure.getDeploymentUnit(name);
+         if(deploymentUnit == null)
+            continue;
+         String beanName = findWithinApplication(deploymentUnit, persistenceUnitName);
+         if(beanName != null)
+            return beanName;
+      }
+      
+      return null;
+   }
+   
+   // TODO: consilidate with DefaultPersistenceUnitDependencyResolver.resolvePersistenceUnitSupplier
+   public String resolvePersistenceUnitSupplier(DeploymentUnit deploymentUnit, String persistenceUnitName)
+   {
+      int i = (persistenceUnitName == null ? -1 : persistenceUnitName.indexOf('#'));
+      if(i != -1)
+      {
+         String path = persistenceUnitName.substring(0, i);
+         String unitName = persistenceUnitName.substring(i + 1);
+         DeploymentUnit targetDeploymentUnit = getDeploymentUnit(deploymentUnit, path);
+         // TODO: verify the existence of PersistenceUnitMetaData?
+         return createBeanName(targetDeploymentUnit, unitName);
+      }
+      else
+      {
+         String name = findWithinModule(deploymentUnit, persistenceUnitName, true);
+         if(name == null)
+            name = findWithinApplication(deploymentUnit.getTopLevel(), persistenceUnitName);
+         if(name == null)
+            name = findWithinMainDeployer(persistenceUnitName);
+         if(name == null)
+            throw new IllegalArgumentException("Can't find a persistence unit named '" + persistenceUnitName + "' in " + deploymentUnit);
+         return name;
+      }
+   }
+   
+   @Inject
+   public void setMainDeployer(MainDeployer mainDeployer)
+   {
+      this.mainDeployer = mainDeployer;
+   }
+   
+   @Inject
+   public void setMainDeployerStructure(MainDeployerStructure mainDeployerStructure)
+   {
+      this.mainDeployerStructure = mainDeployerStructure;
+   }
+}




More information about the jboss-cvs-commits mailing list