[jboss-cvs] JBossAS SVN: r87328 - in projects/jpa/trunk/deployers/src: test/java/org/jboss/jpa/deployers/test and 1 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Apr 15 06:13:16 EDT 2009


Author: wolfc
Date: 2009-04-15 06:13:16 -0400 (Wed, 15 Apr 2009)
New Revision: 87328

Added:
   projects/jpa/trunk/deployers/src/test/java/org/jboss/jpa/deployers/test/jbjpa14/
   projects/jpa/trunk/deployers/src/test/java/org/jboss/jpa/deployers/test/jbjpa14/MockDeploymentContext.java
   projects/jpa/trunk/deployers/src/test/java/org/jboss/jpa/deployers/test/jbjpa14/MockDeploymentUnit.java
   projects/jpa/trunk/deployers/src/test/java/org/jboss/jpa/deployers/test/jbjpa14/MockPersistenceUnitMetaData.java
   projects/jpa/trunk/deployers/src/test/java/org/jboss/jpa/deployers/test/jbjpa14/PersistenceUnitSubclassTestCase.java
Removed:
   projects/jpa/trunk/deployers/src/main/java/org/jboss/jpa/deployers/AbstractDeploymentVisitor.java
Modified:
   projects/jpa/trunk/deployers/src/main/java/org/jboss/jpa/deployers/PersistenceDeployer.java
Log:
JPJPA-14: using AbstractDeploymentVisitor from jboss-deployers

Deleted: projects/jpa/trunk/deployers/src/main/java/org/jboss/jpa/deployers/AbstractDeploymentVisitor.java
===================================================================
--- projects/jpa/trunk/deployers/src/main/java/org/jboss/jpa/deployers/AbstractDeploymentVisitor.java	2009-04-15 10:09:17 UTC (rev 87327)
+++ projects/jpa/trunk/deployers/src/main/java/org/jboss/jpa/deployers/AbstractDeploymentVisitor.java	2009-04-15 10:13:16 UTC (rev 87328)
@@ -1,126 +0,0 @@
-/*
- * 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.deployers;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.jboss.deployers.spi.DeploymentException;
-import org.jboss.deployers.spi.deployer.helpers.DeploymentVisitor;
-import org.jboss.deployers.structure.spi.DeploymentUnit;
-import org.jboss.logging.Logger;
-
-/**
- * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
- * @version $Revision: $
- */
-public abstract class AbstractDeploymentVisitor<T, C> implements DeploymentVisitor<T>
-{
-   private static final Logger log = Logger.getLogger(AbstractDeploymentVisitor.class);
-   
-   /**
-    * Add component.
-    *
-    * @param unit the deployment unit
-    * @param componentMD the component metadata
-    */
-   protected void addComponent(DeploymentUnit unit, C componentMD)
-   {
-      String name = getName(unit, componentMD);
-      DeploymentUnit component = unit.addComponent(name);
-      // TODO: determine proper component meta data class
-      component.addAttachment(componentMD.getClass().getName(), componentMD);
-   }
-
-   public void deploy(DeploymentUnit unit, T deployment) throws DeploymentException
-   {
-      List<C> components = getComponents(deployment);
-      if (components != null && components.isEmpty() == false)
-      {
-         List<C> visited = new ArrayList<C>();
-         try
-         {
-            for (C component : components)
-            {
-               addComponent(unit, component);
-               visited.add(component);
-            }
-         }
-         catch (Throwable t)
-         {
-            for (int i = visited.size()-1; i >= 0; --i)
-            {
-               safeRemoveComponent(unit, visited.get(i));
-            }
-            throw DeploymentException.rethrowAsDeploymentException("Error deploying: " + unit.getName(), t);
-         }
-      }
-   }
-
-   protected abstract List<C> getComponents(T deployment);
-   
-   protected abstract String getName(DeploymentUnit unit, C component);
-   
-   /**
-    * Remove bean component.
-    *
-    * @param unit the deployment unit
-    * @param component the component metadata
-    */
-
-   protected void removeComponent(DeploymentUnit unit, C component)
-   {
-      String name = getName(unit, component);
-      unit.removeComponent(name);
-   }
-
-   /**
-    * Ignore all error during component removal.
-    *
-    * @param unit the deployment unit
-    * @param component the component metadata
-    */
-   protected void safeRemoveComponent(DeploymentUnit unit, C component)
-   {
-      try
-      {
-         removeComponent(unit, component);
-      }
-      catch (Throwable ignored)
-      {
-         log.warn("Error during component removal: " + unit.getName(), ignored);
-      }
-   }
-
-   public void undeploy(DeploymentUnit unit, T deployment)
-   {
-      List<C> components = getComponents(deployment);
-      if (components != null && components.isEmpty() == false)
-      {
-         for (C component : components)
-         {
-            safeRemoveComponent(unit, component);
-         }
-      }
-   }
-
-}

