[jboss-cvs] JBossAS SVN: r100259 - in branches/JBPAPP_5_0: server/src/main/org/jboss/ejb/plugins/cmp/jdbc2 and 13 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Feb 2 10:06:01 EST 2010


Author: alex.loubyansky at jboss.com
Date: 2010-02-02 10:06:00 -0500 (Tue, 02 Feb 2010)
New Revision: 100259

Added:
   branches/JBPAPP_5_0/testsuite/src/main/org/jboss/test/cmp2/jdbc2pm/
   branches/JBPAPP_5_0/testsuite/src/main/org/jboss/test/cmp2/jdbc2pm/ejbstore/
   branches/JBPAPP_5_0/testsuite/src/main/org/jboss/test/cmp2/jdbc2pm/ejbstore/ejb/
   branches/JBPAPP_5_0/testsuite/src/main/org/jboss/test/cmp2/jdbc2pm/ejbstore/ejb/ABean.java
   branches/JBPAPP_5_0/testsuite/src/main/org/jboss/test/cmp2/jdbc2pm/ejbstore/ejb/ALocal.java
   branches/JBPAPP_5_0/testsuite/src/main/org/jboss/test/cmp2/jdbc2pm/ejbstore/ejb/ALocalHome.java
   branches/JBPAPP_5_0/testsuite/src/main/org/jboss/test/cmp2/jdbc2pm/ejbstore/ejb/BBean.java
   branches/JBPAPP_5_0/testsuite/src/main/org/jboss/test/cmp2/jdbc2pm/ejbstore/ejb/BLocal.java
   branches/JBPAPP_5_0/testsuite/src/main/org/jboss/test/cmp2/jdbc2pm/ejbstore/ejb/BLocalHome.java
   branches/JBPAPP_5_0/testsuite/src/main/org/jboss/test/cmp2/jdbc2pm/ejbstore/test/
   branches/JBPAPP_5_0/testsuite/src/main/org/jboss/test/cmp2/jdbc2pm/ejbstore/test/JDBC2PmEjbStoreUnitTestCase.java
   branches/JBPAPP_5_0/testsuite/src/resources/cmp2/jdbc2pm/
   branches/JBPAPP_5_0/testsuite/src/resources/cmp2/jdbc2pm/ejbstore/
   branches/JBPAPP_5_0/testsuite/src/resources/cmp2/jdbc2pm/ejbstore/META-INF/
   branches/JBPAPP_5_0/testsuite/src/resources/cmp2/jdbc2pm/ejbstore/META-INF/ejb-jar.xml
   branches/JBPAPP_5_0/testsuite/src/resources/cmp2/jdbc2pm/ejbstore/META-INF/jboss.xml
   branches/JBPAPP_5_0/testsuite/src/resources/cmp2/jdbc2pm/ejbstore/META-INF/jbosscmp-jdbc.xml
   branches/JBPAPP_5_0/testsuite/src/resources/cmp2/jdbc2pm/ejbstore/b/
   branches/JBPAPP_5_0/testsuite/src/resources/cmp2/jdbc2pm/ejbstore/b/META-INF/
   branches/JBPAPP_5_0/testsuite/src/resources/cmp2/jdbc2pm/ejbstore/b/META-INF/ejb-jar.xml
   branches/JBPAPP_5_0/testsuite/src/resources/cmp2/jdbc2pm/ejbstore/b/META-INF/jboss.xml
   branches/JBPAPP_5_0/testsuite/src/resources/cmp2/jdbc2pm/ejbstore/b/META-INF/jbosscmp-jdbc.xml
Modified:
   branches/JBPAPP_5_0/server/src/main/org/jboss/ejb/GlobalTxEntityMap.java
   branches/JBPAPP_5_0/server/src/main/org/jboss/ejb/plugins/cmp/jdbc2/JDBCStoreManager2.java
   branches/JBPAPP_5_0/server/src/main/org/jboss/ejb/plugins/cmp/jdbc2/schema/Schema.java
   branches/JBPAPP_5_0/testsuite/imports/sections/cmp.xml
Log:
JBPAPP-2775

Modified: branches/JBPAPP_5_0/server/src/main/org/jboss/ejb/GlobalTxEntityMap.java
===================================================================
--- branches/JBPAPP_5_0/server/src/main/org/jboss/ejb/GlobalTxEntityMap.java	2010-02-02 14:57:58 UTC (rev 100258)
+++ branches/JBPAPP_5_0/server/src/main/org/jboss/ejb/GlobalTxEntityMap.java	2010-02-02 15:06:00 UTC (rev 100259)
@@ -31,7 +31,10 @@
 import javax.transaction.SystemException;
 import javax.transaction.Transaction;
 import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 /**
  * This class provides a way to find out what entities are contained in
@@ -242,10 +245,7 @@
       }
    }
 
-   /**
-    * associate instance with transaction
-    */
-   private void associate(Transaction tx, EntityEnterpriseContext entity)
+   public GlobalTxSynchronization getGlobalSynchronization(Transaction tx)
       throws RollbackException, SystemException
    {
       GlobalTxSynchronization globalSync = (GlobalTxSynchronization) txSynch.get(tx);
@@ -255,7 +255,22 @@
          txSynch.set(tx, globalSync);
          tx.registerSynchronization(globalSync);
       }
