[jboss-cvs] JBossAS SVN: r109278 - in projects/jboss-jca/trunk/core: src/test/java/org/jboss/jca/test and 2 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Nov 11 15:23:09 EST 2010


Author: jesper.pedersen
Date: 2010-11-11 15:23:08 -0500 (Thu, 11 Nov 2010)
New Revision: 109278

Added:
   projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/test/txmgr/
   projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/test/txmgr/JBossXATerminatorImpl.java
   projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/test/txmgr/RealTransactionManagerImpl.java
   projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/test/txmgr/TransactionImpl.java
   projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/test/txmgr/TransactionManagerImpl.java
   projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/test/txmgr/TransactionSynchronizationRegistryImpl.java
   projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/test/txmgr/TxRegistry.java
   projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/test/txmgr/UserTransactionImpl.java
   projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/test/txmgr/package.html
   projects/jboss-jca/trunk/core/src/test/resources/txmgr-jboss-beans.xml
Modified:
   projects/jboss-jca/trunk/core/build.xml
Log:
A noop transaction manager implementation for the JCA requirements

Modified: projects/jboss-jca/trunk/core/build.xml
===================================================================
--- projects/jboss-jca/trunk/core/build.xml	2010-11-11 19:45:36 UTC (rev 109277)
+++ projects/jboss-jca/trunk/core/build.xml	2010-11-11 20:23:08 UTC (rev 109278)
@@ -251,6 +251,21 @@
       <fileset dir="src/test/resources"/>
     </copy>
 
+    <jar destfile="${build.core.dir}/test/${name}-test-txmgr.jar"
+         basedir="${build.core.dir}/test"
+         index="true"
+         indexMetaInf="true"
+         update="true"
+         level="9"
+         includes="**/txmgr/**">
+      <manifest>
+        <attribute name="Implementation-Title" value="IronJacamar Test - Transaction Manager"/>
+        <attribute name="Implementation-Version" value="${major}.${minor}.${patch}.${type}"/>
+        <attribute name="Implementation-Vendor" value="The IronJacamar project (http://www.jboss.org/ironjacamar)"/>
+        <attribute name="Implementation-Vendor-Id" value="org.jboss"/>
+      </manifest>
+    </jar>
+
   </target>
 
   <!-- ================================= 