Modified: projects/jpa/trunk/deployers/src/main/java/org/jboss/jpa/deployers/PersistenceDeployer.java
===================================================================
--- projects/jpa/trunk/deployers/src/main/java/org/jboss/jpa/deployers/PersistenceDeployer.java	2009-04-15 10:09:17 UTC (rev 87327)
+++ projects/jpa/trunk/deployers/src/main/java/org/jboss/jpa/deployers/PersistenceDeployer.java	2009-04-15 10:13:16 UTC (rev 87328)
@@ -24,7 +24,7 @@
 import java.util.List;
 
 import org.jboss.deployers.spi.deployer.helpers.AbstractComponentDeployer;
-import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.deployers.spi.deployer.helpers.AbstractDeploymentVisitor;
 import org.jboss.logging.Logger;
 import org.jboss.metadata.jpa.spec.PersistenceMetaData;
 import org.jboss.metadata.jpa.spec.PersistenceUnitMetaData;
@@ -36,6 +36,7 @@
  */
 public class PersistenceDeployer extends AbstractComponentDeployer<PersistenceMetaData, PersistenceUnitMetaData>
 {
+   @SuppressWarnings("unused")
    private static final Logger log = Logger.getLogger(PersistenceDeployer.class);
    
    public PersistenceDeployer()
@@ -48,8 +49,25 @@
       setDeploymentVisitor(new PersistenceDeploymentVisitor());
    }
 
-   private class PersistenceDeploymentVisitor extends AbstractDeploymentVisitor<PersistenceMetaData, PersistenceUnitMetaData>
+   private class PersistenceDeploymentVisitor extends AbstractDeploymentVisitor<PersistenceUnitMetaData, PersistenceMetaData>
    {
+      @Override
+      protected String getComponentName(PersistenceUnitMetaData component)
+      {
+          // we should be OK with this name, as I don't expect multiple PUMDs with same name on same DU?
+          String pumdName = component.getName();
+          if (pumdName == null)
+             throw new IllegalStateException("Persistence unit is unnamed in " + component);
+          
+          return PersistenceUnitMetaData.class.getName() + "." + pumdName;
+      }
+      
+      @Override
+      protected Class<PersistenceUnitMetaData> getComponentType()
+      {
+         return PersistenceUnitMetaData.class;
+      }
+      
       public Class<PersistenceMetaData> getVisitorType()
       {
          return PersistenceMetaData.class;
@@ -60,16 +78,5 @@
       {
          return deployment.getPersistenceUnits();
       }
-
-      @Override
-      protected String getName(DeploymentUnit unit, PersistenceUnitMetaData component)
-      {
-         // we should be OK with this name, as I don't expect multiple PUMDs with same name on same DU?
-         String pumdName = component.getName();
-         if (pumdName == null)
-            throw new IllegalStateException("Persistence unit is unnamed in " + unit);
-         
-         return PersistenceUnitMetaData.class.getName() + "." + pumdName;
-      }
    }
 }

Added: projects/jpa/trunk/deployers/src/test/java/org/jboss/jpa/deployers/test/jbjpa14/MockDeploymentContext.java
===================================================================
--- projects/jpa/trunk/deployers/src/test/java/org/jboss/jpa/deployers/test/jbjpa14/MockDeploymentContext.java	                        (rev 0)
+++ projects/jpa/trunk/deployers/src/test/java/org/jboss/jpa/deployers/test/jbjpa14/MockDeploymentContext.java	2009-04-15 10:13:16 UTC (rev 87328)
@@ -0,0 +1,39 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, 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.deployers.test.jbjpa14;
+
+import org.jboss.deployers.structure.spi.helpers.AbstractDeploymentContext;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class MockDeploymentContext extends AbstractDeploymentContext
+{
+   /**
+    * @param name
+    */
+   public MockDeploymentContext(String name)
+   {
+      super(name, "");
+   }
+}