+      return globalSync;
+   }
+   
+   public Transaction getTransaction()
+   {
+      return txSynch.getTransaction();
+   }
 
+   /**
+    * associate instance with transaction
+    */
+   private void associate(Transaction tx, EntityEnterpriseContext entity)
+      throws RollbackException, SystemException
+   {
+      GlobalTxSynchronization globalSync = getGlobalSynchronization(tx);
+
       //There should be only one thread associated with this tx at a time.
       //Therefore we should not need to synchronize on entityFifoList to ensure exclusive
       //access.  entityFifoList is correct since it was obtained in a synch block.
@@ -268,17 +283,49 @@
    /**
     * A list of instances associated with the transaction.
     */
-   private class GlobalTxSynchronization implements Synchronization
+   public static class GlobalTxSynchronization implements Synchronization
    {
       private Transaction tx;
       private List instances = new ArrayList();
       private boolean synchronizing;
 
+      private List<Synchronization> otherSync = Collections.emptyList();
+      private Map<Object, Object> txLocals = Collections.emptyMap();
+
       public GlobalTxSynchronization(Transaction tx)
       {
          this.tx = tx;
       }
 
+      public void addSynchronization(Synchronization sync)
+      {
+         if(otherSync.isEmpty())
+            otherSync = Collections.singletonList(sync);
+         else
+         {
+            if(otherSync.size() == 1)
+               otherSync = new ArrayList<Synchronization>(otherSync);
+            otherSync.add(sync);
+         }
+      }
+      
+      public void putTxLocal(Object key, Object value)
+      {
+         if(txLocals.isEmpty())
+            txLocals = Collections.singletonMap(key, value);
+         else
+          {
+            if(txLocals.size() == 1)
+               txLocals = new HashMap<Object, Object>(txLocals);
+            txLocals.put(key, value);
+          }
+      }
+
+      public Object getTxLocal(Object key)
+      {
+         return txLocals.get(key);
+      }
+
       public void associate(EntityEnterpriseContext ctx)
       {
          instances.add(ctx);
@@ -376,11 +423,19 @@
          // let the runtime exceptions fall out, so the committer can determine
          // the root cause of a rollback
          synchronize();
+
+         for(Synchronization sync : otherSync)
+         {
+            sync.beforeCompletion();
+         }
       }
 
       public void afterCompletion(int status)
       {
-         //no-op
+         for(Synchronization sync : otherSync)
+         {
+            sync.afterCompletion(status);
+         }
       }
    }
 }

Modified: branches/JBPAPP_5_0/server/src/main/org/jboss/ejb/plugins/cmp/jdbc2/JDBCStoreManager2.java
===================================================================
--- branches/JBPAPP_5_0/server/src/main/org/jboss/ejb/plugins/cmp/jdbc2/JDBCStoreManager2.java	2010-02-02 14:57:58 UTC (rev 100258)
+++ branches/JBPAPP_5_0/server/src/main/org/jboss/ejb/plugins/cmp/jdbc2/JDBCStoreManager2.java	2010-02-02 15:06:00 UTC (rev 100259)
@@ -100,7 +100,7 @@
       schema = (Schema)getApplicationData(SCHEMA);
       if(schema == null)
       {
-         schema = new Schema();
+         schema = new Schema(container.getEjbModule().getServiceName().getCanonicalName());
          putApplicationData(SCHEMA, schema);
       }
       return schema;

Modified: branches/JBPAPP_5_0/server/src/main/org/jboss/ejb/plugins/cmp/jdbc2/schema/Schema.java
===================================================================
--- branches/JBPAPP_5_0/server/src/main/org/jboss/ejb/plugins/cmp/jdbc2/schema/Schema.java	2010-02-02 14:57:58 UTC (rev 100258)
+++ branches/JBPAPP_5_0/server/src/main/org/jboss/ejb/plugins/cmp/jdbc2/schema/Schema.java	2010-02-02 15:06:00 UTC (rev 100259)
@@ -21,17 +21,19 @@
  */
 package org.jboss.ejb.plugins.cmp.jdbc2.schema;
 
+import org.jboss.ejb.EntityContainer;
+import org.jboss.ejb.GlobalTxEntityMap;
+import org.jboss.ejb.GlobalTxEntityMap.GlobalTxSynchronization;
 import org.jboss.ejb.plugins.cmp.jdbc.metadata.JDBCEntityMetaData;
 import org.jboss.ejb.plugins.cmp.jdbc2.bridge.JDBCEntityBridge2;
 import org.jboss.ejb.plugins.cmp.jdbc2.bridge.JDBCCMRFieldBridge2;
 import org.jboss.deployment.DeploymentException;