Added: projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/test/txmgr/JBossXATerminatorImpl.java
===================================================================
--- projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/test/txmgr/JBossXATerminatorImpl.java	                        (rev 0)
+++ projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/test/txmgr/JBossXATerminatorImpl.java	2010-11-11 20:23:08 UTC (rev 109278)
@@ -0,0 +1,113 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, 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.jca.test.txmgr;
+
+import java.io.Serializable;
+
+import javax.resource.spi.work.Work;
+import javax.resource.spi.work.WorkCompletedException;
+import javax.transaction.xa.XAException;
+import javax.transaction.xa.XAResource;
+import javax.transaction.xa.Xid;
+
+import org.jboss.tm.JBossXATerminator;
+
+/**
+ * A JBoss XATerminator implementation
+ * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
+ */
+public class JBossXATerminatorImpl implements JBossXATerminator, Serializable
+{
+   private static final long serialVersionUID = 1L;
+
+   /**
+    * Constructor
+    */
+   public JBossXATerminatorImpl()
+   {
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public void commit(Xid xid, boolean onePhase) throws XAException
+   {
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public void forget(Xid xid) throws XAException
+   {
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public int prepare(Xid xid) throws XAException
+   {
+      return XAResource.XA_OK;
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public Xid[] recover(int flag) throws XAException
+   {
+      return new Xid[0];
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public void rollback(Xid xid) throws XAException
+   {
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public void registerWork(Work work, Xid xid, long timeout) throws WorkCompletedException
+   {
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public void startWork(Work work, Xid xid) throws WorkCompletedException
+   {
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public void endWork(Work work, Xid xid)
+   {
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public void cancelWork(Work work, Xid xid)
+   {
+   }
+}

Added: projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/test/txmgr/RealTransactionManagerImpl.java
===================================================================
--- projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/test/txmgr/RealTransactionManagerImpl.java	                        (rev 0)
+++ projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/test/txmgr/RealTransactionManagerImpl.java	2010-11-11 20:23:08 UTC (rev 109278)
@@ -0,0 +1,70 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, 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.jca.test.txmgr;
+
+import java.io.Serializable;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+
+/**
+ * A transaction manager implementation
+ * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
+ */
+public class RealTransactionManagerImpl extends TransactionManagerImpl implements Serializable
+{
+   private static final long serialVersionUID = 1L;
+   private static final String JNDI_NAME = "java:/TransactionManager";
+
+   /**
+    * Constructor
+    */
+   public RealTransactionManagerImpl()
+   {
+   }
+
+   /**
+    * Start
+    * @exception Throwable Thrown if an error occurs
+    */
+   public void start() throws Throwable
+   {
+      Context context = new InitialContext();
+
+      context.bind(JNDI_NAME, this);
+
+      context.close();
+   }
+
+   /**
+    * Stop
+    * @exception Throwable Thrown if an error occurs
+    */
+   public void stop() throws Throwable
+   {
+      Context context = new InitialContext();
+
+      context.unbind(JNDI_NAME);
+
+      context.close();
+   }
+}

Added: projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/test/txmgr/TransactionImpl.java
===================================================================
--- projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/test/txmgr/TransactionImpl.java	                        (rev 0)
+++ projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/test/txmgr/TransactionImpl.java	2010-11-11 20:23:08 UTC (rev 109278)
@@ -0,0 +1,168 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, 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.jca.test.txmgr;
+
+import java.io.Serializable;
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.transaction.HeuristicMixedException;
+import javax.transaction.HeuristicRollbackException;
+import javax.transaction.RollbackException;
+import javax.transaction.Status;
+import javax.transaction.Synchronization;
+import javax.transaction.SystemException;
+import javax.transaction.Transaction;
+import javax.transaction.xa.XAResource;
+
+/**
+ * A transaction implementation
+ * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
+ */
+public class TransactionImpl implements Transaction, Serializable
+{
+   private static final long serialVersionUID = 1L;
+   private int status;
+   private Set<Synchronization> syncs;
+   private Set<XAResource> xas;
+
+   /**
+    * Constructor
+    */
+   public TransactionImpl()
+   {
+      this.status = Status.STATUS_ACTIVE;
+      this.syncs = null;
+      this.xas = null;
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public void commit() throws RollbackException,
+                               HeuristicMixedException,
+                               HeuristicRollbackException,
+                               SecurityException,
+                               IllegalStateException,
+                               SystemException
+   {
+      finish(Status.STATUS_COMMITTED);
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public boolean delistResource(XAResource xaRes, int flag) throws IllegalStateException,
+                                                                    SystemException
+   {
+      if (xas == null)
+         return false;
+
+      return xas.remove(xaRes);
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public boolean enlistResource(XAResource xaRes) throws RollbackException,
+                                                          IllegalStateException,
+                                                          SystemException
+   {
+      if (xas == null)
+         xas = new HashSet<XAResource>(1);
+
+      return xas.add(xaRes);
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public int getStatus() throws SystemException
+   {
+      return status;
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public void registerSynchronization(Synchronization sync) throws RollbackException,
+                                                                    IllegalStateException,
+                                                                    SystemException
+   {
+      if (syncs == null)
+         syncs = new HashSet<Synchronization>(1);
+
+      syncs.add(sync);
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public void rollback() throws IllegalStateException,
+                                 SystemException
+   {
+      finish(Status.STATUS_ROLLEDBACK);
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public void setRollbackOnly() throws IllegalStateException,
+                                        SystemException
+   {
+      status = Status.STATUS_MARKED_ROLLBACK;
+   }
+
+   /**
+    * Get rollback only
+    * @return The value
+    */
+   boolean getRollbackOnly()
+   {
+      return status == Status.STATUS_MARKED_ROLLBACK;
+   }
+
+   /**
+    * Finish transaction
+    * @param st The status
+    */
+   private void finish(int st)
+   {
+      if (syncs != null)
+      {
+         for (Synchronization s : syncs)
+         {
+            s.beforeCompletion();
+         }
+      }
+
+      status = st;
+
+      if (syncs != null)
+      {
+         for (Synchronization s : syncs)
+         {
+            s.afterCompletion(status);
+         }
+      }
+   }
+}

Added: projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/test/txmgr/TransactionManagerImpl.java
===================================================================
--- projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/test/txmgr/TransactionManagerImpl.java	                        (rev 0)
+++ projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/test/txmgr/TransactionManagerImpl.java	2010-11-11 20:23:08 UTC (rev 109278)
@@ -0,0 +1,196 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, 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.jca.test.txmgr;
+
+import javax.transaction.HeuristicMixedException;
+import javax.transaction.HeuristicRollbackException;
+import javax.transaction.InvalidTransactionException;
+import javax.transaction.NotSupportedException;
+import javax.transaction.RollbackException;
+import javax.transaction.Status;
+import javax.transaction.SystemException;
+import javax.transaction.Transaction;
+import javax.transaction.TransactionManager;
+
+import org.jboss.tm.JBossXATerminator;
+
+/**
+ * A transaction manager implementation
+ * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
+ */
+public class TransactionManagerImpl implements TransactionManager
+{
+   private TxRegistry registry;
+   private JBossXATerminator terminator;
+
+   /**
+    * Constructor
+    */
+   public TransactionManagerImpl()
+   {
+   }
+
+   /**
+    * Set the registry
+    * @param v The value
+    */
+   public void setRegistry(TxRegistry v)
+   {
+      registry = v;
+   }
+
+   /**
+    * Get the terminator
+    * @return The value
+    */
+   public JBossXATerminator getXATerminator()
+   {
+      return terminator;
+   }
+
+   /**
+    * Set the terminator
+    * @param v The value
+    */
+   public void setXATerminator(JBossXATerminator v)
+   {
+      terminator = v;
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public void begin() throws NotSupportedException,
+                              SystemException
+   {
+      Transaction tx = registry.getTransaction();
+      
+      if (tx != null)
+         throw new NotSupportedException();
+
+      registry.startTransaction();
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public void commit() throws RollbackException,
+                               HeuristicMixedException,
+                               HeuristicRollbackException,
+                               SecurityException,
+                               IllegalStateException,
+                               SystemException
+   {
+      Transaction tx = registry.getTransaction();
+
+      if (tx == null)
+         throw new SystemException();
+
+      if (tx.getStatus() == Status.STATUS_ROLLEDBACK ||
+          tx.getStatus() == Status.STATUS_MARKED_ROLLBACK)
+         throw new RollbackException();
+
+      registry.endTransaction();
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public int getStatus() throws SystemException
+   {
+      Transaction tx = registry.getTransaction();
+
+      if (tx == null)
+         return Status.STATUS_NO_TRANSACTION;
+
+      return tx.getStatus();
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public Transaction getTransaction() throws SystemException
+   {
+      return registry.getTransaction();
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public void resume(Transaction tobj) throws InvalidTransactionException,
+                                               IllegalStateException,
+                                               SystemException
+   {
+      if (!(tobj instanceof TransactionImpl))
+         throw new SystemException();
+
+      registry.assignTransaction((TransactionImpl)tobj);
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public void rollback() throws IllegalStateException,
+                                 SecurityException,
+                                 SystemException
+   {
+      Transaction tx = registry.getTransaction();
+
+      if (tx == null)
+         throw new IllegalStateException();
+
+      registry.endTransaction();
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public void setRollbackOnly() throws IllegalStateException,
+                                        SystemException
+   {
+      Transaction tx = registry.getTransaction();
+
+      if (tx == null)
+         throw new IllegalStateException();
+
+      tx.setRollbackOnly();
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public void setTransactionTimeout(int seconds) throws SystemException
+   {
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public Transaction suspend() throws SystemException
+   {
+      Transaction tx = registry.getTransaction();
+
+      registry.assignTransaction(null);
+
+      return tx;
+   }
+}

Added: projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/test/txmgr/TransactionSynchronizationRegistryImpl.java
===================================================================
--- projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/test/txmgr/TransactionSynchronizationRegistryImpl.java	                        (rev 0)
+++ projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/test/txmgr/TransactionSynchronizationRegistryImpl.java	2010-11-11 20:23:08 UTC (rev 109278)
@@ -0,0 +1,245 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, 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.jca.test.txmgr;
+
+import java.io.Serializable;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.transaction.Status;
+import javax.transaction.Synchronization;
+import javax.transaction.TransactionSynchronizationRegistry;
+
+/**
+ * A transaction synchronization registry implementation
+ * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
+ */
+public class TransactionSynchronizationRegistryImpl implements TransactionSynchronizationRegistry, Serializable
+{
+   private static final long serialVersionUID = 1L;
+   private static final String JNDI_NAME = "java:/TransactionSynchronizationRegistry";
+   private TxRegistry registry;
+   private ConcurrentMap<Long, TxEnv> txe;
+
+   /**
+    * Constructor
+    */
+   public TransactionSynchronizationRegistryImpl()
+   {
+      this.registry = null;
+      this.txe = new ConcurrentHashMap<Long, TxEnv>();
+   }
+
+   /**
+    * Set the registry
+    * @param v The value
+    */
+   public void setRegistry(TxRegistry v)
+   {
+      registry = v;
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public Object getTransactionKey()
+   {
+      return getKey();
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public void putResource(Object key, Object value)
+   {
+      TxEnv env = getTxEnv();
+      env.getEnvironment().put(key, value);
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public Object getResource(Object key)
+   {
+      TxEnv env = getTxEnv();
+      return env.getEnvironment().get(key);
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public void registerInterposedSynchronization(Synchronization sync)
+   {
+      TransactionImpl tx = registry.getTransaction();
+
+      if (tx == null)
+         throw new IllegalStateException();
+
+      try
+      {
+         tx.registerSynchronization(sync);
+      }
+      catch (Throwable t)
+      {
+         // Nothing to do
+      }
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public int getTransactionStatus()
+   {
+      TransactionImpl tx = registry.getTransaction();
+
+      if (tx == null)
+         return Status.STATUS_NO_TRANSACTION;
+
+      try
+      {
+         return tx.getStatus();
+      }
+      catch (Throwable t)
+      {
+         return Status.STATUS_UNKNOWN;
+      }
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public void setRollbackOnly()
+   {
+      TransactionImpl tx = registry.getTransaction();
+
+      if (tx == null)
+         throw new IllegalStateException();
+
+      try
+      {
+         tx.setRollbackOnly();
+      }
+      catch (Throwable t)
+      {
+         // Nothing to do
+      }
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public boolean getRollbackOnly()
+   {
+      TransactionImpl tx = registry.getTransaction();
+
+      if (tx == null)
+         throw new IllegalStateException();
+
+      return tx.getRollbackOnly();
+   }
+
+   /**
+    * Start
+    * @exception Throwable Thrown if an error occurs
+    */
+   public void start() throws Throwable
+   {
+      Context context = new InitialContext();
+
+      context.bind(JNDI_NAME, this);
+
+      context.close();
+   }
+
+   /**
+    * Stop
+    * @exception Throwable Thrown if an error occurs
+    */
+   public void stop() throws Throwable
+   {
+      Context context = new InitialContext();
+
+      context.unbind(JNDI_NAME);
+
+      context.close();
+   }
+
+   /**
+    * Get the key
+    * @return The value
+    */
+   private Long getKey()
+   {
+      return Long.valueOf(Thread.currentThread().getId());
+   }
+
+   /**
+    * Get the TxEnv
+    * @return The value
+    */
+   private TxEnv getTxEnv()
+   {
+      Long key = getKey();
+      TxEnv env = txe.get(key);
+      if (env == null)
+      {
+         TxEnv newTxEnv = new TxEnv();
+         env = txe.putIfAbsent(key, newTxEnv);
+         if (env == null)
+         {
+            env = newTxEnv;
+         }
+      }
+
+      return env;
+   }
+
+   /**
+    * Transaction environment
+    */
+   static class TxEnv implements Serializable
+   {
+      private static final long serialVersionUID = 1L;
+      private Map<Object, Object> envs;
+
+      /**
+       * Constructor
+       */
+      TxEnv()
+      {
+         this.envs = new HashMap<Object, Object>(1);
+      }
+
+      /**
+       * Get the environment
+       * @return The value
+       */
+      Map<Object, Object> getEnvironment()
+      {
+         return envs;
+      }
+   }
+}

Added: projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/test/txmgr/TxRegistry.java
===================================================================
--- projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/test/txmgr/TxRegistry.java	                        (rev 0)
+++ projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/test/txmgr/TxRegistry.java	2010-11-11 20:23:08 UTC (rev 109278)
@@ -0,0 +1,82 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, 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.jca.test.txmgr;
+
+import java.io.Serializable;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+
+/**
+ * The transaction registry
+ * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
+ */
+public class TxRegistry implements Serializable
+{
+   private static final long serialVersionUID = 1L;
+   private ConcurrentMap<Long, TransactionImpl> txs;
+
+   /**
+    * Constructor
+    */
+   public TxRegistry()
+   {
+      this.txs = new ConcurrentHashMap<Long, TransactionImpl>();
+   }
+
+   /**
+    * Get the transaction for the current thread
+    * @return The value
+    */
+   public TransactionImpl getTransaction()
+   {
+      Long id = Long.valueOf(Thread.currentThread().getId());
+      return txs.get(id);
+   }
+
+   /**
+    * Start a transaction
+    */
+   public void startTransaction()
+   {
+      Long id = Long.valueOf(Thread.currentThread().getId());
+      txs.put(id, new TransactionImpl());
+   }
+
+   /**
+    * End a transaction
+    */
+   public void endTransaction()
+   {
+      Long id = Long.valueOf(Thread.currentThread().getId());
+      txs.remove(id);
+   }
+
+   /**
+    * Assign a transaction
+    * @param v The value
+    */
+   public void assignTransaction(TransactionImpl v)
+   {
+      Long id = Long.valueOf(Thread.currentThread().getId());
+      txs.put(id, v);
+   }
+}

Added: projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/test/txmgr/UserTransactionImpl.java
===================================================================
--- projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/test/txmgr/UserTransactionImpl.java	                        (rev 0)
+++ projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/test/txmgr/UserTransactionImpl.java	2010-11-11 20:23:08 UTC (rev 109278)
@@ -0,0 +1,174 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, 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.jca.test.txmgr;
+
+import java.io.Serializable;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.transaction.HeuristicMixedException;
+import javax.transaction.HeuristicRollbackException;
+import javax.transaction.NotSupportedException;
+import javax.transaction.RollbackException;
+import javax.transaction.Status;
+import javax.transaction.SystemException;
+import javax.transaction.Transaction;
+import javax.transaction.UserTransaction;
+
+/**
+ * A transaction manager implementation
+ * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
+ */
+public class UserTransactionImpl implements UserTransaction, Serializable
+{
+   private static final long serialVersionUID = 1L;
+   private static final String JNDI_NAME = "java:/UserTransaction";
+   private TxRegistry registry;
+
+   /**
+    * Constructor
+    */
+   public UserTransactionImpl()
+   {
+      this.registry = null;
+   }
+
+   /**
+    * Set the registry
+    * @param v The value
+    */
+   public void setRegistry(TxRegistry v)
+   {
+      registry = v;
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public void begin() throws NotSupportedException,
+                              SystemException
+   {
+      Transaction tx = registry.getTransaction();
+      
+      if (tx != null)
+         throw new NotSupportedException();
+
+      registry.startTransaction();
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public void commit() throws RollbackException,
+                               HeuristicMixedException,
+                               HeuristicRollbackException,
+                               SecurityException,
+                               IllegalStateException,
+                               SystemException
+   {
+      Transaction tx = registry.getTransaction();
+
+      if (tx == null)
+         throw new SystemException();
+
+      if (tx.getStatus() == Status.STATUS_ROLLEDBACK ||
+          tx.getStatus() == Status.STATUS_MARKED_ROLLBACK)
+         throw new RollbackException();
+
+      registry.endTransaction();
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public void rollback() throws IllegalStateException,
+                                 SecurityException,
+                                 SystemException
+   {
+      Transaction tx = registry.getTransaction();
+
+      if (tx == null)
+         throw new IllegalStateException();
+
+      registry.endTransaction();
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public void setRollbackOnly() throws IllegalStateException,
+                                        SystemException
+   {
+      Transaction tx = registry.getTransaction();
+
+      if (tx == null)
+         throw new IllegalStateException();
+
+      tx.setRollbackOnly();
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public int getStatus() throws SystemException
+   {
+      Transaction tx = registry.getTransaction();
+
+      if (tx == null)
+         return Status.STATUS_NO_TRANSACTION;
+
+      return tx.getStatus();
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public void setTransactionTimeout(int seconds) throws SystemException
+   {
+   }
+
+   /**
+    * Start
+    * @exception Throwable Thrown if an error occurs
+    */
+   public void start() throws Throwable
+   {
+      Context context = new InitialContext();
+
+      context.bind(JNDI_NAME, this);
+
+      context.close();
+   }
+
+   /**
+    * Stop
+    * @exception Throwable Thrown if an error occurs
+    */
+   public void stop() throws Throwable
+   {
+      Context context = new InitialContext();
+
+      context.unbind(JNDI_NAME);
+
+      context.close();
+   }
+}

Added: projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/test/txmgr/package.html
===================================================================
--- projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/test/txmgr/package.html	                        (rev 0)
+++ projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/test/txmgr/package.html	2010-11-11 20:23:08 UTC (rev 109278)
@@ -0,0 +1,3 @@
+<body>
+This package contains a no-operation transaction manager implementation which can be used instead of a real implementation
+</body>

Added: projects/jboss-jca/trunk/core/src/test/resources/txmgr-jboss-beans.xml
===================================================================
--- projects/jboss-jca/trunk/core/src/test/resources/txmgr-jboss-beans.xml	                        (rev 0)
+++ projects/jboss-jca/trunk/core/src/test/resources/txmgr-jboss-beans.xml	2010-11-11 20:23:08 UTC (rev 109278)
@@ -0,0 +1,51 @@
+<deployment>
+
+  <!-- Transaction registry -->
+  <bean name="TxRegistry"
+        class="org.jboss.jca.test.txmgr.TxRegistry">
+  </bean>
+
+  <!-- User transaction registry -->
+  <bean name="UserTxRegistry"
+        class="org.jboss.jca.test.txmgr.TxRegistry">
+  </bean>
+
+  <!-- XATerminator -->
+  <bean name="XATerminator"
+        interface="org.jboss.tm.JBossXATerminator" 
+        class="org.jboss.jca.test.txmgr.JBossXATerminatorImpl">
+  </bean>
+
+  <!-- Transaction manager -->
+  <bean name="TransactionManager"
+        interface="javax.transaction.TransactionManager" 
+        class="org.jboss.jca.test.txmgr.TransactionManagerImpl">
+    <property name="Registry"><inject bean="TxRegistry"/></property>
+    <property name="XATerminator"><inject bean="XATerminator"/></property>
+  </bean>
+
+  <!-- Real Transaction manager -->
+  <bean name="RealTransactionManager"
+        interface="javax.transaction.TransactionManager" 
+        class="org.jboss.jca.test.txmgr.RealTransactionManagerImpl">
+    <property name="Registry"><inject bean="TxRegistry"/></property>
+    <depends>NamingServer</depends>
+  </bean>
+
+  <!-- TransactionSynchronizationRegistry -->
+  <bean name="TransactionSynchronizationRegistry"
+        interface="javax.transaction.TransactionSynchronizationRegistry" 
+        class="org.jboss.jca.test.txmgr.TransactionSynchronizationRegistryImpl">
+    <property name="Registry"><inject bean="TxRegistry"/></property>
+    <depends>NamingServer</depends>
+  </bean>
+
+  <!-- UserTransaction -->
+  <bean name="UserTransaction"
+        interface="javax.transaction.UserTransaction" 
+        class="org.jboss.jca.test.txmgr.UserTransactionImpl">
+    <property name="Registry"><inject bean="UserTxRegistry"/></property>
+    <depends>NamingServer</depends>
+  </bean>
+
+</deployment>



More information about the jboss-cvs-commits mailing list