[jboss-cvs] JBossAS SVN: r93375 - in trunk: server/src/main/org/jboss/ejb/plugins/cmp/jdbc2/schema and 6 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Sep 11 05:15:11 EDT 2009


Author: alex.loubyansky at jboss.com
Date: 2009-09-11 05:15:11 -0400 (Fri, 11 Sep 2009)
New Revision: 93375

Added:
   trunk/testsuite/src/main/org/jboss/test/cmp2/jdbc2pm/
   trunk/testsuite/src/resources/cmp2/jdbc2pm/
   trunk/testsuite/src/resources/cmp2/jdbc2pm/ejbstore/
   trunk/testsuite/src/resources/cmp2/jdbc2pm/ejbstore/META-INF/
   trunk/testsuite/src/resources/cmp2/jdbc2pm/ejbstore/META-INF/ejb-jar.xml
   trunk/testsuite/src/resources/cmp2/jdbc2pm/ejbstore/META-INF/jboss.xml
   trunk/testsuite/src/resources/cmp2/jdbc2pm/ejbstore/META-INF/jbosscmp-jdbc.xml
Modified:
   trunk/server/src/main/org/jboss/ejb/GlobalTxEntityMap.java
   trunk/server/src/main/org/jboss/ejb/plugins/cmp/jdbc2/schema/Schema.java
   trunk/testsuite/imports/sections/cmp.xml
Log:
JBAS-7238

Modified: trunk/server/src/main/org/jboss/ejb/GlobalTxEntityMap.java
===================================================================
--- trunk/server/src/main/org/jboss/ejb/GlobalTxEntityMap.java	2009-09-11 08:45:13 UTC (rev 93374)
+++ trunk/server/src/main/org/jboss/ejb/GlobalTxEntityMap.java	2009-09-11 09:15:11 UTC (rev 93375)
@@ -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: trunk/server/src/main/org/jboss/ejb/plugins/cmp/jdbc2/schema/Schema.java
===================================================================
--- trunk/server/src/main/org/jboss/ejb/plugins/cmp/jdbc2/schema/Schema.java	2009-09-11 08:45:13 UTC (rev 93374)
+++ trunk/server/src/main/org/jboss/ejb/plugins/cmp/jdbc2/schema/Schema.java	2009-09-11 09:15:11 UTC (rev 93375)
@@ -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,13 @@
  */
 public class Schema
 {
+   private static final String VIEWS_TX_LOCAL_KEY = "jdbc2pm.Schema.Views";
+
    private EntityTable[] entityTables;
    private RelationTable[] relationTables;
 
-   private TransactionLocal localViews = new TransactionLocal()
-   {
-      protected Object initialValue()
-      {
-         Transaction tx = getTransaction();
+   private GlobalTxEntityMap txLocal = EntityContainer.getGlobalTxEntityMap();
 
-         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 +90,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 +102,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 +114,7 @@
 
    public void flush()
    {
-      Views views = (Views) localViews.get();
+      Views views = getViews();
 
       Table.View[] relationViews = views.relationViews;
       if(relationViews != null)
@@ -231,6 +205,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(VIEWS_TX_LOCAL_KEY);
+      if(views == null)
+      {
+         views = new Views(tx);
+         globalSync.putTxLocal(VIEWS_TX_LOCAL_KEY, views);
+         globalSync.addSynchronization(new SchemaSynchronization(views));
+      }
+      return views;
+   }
+
    // Inner
 
    public class Views

Modified: trunk/testsuite/imports/sections/cmp.xml
===================================================================
--- trunk/testsuite/imports/sections/cmp.xml	2009-09-11 08:45:13 UTC (rev 93374)
+++ trunk/testsuite/imports/sections/cmp.xml	2009-09-11 09:15:11 UTC (rev 93375)
@@ -383,6 +383,21 @@
          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/**"/>
+         </fileset>
+         <fileset dir="${build.resources}/cmp2/jdbc2pm/ejbstore">
+            <include name="**/*.*"/>
+         </fileset>
+         <zipfileset src="${org.jboss.test:jboss-test:jar}"
+            includes="org/jboss/**/*.*"/>
+         <zipfileset src="${junit:junit:jar}"
+            includes="junit/**/*.*"/>
+      </jar>
+
       <!-- build cmp2-jbas979.jar -->
       <jar destfile="${build.lib}/cmp2-jbas979.jar">
          <fileset dir="${build.classes}">

Added: trunk/testsuite/src/resources/cmp2/jdbc2pm/ejbstore/META-INF/ejb-jar.xml
===================================================================
--- trunk/testsuite/src/resources/cmp2/jdbc2pm/ejbstore/META-INF/ejb-jar.xml	                        (rev 0)
+++ trunk/testsuite/src/resources/cmp2/jdbc2pm/ejbstore/META-INF/ejb-jar.xml	2009-09-11 09:15:11 UTC (rev 93375)
@@ -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: trunk/testsuite/src/resources/cmp2/jdbc2pm/ejbstore/META-INF/jboss.xml
===================================================================
--- trunk/testsuite/src/resources/cmp2/jdbc2pm/ejbstore/META-INF/jboss.xml	                        (rev 0)
+++ trunk/testsuite/src/resources/cmp2/jdbc2pm/ejbstore/META-INF/jboss.xml	2009-09-11 09:15:11 UTC (rev 93375)
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<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: trunk/testsuite/src/resources/cmp2/jdbc2pm/ejbstore/META-INF/jbosscmp-jdbc.xml
===================================================================
--- trunk/testsuite/src/resources/cmp2/jdbc2pm/ejbstore/META-INF/jbosscmp-jdbc.xml	                        (rev 0)
+++ trunk/testsuite/src/resources/cmp2/jdbc2pm/ejbstore/META-INF/jbosscmp-jdbc.xml	2009-09-11 09:15:11 UTC (rev 93375)
@@ -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