-import org.jboss.tm.TransactionLocal;
 
 import javax.ejb.EJBException;
+import javax.transaction.RollbackException;
 import javax.transaction.Synchronization;
-import javax.transaction.RollbackException;
+import javax.transaction.Status;
 import javax.transaction.SystemException;
-import javax.transaction.Status;
 import javax.transaction.Transaction;
 import java.sql.SQLException;
 
@@ -41,41 +43,18 @@
  */
 public class Schema
 {
+   private final String viewsTxLocalKey;
+
    private EntityTable[] entityTables;
    private RelationTable[] relationTables;
 
-   private TransactionLocal localViews = new TransactionLocal()
+   private GlobalTxEntityMap txLocal = EntityContainer.getGlobalTxEntityMap();
+
+   public Schema(String ejbModuleName)
    {
-      protected Object initialValue()
-      {
-         Transaction tx = getTransaction();
+	  this.viewsTxLocalKey = ejbModuleName + ".schema.views";
+   }
 
-         if(tx == null)
-         {
-            throw new IllegalStateException("An operation requires an active transaction!");
-         }
-
-         Views views = new Views(tx);
-         Synchronization sync = new SchemaSynchronization(views);
-
-         try
-         {
-            tx.registerSynchronization(sync);
-         }
-         catch(RollbackException e)
-         {
-            throw new EJBException("Transaction already marked to roll back: " + e.getMessage(), e);
-         }
-         catch(SystemException e)
-         {
-            e.printStackTrace();
-            throw new IllegalStateException("Failed to register transaction synchronization: " + e.getMessage());
-         }
-
-         return views;
-      }
-   };
-
    public EntityTable createEntityTable(JDBCEntityMetaData metadata, JDBCEntityBridge2 entity)
       throws DeploymentException
    {
@@ -116,7 +95,7 @@
 
    public Table.View getView(EntityTable table)
    {
-      Views views = (Views) localViews.get();
+      Views views = getViews();
       Table.View view = views.entityViews[table.getTableId()];
       if(view == null)
       {
@@ -128,7 +107,7 @@
 
    public Table.View getView(RelationTable table)
    {
-      Views views = (Views) localViews.get();
+      Views views = getViews();
       Table.View view = views.relationViews[table.getTableId()];
       if(view == null)
       {
@@ -140,7 +119,7 @@
 
    public void flush()
    {
-      Views views = (Views) localViews.get();
+      Views views = getViews();
 
       Table.View[] relationViews = views.relationViews;
       if(relationViews != null)
@@ -231,6 +210,36 @@
       }
    }
 
+   private Views getViews()
+   {
+      Transaction tx = txLocal.getTransaction();
+      GlobalTxSynchronization globalSync;
+      try
+      {
+         globalSync = txLocal.getGlobalSynchronization(tx);
+      }
+      catch(RollbackException e)
+      {
+         throw new EJBException("Transaction already marked to roll back: " + e.getMessage(), e);
+      }
+      catch(SystemException e)
+      {
+         throw new IllegalStateException("Failed to register transaction synchronization: " + e.getMessage());
+      }
+
+      if(globalSync == null)
+         throw new IllegalStateException("Global transaction synchronization is not available for transaction " + tx);
+      
+      Views views = (Views) globalSync.getTxLocal(viewsTxLocalKey);
+      if(views == null)
+      {
+         views = new Views(tx);
+         globalSync.putTxLocal(viewsTxLocalKey, views);
+         globalSync.addSynchronization(new SchemaSynchronization(views));
+      }
+      return views;
+   }
+
    // Inner
 
    public class Views

Modified: branches/JBPAPP_5_0/testsuite/imports/sections/cmp.xml
===================================================================
--- branches/JBPAPP_5_0/testsuite/imports/sections/cmp.xml	2010-02-02 14:57:58 UTC (rev 100258)
+++ branches/JBPAPP_5_0/testsuite/imports/sections/cmp.xml	2010-02-02 15:06:00 UTC (rev 100259)
@@ -383,6 +383,31 @@
          tofile="${build.resources}/cmp2/jbas3541/META-INF/jboss.xml"
          overwrite="true"/>
 
+      <!-- build cmp2-jdbc2pm-ejbstore.jar -->
+      <jar destfile="${build.lib}/cmp2-jdbc2pm-ejbstore.jar">
+         <fileset dir="${build.classes}">
+            <patternset refid="common.test.client.classes"/>
+            <include name="org/jboss/test/cmp2/jdbc2pm/ejbstore/**/A*"/>
+            <include name="org/jboss/test/cmp2/jdbc2pm/ejbstore/test/**"/>
+         </fileset>
+         <fileset dir="${build.resources}/cmp2/jdbc2pm/ejbstore">
+            <include name="META-INF**/*.*"/>
+         </fileset>
+         <zipfileset src="${jboss.test.lib}/jboss-test.jar"
+            includes="org/jboss/**/*.*"/>
+         <zipfileset src="${junit.junit.lib}/junit.jar"
+            includes="junit/**/*.*"/>
+      </jar>
+      <!-- build cmp2-jdbc2pm-ejbstoreb.jar -->
+      <jar destfile="${build.lib}/cmp2-jdbc2pm-ejbstoreb.jar">
+         <fileset dir="${build.classes}">
+            <include name="org/jboss/test/cmp2/jdbc2pm/ejbstore/**/B*"/>
+         </fileset>
+         <fileset dir="${build.resources}/cmp2/jdbc2pm/ejbstore/b">
+            <include name="**/*.*"/>
+         </fileset>
+      </jar>
+
       <!-- build cmp2-jbas979.jar -->
       <jar destfile="${build.lib}/cmp2-jbas979.jar">
          <fileset dir="${build.classes}">

Added: branches/JBPAPP_5_0/testsuite/src/main/org/jboss/test/cmp2/jdbc2pm/ejbstore/ejb/ABean.java
===================================================================
--- branches/JBPAPP_5_0/testsuite/src/main/org/jboss/test/cmp2/jdbc2pm/ejbstore/ejb/ABean.java	                        (rev 0)
+++ branches/JBPAPP_5_0/testsuite/src/main/org/jboss/test/cmp2/jdbc2pm/ejbstore/ejb/ABean.java	2010-02-02 15:06:00 UTC (rev 100259)
@@ -0,0 +1,114 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, 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.test.cmp2.jdbc2pm.ejbstore.ejb;
+
+
+import javax.ejb.EntityBean;
+import javax.ejb.EntityContext;
+import javax.ejb.RemoveException;
+import javax.ejb.CreateException;
+
+
+/**
+ * @author <a href="mailto:alex at jboss.org">Alexey Loubyansky</a>
+ * @version <tt>$Revision: $</tt>
+ */
+public abstract class ABean implements EntityBean
+{
+   // CMP accessors --------------------------------------------
+   /**
+    * @ejb.pk-field
+    * @ejb.persistent-field
+    * @ejb.interface-method
+    */
+   public abstract Long getId();
+
+   public abstract void setId(Long id);
+
+   /**
+    * @ejb.persistent-field
+    * @ejb.interface-method
+    */
+   public abstract Integer getIntField();
+
+  /**
+   * @ejb.interface-method
+   */
+   public abstract void setIntField(Integer i);
+
+   /**
+    * @ejb.persistent-field
+    * @ejb.interface-method
+    */
+   public abstract Integer getStoreCount();
+
+  /**
+   * @ejb.interface-method
+   */
+   public abstract void setStoreCount(Integer i);
+
+   /**
+    * @throws javax.ejb.CreateException
+    * @ejb.create-method
+    */
+   public Long ejbCreate(Long id, Integer i)
+      throws CreateException
+   {
+      setId(id);
+      setIntField(i);
+      setStoreCount(new Integer(0));
+      return null;
+   }
+
+   public void ejbPostCreate(Long id, Integer i)
+   {
+   }
+
+   public void setEntityContext(EntityContext ctx)
+   {
+   }
+
+   public void unsetEntityContext()
+   {
+   }
+
+   public void ejbActivate()
+   {
+   }
+
+   public void ejbLoad()
+   {
+   }
+
+   public void ejbPassivate()
+   {
+   }
+
+   public void ejbRemove() throws RemoveException
+   {
+   }
+
+   public void ejbStore()
+   {
+      setStoreCount(new Integer(getStoreCount().intValue() + 1));
+   }
+}

Added: branches/JBPAPP_5_0/testsuite/src/main/org/jboss/test/cmp2/jdbc2pm/ejbstore/ejb/ALocal.java
===================================================================
--- branches/JBPAPP_5_0/testsuite/src/main/org/jboss/test/cmp2/jdbc2pm/ejbstore/ejb/ALocal.java	                        (rev 0)
+++ branches/JBPAPP_5_0/testsuite/src/main/org/jboss/test/cmp2/jdbc2pm/ejbstore/ejb/ALocal.java	2010-02-02 15:06:00 UTC (rev 100259)
@@ -0,0 +1,38 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, 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.test.cmp2.jdbc2pm.ejbstore.ejb;
+
+/**
+ * @author <a href="mailto:alex at jboss.org">Alexey Loubyansky</a>
+ * @version <tt>$Revision: $</tt>
+ */
+public interface ALocal
+   extends javax.ejb.EJBLocalObject
+{
+   public Long getId(  ) ;
+
+   public Integer getIntField(  ) ;
+
+   public void setIntField( Integer i ) ;
+   
+   public Integer getStoreCount();
+}

Added: branches/JBPAPP_5_0/testsuite/src/main/org/jboss/test/cmp2/jdbc2pm/ejbstore/ejb/ALocalHome.java
===================================================================
--- branches/JBPAPP_5_0/testsuite/src/main/org/jboss/test/cmp2/jdbc2pm/ejbstore/ejb/ALocalHome.java	                        (rev 0)
+++ branches/JBPAPP_5_0/testsuite/src/main/org/jboss/test/cmp2/jdbc2pm/ejbstore/ejb/ALocalHome.java	2010-02-02 15:06:00 UTC (rev 100259)
@@ -0,0 +1,37 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, 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.test.cmp2.jdbc2pm.ejbstore.ejb;
+
+
+/**
+ * @author <a href="mailto:alex at jboss.org">Alexey Loubyansky</a>
+ * @version <tt>$Revision: $</tt>
+ */
+public interface ALocalHome
+   extends javax.ejb.EJBLocalHome
+{
+   public ALocal create(Long id , Integer i)
+      throws javax.ejb.CreateException;
+
+   public ALocal findByPrimaryKey(Long pk)
+      throws javax.ejb.FinderException;
+}

Added: branches/JBPAPP_5_0/testsuite/src/main/org/jboss/test/cmp2/jdbc2pm/ejbstore/ejb/BBean.java
===================================================================
--- branches/JBPAPP_5_0/testsuite/src/main/org/jboss/test/cmp2/jdbc2pm/ejbstore/ejb/BBean.java	                        (rev 0)
+++ branches/JBPAPP_5_0/testsuite/src/main/org/jboss/test/cmp2/jdbc2pm/ejbstore/ejb/BBean.java	2010-02-02 15:06:00 UTC (rev 100259)
@@ -0,0 +1,114 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, 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.test.cmp2.jdbc2pm.ejbstore.ejb;
+
+
+import javax.ejb.EntityBean;
+import javax.ejb.EntityContext;
+import javax.ejb.RemoveException;
+import javax.ejb.CreateException;
+
+
+/**
+ * @author <a href="mailto:alex at jboss.org">Alexey Loubyansky</a>
+ * @version <tt>$Revision: $</tt>
+ */
+public abstract class BBean implements EntityBean
+{
+   // CMP accessors --------------------------------------------
+   /**
+    * @ejb.pk-field
+    * @ejb.persistent-field
+    * @ejb.interface-method
+    */
+   public abstract Long getId();
+
+   public abstract void setId(Long id);
+
+   /**
+    * @ejb.persistent-field
+    * @ejb.interface-method
+    */
+   public abstract String getStringField();
+
+  /**
+   * @ejb.interface-method
+   */
+   public abstract void setStringField(String i);
+
+   /**
+    * @ejb.persistent-field
+    * @ejb.interface-method
+    */
+   public abstract Integer getStoreCount();
+
+  /**
+   * @ejb.interface-method
+   */
+   public abstract void setStoreCount(Integer i);
+
+   /**
+    * @throws javax.ejb.CreateException
+    * @ejb.create-method
+    */
+   public Long ejbCreate(Long id, String i)
+      throws CreateException
+   {
+      setId(id);
+      setStringField(i);
+      setStoreCount(new Integer(0));
+      return null;
+   }
+
+   public void ejbPostCreate(Long id, String i)
+   {
+   }
+
+   public void setEntityContext(EntityContext ctx)
+   {
+   }
+
+   public void unsetEntityContext()
+   {
+   }
+
+   public void ejbActivate()
+   {
+   }
+
+   public void ejbLoad()
+   {
+   }
+
+   public void ejbPassivate()
+   {
+   }
+
+   public void ejbRemove() throws RemoveException
+   {
+   }
+
+   public void ejbStore()
+   {
+      setStoreCount(new Integer(getStoreCount().intValue() + 1));
+   }
+}

Added: branches/JBPAPP_5_0/testsuite/src/main/org/jboss/test/cmp2/jdbc2pm/ejbstore/ejb/BLocal.java
===================================================================
--- branches/JBPAPP_5_0/testsuite/src/main/org/jboss/test/cmp2/jdbc2pm/ejbstore/ejb/BLocal.java	                        (rev 0)
+++ branches/JBPAPP_5_0/testsuite/src/main/org/jboss/test/cmp2/jdbc2pm/ejbstore/ejb/BLocal.java	2010-02-02 15:06:00 UTC (rev 100259)
@@ -0,0 +1,38 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, 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.test.cmp2.jdbc2pm.ejbstore.ejb;
+
+/**
+ * @author <a href="mailto:alex at jboss.org">Alexey Loubyansky</a>
+ * @version <tt>$Revision: $</tt>
+ */
+public interface BLocal
+   extends javax.ejb.EJBLocalObject
+{
+   public Long getId(  ) ;
+
+   public String getStringField(  ) ;
+
+   public void setStringField( String i ) ;
+   
+   public Integer getStoreCount();
+}

Added: branches/JBPAPP_5_0/testsuite/src/main/org/jboss/test/cmp2/jdbc2pm/ejbstore/ejb/BLocalHome.java
===================================================================
--- branches/JBPAPP_5_0/testsuite/src/main/org/jboss/test/cmp2/jdbc2pm/ejbstore/ejb/BLocalHome.java	                        (rev 0)
+++ branches/JBPAPP_5_0/testsuite/src/main/org/jboss/test/cmp2/jdbc2pm/ejbstore/ejb/BLocalHome.java	2010-02-02 15:06:00 UTC (rev 100259)
@@ -0,0 +1,37 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, 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.test.cmp2.jdbc2pm.ejbstore.ejb;
+
+
+/**
+ * @author <a href="mailto:alex at jboss.org">Alexey Loubyansky</a>
+ * @version <tt>$Revision: $</tt>
+ */
+public interface BLocalHome
+   extends javax.ejb.EJBLocalHome
+{
+   public BLocal create(Long id , String i)
+      throws javax.ejb.CreateException;
+
+   public BLocal findByPrimaryKey(Long pk)
+      throws javax.ejb.FinderException;
+}

Added: branches/JBPAPP_5_0/testsuite/src/main/org/jboss/test/cmp2/jdbc2pm/ejbstore/test/JDBC2PmEjbStoreUnitTestCase.java
===================================================================
--- branches/JBPAPP_5_0/testsuite/src/main/org/jboss/test/cmp2/jdbc2pm/ejbstore/test/JDBC2PmEjbStoreUnitTestCase.java	                        (rev 0)
+++ branches/JBPAPP_5_0/testsuite/src/main/org/jboss/test/cmp2/jdbc2pm/ejbstore/test/JDBC2PmEjbStoreUnitTestCase.java	2010-02-02 15:06:00 UTC (rev 100259)
@@ -0,0 +1,96 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, 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.test.cmp2.jdbc2pm.ejbstore.test;
+
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import org.jboss.test.JBossTestCase;
+import org.jboss.test.cmp2.jdbc2pm.ejbstore.ejb.ALocal;
+import org.jboss.test.cmp2.jdbc2pm.ejbstore.ejb.ALocalHome;
+import org.jboss.test.cmp2.jdbc2pm.ejbstore.ejb.BLocal;
+import org.jboss.test.cmp2.jdbc2pm.ejbstore.ejb.BLocalHome;
+import org.jboss.test.util.ejb.EJBTestCase;
+import junit.framework.Test;
+
+/**
+ * @author <a href="mailto:alex at jboss.org">Alexey Loubyansky</a>
+ * @version <tt>$Revision: 44174 $</tt>
+ */
+public class JDBC2PmEjbStoreUnitTestCase
+   extends EJBTestCase
+{
+   public static Test suite() throws Exception
+   {
+      return JBossTestCase.getDeploySetup(JDBC2PmEjbStoreUnitTestCase.class, "cmp2-jdbc2pm-ejbstoreb.jar, cmp2-jdbc2pm-ejbstore.jar");
+   }
+
+   public JDBC2PmEjbStoreUnitTestCase(String methodName)
+   {
+      super(methodName);
+   }
+
+   protected void setUp() throws Exception
+   {
+      getALocalHome().create(new Long(1), new Integer(2));
+   }
+
+   protected void tearDown() throws Exception
+   {
+      getALocalHome().remove(new Long(1));
+   }
+
+   // Tests
+
+   public void testMain() throws Throwable
+   {
+      ALocal a = getALocalHome().findByPrimaryKey(new Long(1));
+      int storeCount = a.getStoreCount().intValue();
+      a.setIntField(new Integer(a.getIntField().intValue() + 1));
+      assertEquals(storeCount + 1, a.getStoreCount().intValue());      
+   }
+
+   public void testCorrectView() throws Throwable
+   {
+      BLocal b = getBLocalHome().create(new Long(11), "test");
+      ALocal a = getALocalHome().findByPrimaryKey(new Long(1));
+   }
+
+   // Private
+
+   private ALocalHome getALocalHome()
+      throws NamingException
+   {
+      return (ALocalHome)lookup("ALocal");
+   }
+
+   private BLocalHome getBLocalHome()
+      throws NamingException
+   {
+      return (BLocalHome)lookup("BLocal");
+   }
+
+   private Object lookup(String name) throws NamingException
+   {
+      InitialContext ic = new InitialContext();
+      return ic.lookup(name);
+   }
+}

Added: branches/JBPAPP_5_0/testsuite/src/resources/cmp2/jdbc2pm/ejbstore/META-INF/ejb-jar.xml
===================================================================
--- branches/JBPAPP_5_0/testsuite/src/resources/cmp2/jdbc2pm/ejbstore/META-INF/ejb-jar.xml	                        (rev 0)
+++ branches/JBPAPP_5_0/testsuite/src/resources/cmp2/jdbc2pm/ejbstore/META-INF/ejb-jar.xml	2010-02-02 15:06:00 UTC (rev 100259)
@@ -0,0 +1,62 @@
+<?xml version="1.0"?>
+<!DOCTYPE ejb-jar PUBLIC
+   "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN"
+   "http://java.sun.com/dtd/ejb-jar_2_0.dtd">
+
+<ejb-jar>
+   <enterprise-beans>
+      <session>
+         <description>JUnit Session Bean Test Runner</description>
+         <ejb-name>EJBTestRunnerEJB</ejb-name>
+         <home>org.jboss.test.util.ejb.EJBTestRunnerHome</home>
+         <remote>org.jboss.test.util.ejb.EJBTestRunner</remote>
+         <ejb-class>org.jboss.test.util.ejb.EJBTestRunnerBean</ejb-class>
+         <session-type>Stateless</session-type>
+         <transaction-type>Bean</transaction-type>
+      </session>
+      <entity >
+         <ejb-name>A</ejb-name>
+
+         <local-home>org.jboss.test.cmp2.jdbc2pm.ejbstore.ejb.ALocalHome</local-home>
+         <local>org.jboss.test.cmp2.jdbc2pm.ejbstore.ejb.ALocal</local>
+
+         <ejb-class>org.jboss.test.cmp2.jdbc2pm.ejbstore.ejb.ABean</ejb-class>
+         <persistence-type>Container</persistence-type>
+         <prim-key-class>java.lang.Long</prim-key-class>
+         <reentrant>false</reentrant>
+         <cmp-version>2.x</cmp-version>
+         <abstract-schema-name>A</abstract-schema-name>
+         <cmp-field >
+            <description><![CDATA[]]></description>
+            <field-name>id</field-name>
+         </cmp-field>
+         <cmp-field >
+            <description><![CDATA[]]></description>
+            <field-name>intField</field-name>
+         </cmp-field>
+         <cmp-field >
+            <description><![CDATA[]]></description>
+            <field-name>storeCount</field-name>
+         </cmp-field>
+         <primkey-field>id</primkey-field>
+      </entity>
+   </enterprise-beans>
+
+   <assembly-descriptor >
+      <container-transaction >
+         <method >
+            <ejb-name>A</ejb-name>
+            <method-name>getStoreCount</method-name>
+         </method>
+         <trans-attribute>RequiresNew</trans-attribute>
+      </container-transaction>
+      <container-transaction >
+         <method >
+            <ejb-name>A</ejb-name>
+            <method-name>setIntField</method-name>
+         </method>
+         <trans-attribute>RequiresNew</trans-attribute>
+      </container-transaction>
+   </assembly-descriptor>
+
+</ejb-jar>

Added: branches/JBPAPP_5_0/testsuite/src/resources/cmp2/jdbc2pm/ejbstore/META-INF/jboss.xml
===================================================================
--- branches/JBPAPP_5_0/testsuite/src/resources/cmp2/jdbc2pm/ejbstore/META-INF/jboss.xml	                        (rev 0)
+++ branches/JBPAPP_5_0/testsuite/src/resources/cmp2/jdbc2pm/ejbstore/META-INF/jboss.xml	2010-02-02 15:06:00 UTC (rev 100259)
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<!DOCTYPE jboss PUBLIC "-//JBoss//DTD JBOSS 4.0//EN" "http://www.jboss.org/j2ee/dtd/jboss_4_0.dtd">
+
+<jboss>
+   <enterprise-beans>
+      <entity>
+         <ejb-name>A</ejb-name>
+         <local-jndi-name>ALocal</local-jndi-name>
+         <configuration-name>custom</configuration-name>
+      </entity>
+      <session>
+         <ejb-name>EJBTestRunnerEJB</ejb-name>
+         <jndi-name>ejb/EJBTestRunner</jndi-name>
+      </session>
+   </enterprise-beans>
+
+    <container-configurations>
+        <container-configuration extends="cmp2.x jdbc2 pm">
+            <container-name>custom</container-name>
+            <call-ejb-store-on-clean>false</call-ejb-store-on-clean>
+        </container-configuration>
+    </container-configurations>
+</jboss>

Added: branches/JBPAPP_5_0/testsuite/src/resources/cmp2/jdbc2pm/ejbstore/META-INF/jbosscmp-jdbc.xml
===================================================================
--- branches/JBPAPP_5_0/testsuite/src/resources/cmp2/jdbc2pm/ejbstore/META-INF/jbosscmp-jdbc.xml	                        (rev 0)
+++ branches/JBPAPP_5_0/testsuite/src/resources/cmp2/jdbc2pm/ejbstore/META-INF/jbosscmp-jdbc.xml	2010-02-02 15:06:00 UTC (rev 100259)
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE jbosscmp-jdbc PUBLIC
+   "-//JBoss//DTD JBOSSCMP-JDBC 3.2//EN"
+   "http://www.jboss.org/j2ee/dtd/jbosscmp-jdbc_3_2.dtd">
+<jbosscmp-jdbc>
+   <defaults>
+      <remove-table>true</remove-table>
+   </defaults>
+</jbosscmp-jdbc>

Added: branches/JBPAPP_5_0/testsuite/src/resources/cmp2/jdbc2pm/ejbstore/b/META-INF/ejb-jar.xml
===================================================================
--- branches/JBPAPP_5_0/testsuite/src/resources/cmp2/jdbc2pm/ejbstore/b/META-INF/ejb-jar.xml	                        (rev 0)
+++ branches/JBPAPP_5_0/testsuite/src/resources/cmp2/jdbc2pm/ejbstore/b/META-INF/ejb-jar.xml	2010-02-02 15:06:00 UTC (rev 100259)
@@ -0,0 +1,53 @@
+<?xml version="1.0"?>
+<!DOCTYPE ejb-jar PUBLIC
+   "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN"
+   "http://java.sun.com/dtd/ejb-jar_2_0.dtd">
+
+<ejb-jar>
+   <enterprise-beans>
+      <entity >
+         <ejb-name>B</ejb-name>
+
+         <local-home>org.jboss.test.cmp2.jdbc2pm.ejbstore.ejb.BLocalHome</local-home>
+         <local>org.jboss.test.cmp2.jdbc2pm.ejbstore.ejb.BLocal</local>
+
+         <ejb-class>org.jboss.test.cmp2.jdbc2pm.ejbstore.ejb.BBean</ejb-class>
+         <persistence-type>Container</persistence-type>
+         <prim-key-class>java.lang.Long</prim-key-class>
+         <reentrant>false</reentrant>
+         <cmp-version>2.x</cmp-version>
+         <abstract-schema-name>B</abstract-schema-name>
+         <cmp-field >
+            <description><![CDATA[]]></description>
+            <field-name>id</field-name>
+         </cmp-field>
+         <cmp-field >
+            <description><![CDATA[]]></description>
+            <field-name>stringField</field-name>
+         </cmp-field>
+         <cmp-field >
+            <description><![CDATA[]]></description>
+            <field-name>storeCount</field-name>
+         </cmp-field>
+         <primkey-field>id</primkey-field>
+      </entity>
+   </enterprise-beans>
+
+   <assembly-descriptor >
+      <container-transaction >
+         <method >
+            <ejb-name>B</ejb-name>
+            <method-name>getStoreCount</method-name>
+         </method>
+         <trans-attribute>RequiresNew</trans-attribute>
+      </container-transaction>
+      <container-transaction >
+         <method >
+            <ejb-name>B</ejb-name>
+            <method-name>setStringField</method-name>
+         </method>
+         <trans-attribute>RequiresNew</trans-attribute>
+      </container-transaction>
+   </assembly-descriptor>
+
+</ejb-jar>

Added: branches/JBPAPP_5_0/testsuite/src/resources/cmp2/jdbc2pm/ejbstore/b/META-INF/jboss.xml
===================================================================
--- branches/JBPAPP_5_0/testsuite/src/resources/cmp2/jdbc2pm/ejbstore/b/META-INF/jboss.xml	                        (rev 0)
+++ branches/JBPAPP_5_0/testsuite/src/resources/cmp2/jdbc2pm/ejbstore/b/META-INF/jboss.xml	2010-02-02 15:06:00 UTC (rev 100259)
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<!DOCTYPE jboss PUBLIC "-//JBoss//DTD JBOSS 4.0//EN" "http://www.jboss.org/j2ee/dtd/jboss_4_0.dtd">
+
+<jboss>
+   <enterprise-beans>
+      <entity>
+         <ejb-name>B</ejb-name>
+         <local-jndi-name>BLocal</local-jndi-name>
+         <configuration-name>custom</configuration-name>
+      </entity>
+   </enterprise-beans>
+
+    <container-configurations>
+        <container-configuration extends="cmp2.x jdbc2 pm">
+            <container-name>custom</container-name>
+            <call-ejb-store-on-clean>false</call-ejb-store-on-clean>
+        </container-configuration>
+    </container-configurations>
+</jboss>

Added: branches/JBPAPP_5_0/testsuite/src/resources/cmp2/jdbc2pm/ejbstore/b/META-INF/jbosscmp-jdbc.xml
===================================================================
--- branches/JBPAPP_5_0/testsuite/src/resources/cmp2/jdbc2pm/ejbstore/b/META-INF/jbosscmp-jdbc.xml	                        (rev 0)
+++ branches/JBPAPP_5_0/testsuite/src/resources/cmp2/jdbc2pm/ejbstore/b/META-INF/jbosscmp-jdbc.xml	2010-02-02 15:06:00 UTC (rev 100259)
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE jbosscmp-jdbc PUBLIC
+   "-//JBoss//DTD JBOSSCMP-JDBC 3.2//EN"
+   "http://www.jboss.org/j2ee/dtd/jbosscmp-jdbc_3_2.dtd">
+<jbosscmp-jdbc>
+   <defaults>
+      <remove-table>true</remove-table>
+   </defaults>
+</jbosscmp-jdbc>




More information about the jboss-cvs-commits mailing list