Added: projects/jpa/trunk/deployers/src/test/java/org/jboss/jpa/deployers/test/jbjpa14/MockDeploymentUnit.java
===================================================================
--- projects/jpa/trunk/deployers/src/test/java/org/jboss/jpa/deployers/test/jbjpa14/MockDeploymentUnit.java	                        (rev 0)
+++ projects/jpa/trunk/deployers/src/test/java/org/jboss/jpa/deployers/test/jbjpa14/MockDeploymentUnit.java	2009-04-15 10:13:16 UTC (rev 87328)
@@ -0,0 +1,42 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, 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.deployers.test.jbjpa14;
+
+import org.jboss.deployers.structure.spi.DeploymentContext;
+import org.jboss.deployers.structure.spi.helpers.AbstractDeploymentUnit;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class MockDeploymentUnit extends AbstractDeploymentUnit
+{
+   private static final long serialVersionUID = 1L;
+
+   /**
+    * @param deploymentContext
+    */
+   public MockDeploymentUnit(DeploymentContext deploymentContext)
+   {
+      super(deploymentContext);
+   }
+}

Added: projects/jpa/trunk/deployers/src/test/java/org/jboss/jpa/deployers/test/jbjpa14/MockPersistenceUnitMetaData.java
===================================================================
--- projects/jpa/trunk/deployers/src/test/java/org/jboss/jpa/deployers/test/jbjpa14/MockPersistenceUnitMetaData.java	                        (rev 0)
+++ projects/jpa/trunk/deployers/src/test/java/org/jboss/jpa/deployers/test/jbjpa14/MockPersistenceUnitMetaData.java	2009-04-15 10:13:16 UTC (rev 87328)
@@ -0,0 +1,33 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, 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.deployers.test.jbjpa14;
+
+import org.jboss.metadata.jpa.spec.PersistenceUnitMetaData;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class MockPersistenceUnitMetaData extends PersistenceUnitMetaData
+{
+   private static final long serialVersionUID = 1L;
+}

Added: projects/jpa/trunk/deployers/src/test/java/org/jboss/jpa/deployers/test/jbjpa14/PersistenceUnitSubclassTestCase.java
===================================================================
--- projects/jpa/trunk/deployers/src/test/java/org/jboss/jpa/deployers/test/jbjpa14/PersistenceUnitSubclassTestCase.java	                        (rev 0)
+++ projects/jpa/trunk/deployers/src/test/java/org/jboss/jpa/deployers/test/jbjpa14/PersistenceUnitSubclassTestCase.java	2009-04-15 10:13:16 UTC (rev 87328)
@@ -0,0 +1,91 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, 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.deployers.test.jbjpa14;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.jboss.deployers.spi.DeploymentException;
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.jpa.deployers.PersistenceDeployer;
+import org.jboss.metadata.jpa.spec.PersistenceMetaData;
+import org.jboss.metadata.jpa.spec.PersistenceUnitMetaData;
+import org.junit.Test;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class PersistenceUnitSubclassTestCase
+{
+   private static void test(String name, PersistenceUnitMetaData metaData) throws DeploymentException
+   {
+      PersistenceDeployer deployer = new PersistenceDeployer();
+      MockDeploymentContext deploymentContext = new MockDeploymentContext(name);
+      
+      List<PersistenceUnitMetaData> persistenceUnits = new ArrayList<PersistenceUnitMetaData>();
+      persistenceUnits.add(metaData);
+      
+      PersistenceMetaData attachment = new PersistenceMetaData();
+      attachment.setPersistenceUnits(persistenceUnits);
+      
+      deploymentContext.getTransientAttachments().addAttachment(PersistenceMetaData.class, attachment);
+      DeploymentUnit unit = deploymentContext.getDeploymentUnit();
+      deployer.deploy(unit);
+      
+      String componentName = "org.jboss.metadata.jpa.spec.PersistenceUnitMetaData." + metaData.getName();
+      DeploymentUnit component = unit.getComponent(componentName);
+      assertNotNull("can't find component " + componentName, component);
+      assertEquals("expected PersistenceMetaData and PersistenceUnitMetaData attachments", 2, component.getAttachments().size());
+      PersistenceUnitMetaData pu = component.getAttachment(PersistenceUnitMetaData.class);
+      assertNotNull("can't find PersistenceUnitMetaData attachment", pu);
+   }
+   
+   private static MockPersistenceUnitMetaData mockUnit(String name)
+   {
+      MockPersistenceUnitMetaData pu = new MockPersistenceUnitMetaData();
+      pu.setName(name);
+      return pu;
+   }
+   
+   private static PersistenceUnitMetaData unit(String name)
+   {
+      PersistenceUnitMetaData pu = new PersistenceUnitMetaData();
+      pu.setName(name);
+      return pu;
+   }
+   
+   @Test
+   public void testNormal() throws DeploymentException
+   {
+      test("testNormal", unit("normalunit"));
+   }
+   
+   @Test
+   public void testSubclass() throws DeploymentException
+   {
+      test("testSubclass", mockUnit("mockunit"));
+   }
+}




More information about the jboss-cvs-commits mailing list