geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject cvs commit: incubator-geronimo/modules/transaction/src/test/org/apache/geronimo/transaction/manager MockResource.java MockResourceManager.java TestTransactionManager.java XATransactionTester.java
Date Fri, 23 Jan 2004 18:54:16 GMT
dain        2004/01/23 10:54:16

  Added:       modules/transaction .cvsignore project.properties
                        project.xml
               modules/transaction/src/java/org/apache/geronimo/transaction
                        GeronimoRollbackException.java
                        GeronimoTransactionRolledbackException.java
                        GeronimoTransactionRolledbackLocalException.java
                        TransactionManagerProxy.java TransactionProxy.java
               modules/transaction/src/java/org/apache/geronimo/transaction/log
                        UnrecoverableLog.java
               modules/transaction/src/java/org/apache/geronimo/transaction/manager
                        TransactionImpl.java TransactionLog.java
                        TransactionManagerImpl.java
                        UserTransactionImpl.java XidFactory.java
                        XidImpl.java
               modules/transaction/src/test/org/apache/geronimo/transaction/manager
                        MockResource.java MockResourceManager.java
                        TestTransactionManager.java
                        XATransactionTester.java
  Log:
  Moved from core module
  
  Revision  Changes    Path
  1.1                  incubator-geronimo/modules/transaction/.cvsignore
  
  Index: .cvsignore
  ===================================================================
  target
  maven.log
  junit64798903.properties
  
  
  
  1.1                  incubator-geronimo/modules/transaction/project.properties
  
  Index: project.properties
  ===================================================================
  ##
  ## $Revision: 1.1 $ $Date: 2004/01/23 18:54:15 $
  ##
  
  maven.repo.remote=http://www.apache.org/~dain/maven, http://www.ibiblio.org/maven
  
  
  
  1.1                  incubator-geronimo/modules/transaction/project.xml
  
  Index: project.xml
  ===================================================================
  <?xml version="1.0" encoding="ISO-8859-1"?>
  
  <!-- $Revision: 1.1 $ $Date: 2004/01/23 18:54:15 $ -->
  
  <project>
      <pomVersion>3</pomVersion>
      <extend>${basedir}/../../etc/project.xml</extend>
  
      <!-- ===================== -->
      <!-- Module Identification -->
      <!-- ===================== -->
  
      <name>Geronimo :: Transaction</name>
      <id>geronimo-transaction</id>
      <shortDescription>Geronimo Transaction</shortDescription>
      <description>Geronimo Transaction</description>
      <url>http://incubator.apache.org/projects/geronimo/transaction/</url>
      <siteDirectory>/www/incubator.apache.org/projects/geronimo/transaction</siteDirectory>
      <distributionDirectory>/www/incubator.apache.org/projects/geronimo/builds/transaction</distributionDirectory>
  
      <currentVersion>DEV</currentVersion>
  
      <!-- ============ -->
      <!-- Dependencies -->
      <!-- ============ -->
  
      <dependencies>
  
          <!-- Module Dependencies -->
  
          <dependency>
              <groupId>geronimo</groupId>
              <artifactId>geronimo-kernel</artifactId>
              <version>DEV</version>
              <properties>
                  <module>true</module>
              </properties>
          </dependency>
  
          <dependency>
              <groupId>geronimo-spec</groupId>
              <artifactId>geronimo-spec-jta</artifactId>
              <version>DEV</version>
              <properties>
                  <module>true</module>
              </properties>
          </dependency>
  
          <dependency>
              <groupId>geronimo-spec</groupId>
              <artifactId>geronimo-spec-ejb</artifactId>
              <version>DEV</version>
              <properties>
                  <module>true</module>
              </properties>
          </dependency>
  
          <dependency>
              <groupId>geronimo-spec</groupId>
              <artifactId>geronimo-spec-j2ee-connector</artifactId>
              <version>DEV</version>
              <properties>
                  <module>true</module>
              </properties>
          </dependency>
  
          <!-- Thirdparty -->
  
          <dependency>
              <id>commons-logging</id>
              <version>1.0.3</version>
              <url>http://jakarta.apache.org/commons/logging/</url>
              <properties>
                  <runtime>false</runtime>
              </properties>
          </dependency>
  
      </dependencies>
  </project>
  
  
  
  1.1                  incubator-geronimo/modules/transaction/src/java/org/apache/geronimo/transaction/GeronimoRollbackException.java
  
  Index: GeronimoRollbackException.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Geronimo" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Geronimo", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
  package org.apache.geronimo.transaction;
  
  
  /**
   *
   *
   *
   * @version $Revision: 1.1 $ $Date: 2004/01/23 18:54:15 $
   * @todo investigate using the 1.4 cause instead
   */
  public class GeronimoRollbackException extends RuntimeException {
      public GeronimoRollbackException() {
      }
  
      public GeronimoRollbackException(String message) {
          super(message);
      }
  
      public GeronimoRollbackException(String message, Throwable cause) {
          super(message, cause);
      }
  
      public GeronimoRollbackException(Throwable cause) {
          super(cause);
      }
  }
  
  
  
  1.1                  incubator-geronimo/modules/transaction/src/java/org/apache/geronimo/transaction/GeronimoTransactionRolledbackException.java
  
  Index: GeronimoTransactionRolledbackException.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Geronimo" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Geronimo", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
  package org.apache.geronimo.transaction;
  
  import javax.transaction.TransactionRolledbackException;
  
  /**
   *
   *
   *
   * @version $Revision: 1.1 $ $Date: 2004/01/23 18:54:15 $
   * @todo investigate using the 1.4 cause instead
   */
  public class GeronimoTransactionRolledbackException extends TransactionRolledbackException {
      public GeronimoTransactionRolledbackException() {
      }
  
      public GeronimoTransactionRolledbackException(String s) {
          super(s);
      }
  
      public GeronimoTransactionRolledbackException(String s, Throwable t) {
          super(s);
          this.detail = t;
      }
  
      public GeronimoTransactionRolledbackException(Throwable t) {
          super();
          this.detail = t;
      }
  }
  
  
  
  1.1                  incubator-geronimo/modules/transaction/src/java/org/apache/geronimo/transaction/GeronimoTransactionRolledbackLocalException.java
  
  Index: GeronimoTransactionRolledbackLocalException.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Geronimo" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Geronimo", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
  package org.apache.geronimo.transaction;
  
  import javax.ejb.TransactionRolledbackLocalException;
  
  /**
   *
   *
   *
   * @version $Revision: 1.1 $ $Date: 2004/01/23 18:54:15 $
   * @todo investigate using the 1.4 cause instead
   */
  public class GeronimoTransactionRolledbackLocalException extends TransactionRolledbackLocalException {
      public GeronimoTransactionRolledbackLocalException() {
      }
  
      public GeronimoTransactionRolledbackLocalException(String s) {
          super(s);
      }
  
      public GeronimoTransactionRolledbackLocalException(String s, Exception e) {
          super(s, e);
      }
  
      public GeronimoTransactionRolledbackLocalException(Exception e) {
          super(null, e);
      }
  }
  
  
  
  1.1                  incubator-geronimo/modules/transaction/src/java/org/apache/geronimo/transaction/TransactionManagerProxy.java
  
  Index: TransactionManagerProxy.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Geronimo" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Geronimo", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
  package org.apache.geronimo.transaction;
  
  import javax.resource.spi.XATerminator;
  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 javax.transaction.xa.XAException;
  import javax.transaction.xa.Xid;
  
  import org.apache.geronimo.gbean.GBeanInfo;
  import org.apache.geronimo.gbean.GBeanInfoFactory;
  import org.apache.geronimo.gbean.GOperationInfo;
  import org.apache.geronimo.transaction.manager.TransactionManagerImpl;
  
  /**
   * A wrapper for a TransactionManager that wraps all Transactions in a TransactionProxy
   * so that we can add addition metadata to the Transaction. Only begin (and setTransactionTimeout)
   * are delegated to the wrapped TransactionManager; all other operations are delegated to the
   * wrapped Transaction.
   *
   * @version $Revision: 1.1 $ $Date: 2004/01/23 18:54:15 $
   */
  public class TransactionManagerProxy implements TransactionManager, XATerminator {
  
      private static final GBeanInfo GBEAN_INFO;
  
      private final TransactionManager delegate;
      private final ThreadLocal threadTx = new ThreadLocal();
  
      /**
       * Constructor taking the TransactionManager to wrap.
       * @param delegate the TransactionManager that should be wrapped
       */
      public TransactionManagerProxy(TransactionManager delegate) {
          this.delegate = delegate;
      }
  
      /**
       * Possibly temporary constructor to enable deploying this as a geronimo mbean w/o a managed constructor.
       */
      public TransactionManagerProxy() {
          this.delegate = new TransactionManagerImpl();
      }
  
      public void setTransactionTimeout(int timeout) throws SystemException {
          delegate.setTransactionTimeout(timeout);
      }
  
      public void begin() throws NotSupportedException, SystemException {
          delegate.begin();
          threadTx.set(new TransactionProxy(delegate.getTransaction()));
      }
  
      public int getStatus() throws SystemException {
          Transaction tx = getTransaction();
          return (tx != null) ? tx.getStatus() : Status.STATUS_NO_TRANSACTION;
      }
  
      public Transaction getTransaction() throws SystemException {
          return (Transaction) threadTx.get();
      }
  
      public Transaction suspend() throws SystemException {
          Transaction tx = getTransaction();
          threadTx.set(null);
          return tx;
      }
  
      public void resume(Transaction tx) throws IllegalStateException, InvalidTransactionException, SystemException {
          if (threadTx.get() != null) {
              throw new IllegalStateException("Transaction already associated with current thread");
          }
          if (tx instanceof TransactionProxy == false) {
              throw new InvalidTransactionException("Cannot resume foreign transaction: " + tx);
          }
          threadTx.set(tx);
      }
  
      public void commit() throws HeuristicMixedException, HeuristicRollbackException, IllegalStateException, RollbackException, SecurityException, SystemException {
          Transaction tx = getTransaction();
          if (tx == null) {
              throw new IllegalStateException("No transaction associated with current thread");
          }
          try {
              tx.commit();
          } finally {
              threadTx.set(null);
          }
      }
  
      public void rollback() throws IllegalStateException, SecurityException, SystemException {
          Transaction tx = getTransaction();
          if (tx == null) {
              throw new IllegalStateException("No transaction associated with current thread");
          }
          try {
              tx.rollback();
          } finally {
              threadTx.set(null);
          }
      }
  
      public void setRollbackOnly() throws IllegalStateException, SystemException {
          Transaction tx = getTransaction();
          if (tx == null) {
              throw new IllegalStateException("No transaction associated with current thread");
          }
          tx.setRollbackOnly();
      }
  
      /**
       * @see javax.resource.spi.XATerminator#commit(javax.transaction.xa.Xid, boolean)
       */
      public void commit(Xid arg0, boolean arg1) throws XAException {
          throw new XAException("Not implemented.");
      }
  
      /**
       * @see javax.resource.spi.XATerminator#forget(javax.transaction.xa.Xid)
       */
      public void forget(Xid arg0) throws XAException {
          throw new XAException("Not implemented.");
      }
  
      /**
       * @see javax.resource.spi.XATerminator#prepare(javax.transaction.xa.Xid)
       */
      public int prepare(Xid arg0) throws XAException {
          throw new XAException("Not implemented.");
      }
  
      /**
       * @see javax.resource.spi.XATerminator#recover(int)
       */
      public Xid[] recover(int arg0) throws XAException {
          throw new XAException("Not implemented.");
      }
  
      /**
       * @see javax.resource.spi.XATerminator#rollback(javax.transaction.xa.Xid)
       */
      public void rollback(Xid arg0) throws XAException {
          throw new XAException("Not implemented.");
      }
  
      //for now we use the default constructor.
      static {
          GBeanInfoFactory infoFactory = new GBeanInfoFactory(TransactionManagerProxy.class.getName());
          infoFactory.addOperation(new GOperationInfo("setTransactionTimeout", new String[] {Integer.TYPE.getName()}));
          infoFactory.addOperation(new GOperationInfo("begin"));
          infoFactory.addOperation(new GOperationInfo("getStatus"));
          infoFactory.addOperation(new GOperationInfo("getTransaction"));
          infoFactory.addOperation(new GOperationInfo("suspend"));
          infoFactory.addOperation(new GOperationInfo("resume", new String[] {Transaction.class.getName()}));
          infoFactory.addOperation(new GOperationInfo("commit"));
          infoFactory.addOperation(new GOperationInfo("rollback"));
          infoFactory.addOperation(new GOperationInfo("setRollbackOnly"));
          GBEAN_INFO = infoFactory.getBeanInfo();
      }
  
      public static GBeanInfo getGBeanInfo() {
          return GBEAN_INFO;
      }
  
  }
  
  
  
  1.1                  incubator-geronimo/modules/transaction/src/java/org/apache/geronimo/transaction/TransactionProxy.java
  
  Index: TransactionProxy.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Geronimo" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Geronimo", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
  package org.apache.geronimo.transaction;
  
  import javax.transaction.Transaction;
  import javax.transaction.HeuristicMixedException;
  import javax.transaction.HeuristicRollbackException;
  import javax.transaction.RollbackException;
  import javax.transaction.SystemException;
  import javax.transaction.Synchronization;
  import javax.transaction.xa.XAResource;
  
  /**
   * Our version of a JTA Transaction which also carries metadata such as isolation level
   * and write-intent. Delegates all Transaction methods to a real Transaction obtained from
   * the vendor's TransactionManager.
   *
   *
   * @version $Revision: 1.1 $ $Date: 2004/01/23 18:54:15 $
   */
  public class TransactionProxy implements Transaction {
      private final Transaction delegate;
  
      public TransactionProxy(Transaction delegate) {
          this.delegate = delegate;
      }
  
      public void commit() throws HeuristicMixedException, HeuristicRollbackException, RollbackException, SecurityException, SystemException {
          delegate.commit();
      }
  
      public boolean delistResource(XAResource xaResource, int i) throws IllegalStateException, SystemException {
          return delegate.delistResource(xaResource, i);
      }
  
      public boolean enlistResource(XAResource xaResource) throws IllegalStateException, RollbackException, SystemException {
          return delegate.enlistResource(xaResource);
      }
  
      public int getStatus() throws SystemException {
          return delegate.getStatus();
      }
  
      public void registerSynchronization(Synchronization synchronization) throws IllegalStateException, RollbackException, SystemException {
          delegate.registerSynchronization(synchronization);
      }
  
      public void rollback() throws IllegalStateException, SystemException {
          delegate.rollback();
      }
  
      public void setRollbackOnly() throws IllegalStateException, SystemException {
          delegate.setRollbackOnly();
      }
  }
  
  
  
  1.1                  incubator-geronimo/modules/transaction/src/java/org/apache/geronimo/transaction/log/UnrecoverableLog.java
  
  Index: UnrecoverableLog.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Geronimo" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Geronimo", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
  package org.apache.geronimo.transaction.log;
  
  import java.io.IOException;
  import javax.transaction.xa.Xid;
  
  import org.apache.geronimo.transaction.manager.TransactionLog;
  
  /**
   * A log sink that doesn't actually do anything.
   * Not recommended for production use as heuristic recovery will be needed if
   * the transaction coordinator dies.
   *
   * @version $Revision: 1.1 $ $Date: 2004/01/23 18:54:16 $
   */
  public class UnrecoverableLog implements TransactionLog {
      public void begin(Xid xid) throws IOException {
      }
  
      public void prepare(Xid xid) throws IOException {
      }
  
      public void commit(Xid xid) throws IOException {
      }
  
      public void rollback(Xid xid) throws IOException {
      }
  }
  
  
  
  1.1                  incubator-geronimo/modules/transaction/src/java/org/apache/geronimo/transaction/manager/TransactionImpl.java
  
  Index: TransactionImpl.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Geronimo" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Geronimo", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
  package org.apache.geronimo.transaction.manager;
  
  import java.io.IOException;
  import java.util.ArrayList;
  import java.util.HashMap;
  import java.util.Iterator;
  import java.util.LinkedList;
  import java.util.List;
  import java.util.Map;
  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.XAException;
  import javax.transaction.xa.XAResource;
  import javax.transaction.xa.Xid;
  
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  
  /**
   * Basic local transaction with support for multiple resources.
   *
   * @version $Revision: 1.1 $ $Date: 2004/01/23 18:54:16 $
   */
  public class TransactionImpl implements Transaction {
      private static final Log log = LogFactory.getLog("Transaction");
  
      private final XidFactory xidFactory;
      private final Xid xid;
      private final TransactionLog txnLog;
      private int status = Status.STATUS_NO_TRANSACTION;
      private List syncList = new ArrayList(5);
      private LinkedList resourceManagers = new LinkedList();
      private Map xaResources = new HashMap(3);
  
      TransactionImpl(XidFactory xidFactory, TransactionLog txnLog) throws SystemException {
          this.xidFactory = xidFactory;
          this.txnLog = txnLog;
          this.xid = xidFactory.createXid();
          try {
              txnLog.begin(xid);
          } catch (IOException e) {
              status = Status.STATUS_MARKED_ROLLBACK;
              SystemException ex = new SystemException("Error logging begin; transaction marked for roll back)");
              ex.initCause(e);
              throw ex;
          }
          status = Status.STATUS_ACTIVE;
      }
  
      public synchronized int getStatus() throws SystemException {
          return status;
      }
  
      public synchronized void setRollbackOnly() throws IllegalStateException, SystemException {
          switch (status) {
          case Status.STATUS_ACTIVE:
          case Status.STATUS_PREPARING:
              status = Status.STATUS_MARKED_ROLLBACK;
              break;
          case Status.STATUS_MARKED_ROLLBACK:
          case Status.STATUS_ROLLING_BACK:
              // nothing to do
              break;
          default:
              throw new IllegalStateException("Cannot set rollback only, status is " + getStateString(status));
          }
      }
  
      public synchronized void registerSynchronization(Synchronization synch) throws IllegalStateException, RollbackException, SystemException {
          if (synch == null) {
              throw new IllegalArgumentException("Synchronization is null");
          }
          switch (status) {
          case Status.STATUS_ACTIVE:
          case Status.STATUS_PREPARING:
              break;
          case Status.STATUS_MARKED_ROLLBACK:
              throw new RollbackException("Transaction is marked for rollback");
          default:
              throw new IllegalStateException("Status is " + getStateString(status));
          }
          syncList.add(synch);
      }
  
      public synchronized boolean enlistResource(XAResource xaRes) throws IllegalStateException, RollbackException, SystemException {
          if (xaRes == null) {
              throw new IllegalArgumentException("XAResource is null");
          }
          switch (status) {
          case Status.STATUS_ACTIVE:
              break;
          case Status.STATUS_MARKED_ROLLBACK:
              throw new RollbackException("Transaction is marked for rollback");
          default:
              throw new IllegalStateException("Status is " + getStateString(status));
          }
  
          try {
              for (Iterator i = resourceManagers.iterator(); i.hasNext();) {
                  ResourceManager manager = (ResourceManager) i.next();
                  boolean sameRM;
                  //if the xares is already known, we must be resuming after a suspend.
                  if (xaRes == manager.committer) {
                      xaRes.start(manager.branchId, XAResource.TMRESUME);
                      return true;
                  }
                  //Otherwise, see if this is a new xares for the same resource manager
                  try {
                      sameRM = xaRes.isSameRM(manager.committer);
                  } catch (XAException e) {
                      log.warn("Unexpected error checking for same RM", e);
                      continue;
                  }
                  if (sameRM) {
                      xaRes.start(manager.branchId, XAResource.TMJOIN);
                      xaResources.put(xaRes, manager);
                      return true;
                  }
              }
  
              Xid branchId = xidFactory.createBranch(xid, resourceManagers.size() + 1);
              xaRes.start(branchId, XAResource.TMNOFLAGS);
              ResourceManager manager = new ResourceManager(xaRes, branchId);
              resourceManagers.add(manager);
              xaResources.put(xaRes, manager);
              return true;
          } catch (XAException e) {
              log.warn("Unable to enlist XAResource " + xaRes, e);
              return false;
          }
      }
  
      public synchronized boolean delistResource(XAResource xaRes, int flag) throws IllegalStateException, SystemException {
          if (xaRes == null) {
              throw new IllegalArgumentException("XAResource is null");
          }
          switch (status) {
          case Status.STATUS_ACTIVE:
          case Status.STATUS_MARKED_ROLLBACK:
              break;
          default:
              throw new IllegalStateException("Status is " + getStateString(status));
          }
          ResourceManager manager = (ResourceManager) xaResources.remove(xaRes);
          if (manager == null) {
              throw new IllegalStateException("Resource not enlisted");
          }
          try {
              xaRes.end(manager.branchId, flag);
              return true;
          } catch (XAException e) {
              log.warn("Unable to delist XAResource " + xaRes, e);
              return false;
          }
      }
  
      public void commit() throws HeuristicMixedException, HeuristicRollbackException, RollbackException, SecurityException, SystemException {
          synchronized (this) {
              switch (status) {
              case Status.STATUS_ACTIVE:
              case Status.STATUS_MARKED_ROLLBACK:
                  break;
              default:
                  throw new IllegalStateException("Status is " + getStateString(status));
              }
          }
  
          beforeCompletion();
          endResources();
          try {
              LinkedList rms;
              synchronized (this) {
                  if (status == Status.STATUS_ACTIVE) {
                      if (resourceManagers.size() == 0) {
                          // nothing to commit
                          status = Status.STATUS_COMMITTED;
                      } else if (resourceManagers.size() == 1) {
                          // one-phase commit decision
                          status = Status.STATUS_COMMITTING;
                      } else {
                          // start prepare part of two-phase
                          status = Status.STATUS_PREPARING;
                      }
                  }
                  // resourceManagers is now immutable
                  rms = resourceManagers;
              }
  
              // one-phase
              if (rms.size() == 1) {
                  ResourceManager manager = (ResourceManager) rms.getFirst();
                  try {
                      manager.committer.commit(manager.branchId, true);
                      synchronized (this) {
                          status = Status.STATUS_COMMITTED;
                      }
                      return;
                  } catch (XAException e) {
                      synchronized (this) {
                          status = Status.STATUS_ROLLEDBACK;
                      }
                      RollbackException ex = new RollbackException("Error during one-phase commit");
                      ex.initCause(e);
                      throw ex;
                  }
              }
  
              // two-phase
              try {
                  txnLog.prepare(xid);
              } catch (IOException e) {
                  try {
                      rollbackResources(rms);
                  } catch (Exception se) {
                      log.error("Unable to rollback after failure to log prepare", se.getCause());
                  }
                  SystemException ex = new SystemException("Error logging prepare; transaction was rolled back)");
                  ex.initCause(e);
                  throw ex;
              }
              for (Iterator i = rms.iterator(); i.hasNext();) {
                  synchronized (this) {
                      if (status != Status.STATUS_PREPARING) {
                          // we were marked for rollback
                          break;
                      }
                  }
                  ResourceManager manager = (ResourceManager) i.next();
                  try {
                      int vote = manager.committer.prepare(manager.branchId);
                      if (vote == XAResource.XA_RDONLY) {
                          // we don't need to consider this RM any more
                          i.remove();
                      }
                  } catch (XAException e) {
                      synchronized (this) {
                          status = Status.STATUS_MARKED_ROLLBACK;
                      }
                  }
              }
  
              // decision time...
              boolean willCommit;
              synchronized (this) {
                  willCommit = (status != Status.STATUS_MARKED_ROLLBACK);
                  if (willCommit) {
                      status = Status.STATUS_PREPARED;
                  }
              }
  
              // log our decision
              try {
                  if (willCommit) {
                      txnLog.commit(xid);
                  } else {
                      txnLog.rollback(xid);
                  }
              } catch (IOException e) {
                  try {
                      rollbackResources(rms);
                  } catch (Exception se) {
                      log.error("Unable to rollback after failure to log decision", se.getCause());
                  }
                  SystemException ex = new SystemException("Error logging decision (outcome is unknown)");
                  ex.initCause(e);
                  throw ex;
              }
  
              // notify the RMs
              if (willCommit) {
                  commitResources(rms);
              } else {
                  rollbackResources(rms);
                  throw new RollbackException("Unable to commit");
              }
          } finally {
              afterCompletion();
              synchronized (this) {
                  status = Status.STATUS_NO_TRANSACTION;
              }
          }
      }
  
      public void rollback() throws IllegalStateException, SystemException {
          List rms;
          synchronized (this) {
              switch (status) {
              case Status.STATUS_ACTIVE:
                  status = Status.STATUS_MARKED_ROLLBACK;
                  break;
              case Status.STATUS_MARKED_ROLLBACK:
                  break;
              default:
                  throw new IllegalStateException("Status is " + getStateString(status));
              }
              rms = resourceManagers;
          }
  
          beforeCompletion();
          endResources();
          try {
              try {
                  txnLog.rollback(xid);
              } catch (IOException e) {
                  try {
                      rollbackResources(rms);
                  } catch (Exception se) {
                      log.error("Unable to rollback after failure to log decision", se.getCause());
                  }
                  SystemException ex = new SystemException("Error logging rollback");
                  ex.initCause(e);
                  throw ex;
              }
              rollbackResources(rms);
          } finally {
              afterCompletion();
              synchronized (this) {
                  status = Status.STATUS_NO_TRANSACTION;
              }
          }
      }
  
      private void beforeCompletion() {
          int i = 0;
          while (true) {
              Synchronization synch;
              synchronized (this) {
                  if (i == syncList.size()) {
                      return;
                  }
                  synch = (Synchronization) syncList.get(i++);
              }
              try {
                  synch.beforeCompletion();
              } catch (Exception e) {
                  log.warn("Unexpected exception from beforeCompletion; transaction will roll back", e);
                  synchronized (this) {
                      status = Status.STATUS_MARKED_ROLLBACK;
                  }
              }
          }
      }
  
      private void afterCompletion() {
          // this does not synchronize because nothing can modify our state at this time
          for (Iterator i = syncList.iterator(); i.hasNext();) {
              Synchronization synch = (Synchronization) i.next();
              try {
                  synch.afterCompletion(status);
              } catch (Exception e) {
                  log.warn("Unexpected exception from afterCompletion; continuing", e);
                  continue;
              }
          }
      }
  
      private void endResources() {
          while (true) {
              XAResource xaRes;
              ResourceManager manager;
              int flags;
              synchronized (this) {
                  Set entrySet = xaResources.entrySet();
                  if (entrySet.isEmpty()) {
                      return;
                  }
                  Map.Entry entry = (Map.Entry) entrySet.iterator().next();
                  xaRes = (XAResource) entry.getKey();
                  manager = (ResourceManager) entry.getValue();
                  flags = (status == Status.STATUS_MARKED_ROLLBACK) ? XAResource.TMFAIL : XAResource.TMSUCCESS;
                  xaResources.remove(xaRes);
              }
              try {
                  xaRes.end(manager.branchId, flags);
              } catch (XAException e) {
                  log.warn("Error ending association for XAResource " + xaRes + "; transaction will roll back", e);
                  synchronized (this) {
                      status = Status.STATUS_MARKED_ROLLBACK;
                  }
              }
          }
      }
  
      private void rollbackResources(List rms) throws SystemException {
          SystemException cause = null;
          synchronized (this) {
              status = Status.STATUS_ROLLING_BACK;
          }
          for (Iterator i = rms.iterator(); i.hasNext();) {
              ResourceManager manager = (ResourceManager) i.next();
              try {
                  manager.committer.rollback(manager.branchId);
              } catch (XAException e) {
                  log.error("Unexpected exception rolling back " + manager.committer + "; continuing with rollback", e);
                  if (cause == null) {
                      cause = new SystemException(e.errorCode);
                  }
                  continue;
              }
          }
          synchronized (this) {
              status = Status.STATUS_ROLLEDBACK;
          }
          if (cause != null) {
              throw cause;
          }
      }
  
      private void commitResources(List rms) throws SystemException {
          SystemException cause = null;
          synchronized (this) {
              status = Status.STATUS_COMMITTING;
          }
          for (Iterator i = rms.iterator(); i.hasNext();) {
              ResourceManager manager = (ResourceManager) i.next();
              try {
                  manager.committer.commit(manager.branchId, false);
              } catch (XAException e) {
                  log.error("Unexpected exception committing" + manager.committer + "; continuing to commit other RMs", e);
                  if (cause == null) {
                      cause = new SystemException(e.errorCode);
                  }
                  continue;
              }
          }
          synchronized (this) {
              status = Status.STATUS_COMMITTED;
          }
          if (cause != null) {
              throw cause;
          }
      }
  
      private static String getStateString(int status) {
          switch (status) {
          case Status.STATUS_ACTIVE:
              return "STATUS_ACTIVE";
          case Status.STATUS_PREPARING:
              return "STATUS_PREPARING";
          case Status.STATUS_PREPARED:
              return "STATUS_PREPARED";
          case Status.STATUS_MARKED_ROLLBACK:
              return "STATUS_MARKED_ROLLBACK";
          case Status.STATUS_ROLLING_BACK:
              return "STATUS_ROLLING_BACK";
          case Status.STATUS_COMMITTING:
              return "STATUS_COMMITTING";
          case Status.STATUS_COMMITTED:
              return "STATUS_COMMITTED";
          case Status.STATUS_ROLLEDBACK:
              return "STATUS_ROLLEDBACK";
          case Status.STATUS_NO_TRANSACTION:
              return "STATUS_NO_TRANSACTION";
          case Status.STATUS_UNKNOWN:
              return "STATUS_UNKNOWN";
          default:
              throw new AssertionError();
          }
      }
  
      public boolean equals(Object obj) {
          if (obj instanceof TransactionImpl) {
              TransactionImpl other = (TransactionImpl) obj;
              return xid.equals(other.xid);
          } else {
              return false;
          }
      }
  
      private static class ResourceManager {
          private final XAResource committer;
          private final Xid branchId;
  
          public ResourceManager(XAResource xaRes, Xid branchId) {
              committer = xaRes;
              this.branchId = branchId;
          }
      }
  }
  
  
  
  1.1                  incubator-geronimo/modules/transaction/src/java/org/apache/geronimo/transaction/manager/TransactionLog.java
  
  Index: TransactionLog.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Geronimo" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Geronimo", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
  package org.apache.geronimo.transaction.manager;
  
  import java.io.IOException;
  import javax.transaction.xa.Xid;
  
  /**
   * Interface used to notify a logging subsystem of transaction events.
   *
   * @version $Revision: 1.1 $ $Date: 2004/01/23 18:54:16 $
   */
  public interface TransactionLog {
      public void begin(Xid xid) throws IOException;
  
      public void prepare(Xid xid) throws IOException;
  
      public void commit(Xid xid) throws IOException;
  
      public void rollback(Xid xid) throws IOException;
  }
  
  
  
  1.1                  incubator-geronimo/modules/transaction/src/java/org/apache/geronimo/transaction/manager/TransactionManagerImpl.java
  
  Index: TransactionManagerImpl.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Geronimo" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Geronimo", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
  package org.apache.geronimo.transaction.manager;
  
  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.apache.geronimo.transaction.log.UnrecoverableLog;
  
  /**
   * Simple implementation of a local transaction manager.
   *
   * @version $Revision: 1.1 $ $Date: 2004/01/23 18:54:16 $
   */
  public class TransactionManagerImpl implements TransactionManager {
      private final TransactionLog txnLog;
      private final XidFactory xidFactory = new XidFactory();
      private volatile int timeout;
      private final ThreadLocal threadTx = new ThreadLocal();
  
      public TransactionManagerImpl() {
          txnLog = new UnrecoverableLog();
      }
  
      public TransactionManagerImpl(TransactionLog txnLog) {
          this.txnLog = txnLog;
      }
  
      public Transaction getTransaction() throws SystemException {
          return (Transaction) threadTx.get();
      }
  
      public void setTransactionTimeout(int seconds) throws SystemException {
          timeout = seconds;
      }
  
      public int getStatus() throws SystemException {
          Transaction tx = getTransaction();
          return (tx != null) ? tx.getStatus() : Status.STATUS_NO_TRANSACTION;
      }
  
      public void begin() throws NotSupportedException, SystemException {
          if (getStatus() != Status.STATUS_NO_TRANSACTION) {
              throw new NotSupportedException("Nested Transactions are not supported");
          }
          TransactionImpl tx = new TransactionImpl(xidFactory, txnLog);
          threadTx.set(tx);
      }
  
      public Transaction suspend() throws SystemException {
          Transaction tx = getTransaction();
          threadTx.set(null);
          return tx;
      }
  
      public void resume(Transaction tx) throws IllegalStateException, InvalidTransactionException, SystemException {
          if (threadTx.get() != null) {
              throw new IllegalStateException("Transaction already associated with current thread");
          }
          if (tx instanceof TransactionImpl == false) {
              throw new InvalidTransactionException("Cannot resume foreign transaction: " + tx);
          }
          threadTx.set(tx);
      }
  
      public void setRollbackOnly() throws IllegalStateException, SystemException {
          Transaction tx = getTransaction();
          if (tx == null) {
              throw new IllegalStateException("No transaction associated with current thread");
          }
          tx.setRollbackOnly();
      }
  
      public void commit() throws HeuristicMixedException, HeuristicRollbackException, IllegalStateException, RollbackException, SecurityException, SystemException {
          Transaction tx = getTransaction();
          if (tx == null) {
              throw new IllegalStateException("No transaction associated with current thread");
          }
          try {
              tx.commit();
          } finally {
              threadTx.set(null);
          }
      }
  
      public void rollback() throws IllegalStateException, SecurityException, SystemException {
          Transaction tx = getTransaction();
          if (tx == null) {
              throw new IllegalStateException("No transaction associated with current thread");
          }
          try {
              tx.rollback();
          } finally {
              threadTx.set(null);
          }
      }
  }
  
  
  
  1.1                  incubator-geronimo/modules/transaction/src/java/org/apache/geronimo/transaction/manager/UserTransactionImpl.java
  
  Index: UserTransactionImpl.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Geronimo" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Geronimo", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
  package org.apache.geronimo.transaction.manager;
  
  import java.io.Serializable;
  
  import javax.transaction.HeuristicMixedException;
  import javax.transaction.HeuristicRollbackException;
  import javax.transaction.NotSupportedException;
  import javax.transaction.RollbackException;
  import javax.transaction.SystemException;
  import javax.transaction.TransactionManager;
  import javax.transaction.UserTransaction;
  
  //import org.apache.geronimo.connector.outbound.connectiontracking.TrackedConnectionAssociator;
  
  /**
   * TODO this needs to migrate to using TransactionContext.
   * TODO this needs to notify the TrackedConnectionAssociator when a tx starts.
   *
   *
   * @version $Revision: 1.1 $ $Date: 2004/01/23 18:54:16 $
   */
  public class UserTransactionImpl implements UserTransaction, Serializable{
      private transient TransactionManager transactionManager;
  //    private transient TrackedConnectionAssociator trackedConnectionAssociator;
  
      public UserTransactionImpl() {
      }
  
      public TransactionManager getTransactionManager() {
          return transactionManager;
      }
  
      public void setTransactionManager(TransactionManager transactionManager) {
          this.transactionManager = transactionManager;
      }
  
  //    public TrackedConnectionAssociator getTrackedConnectionAssociator() {
  //        return trackedConnectionAssociator;
  //    }
  
  //    public void setTrackedConnectionAssociator(TrackedConnectionAssociator trackedConnectionAssociator) {
  //        this.trackedConnectionAssociator = trackedConnectionAssociator;
  //    }
  
      public void begin() throws NotSupportedException, SystemException {
          checkState();
          transactionManager.begin();
      }
  
      public void commit() throws HeuristicMixedException, HeuristicRollbackException, IllegalStateException, RollbackException, SecurityException, SystemException {
          checkState();
          transactionManager.commit();
      }
  
      public int getStatus() throws SystemException {
          checkState();
          return transactionManager.getStatus();
      }
  
      public void rollback() throws IllegalStateException, SecurityException, SystemException {
          checkState();
          transactionManager.rollback();
      }
  
      public void setRollbackOnly() throws IllegalStateException, SystemException {
          checkState();
          transactionManager.setRollbackOnly();
      }
  
      public void setTransactionTimeout(int timeout) throws SystemException {
          checkState();
          transactionManager.setTransactionTimeout(timeout);
      }
  
      private void checkState() {
  //        if (transactionManager == null || trackedConnectionAssociator == null) {
  //            throw new IllegalStateException("UserTransaction is disabled");
  //        }
      }
  
  }
  
  
  
  1.1                  incubator-geronimo/modules/transaction/src/java/org/apache/geronimo/transaction/manager/XidFactory.java
  
  Index: XidFactory.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Geronimo" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Geronimo", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
  package org.apache.geronimo.transaction.manager;
  
  import java.net.InetAddress;
  import java.net.UnknownHostException;
  import javax.transaction.xa.Xid;
  
  /**
   * Factory for transaction ids.
   * The Xid is constructed of three parts:
   * <ol><li>8 byte count (LSB first)</li>
   * <li>4 byte system id</li>
   * <li>4 or 16 byte IP address of host</li>
   * <ol>
   * @version $Revision: 1.1 $ $Date: 2004/01/23 18:54:16 $
   * @todo Should have a way of setting baseId
   */
  public class XidFactory {
      byte[] baseId = new byte[Xid.MAXGTRIDSIZE];
      long count = 1;
  
      public XidFactory() {
          byte[] hostid;
          try {
              hostid = InetAddress.getLocalHost().getAddress();
          } catch (UnknownHostException e) {
              hostid = new byte[]{127, 0, 0, 1};
          }
          int uid = System.identityHashCode(this);
          baseId[8] = (byte) uid;
          baseId[9] = (byte) (uid >>> 8);
          baseId[10] = (byte) (uid >>> 16);
          baseId[11] = (byte) (uid >>> 24);
          System.arraycopy(hostid, 0, baseId, 12, hostid.length);
      }
  
      public Xid createXid() {
          byte[] globalId = (byte[]) baseId.clone();
          long id;
          synchronized (this) {
              id = count++;
          }
          globalId[0] = (byte) id;
          globalId[1] = (byte) (id >>> 8);
          globalId[2] = (byte) (id >>> 16);
          globalId[3] = (byte) (id >>> 24);
          globalId[4] = (byte) (id >>> 32);
          globalId[5] = (byte) (id >>> 40);
          globalId[6] = (byte) (id >>> 48);
          globalId[7] = (byte) (id >>> 56);
          return new XidImpl(globalId);
      }
  
      public Xid createBranch(Xid globalId, int branch) {
          return new XidImpl(globalId, branch);
      }
  }
  
  
  
  1.1                  incubator-geronimo/modules/transaction/src/java/org/apache/geronimo/transaction/manager/XidImpl.java
  
  Index: XidImpl.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Geronimo" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Geronimo", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
  package org.apache.geronimo.transaction.manager;
  
  import java.io.Serializable;
  import java.util.Arrays;
  import javax.transaction.xa.Xid;
  
  /**
   * Unique id for a transaction.
   *
   * @version $Revision: 1.1 $ $Date: 2004/01/23 18:54:16 $
   */
  public class XidImpl implements Xid, Serializable {
      private static int FORMAT_ID = 0x4765526f;  // Gero
      private final byte[] globalId;
      private final byte[] branchId;
      private final int hash;
  
      /**
       * Constructor taking a global id (for the main transaction)
       * @param globalId the global transaction id
       */
      public XidImpl(byte[] globalId) {
          this.globalId = globalId;
          this.hash = hash(globalId);
          branchId = new byte[Xid.MAXBQUALSIZE];
      }
  
      /**
       * Constructor for a branch id
       * @param global the xid of the global transaction this branch belongs to
       * @param branch the branch id
       */
      public XidImpl(Xid global, int branch) {
          int hash;
          if (global instanceof XidImpl) {
              globalId = ((XidImpl) global).globalId;
              hash = ((XidImpl) global).hash;
          } else {
              globalId = global.getGlobalTransactionId();
              hash = hash(globalId);
          }
          branchId = new byte[Xid.MAXBQUALSIZE];
          branchId[0] = (byte) branch;
          branchId[1] = (byte) (branch >>> 8);
          branchId[2] = (byte) (branch >>> 16);
          branchId[3] = (byte) (branch >>> 24);
          for (int i = 0; i < 4; i++) {
              hash = (hash * 37) + branchId[i];
          }
          this.hash = hash;
      }
  
      private int hash(byte[] id) {
          int hash = 0;
          for (int i = 0; i < id.length; i++) {
              hash = (hash * 37) + id[i];
          }
          return hash;
      }
  
      public int getFormatId() {
          return FORMAT_ID;
      }
  
      public byte[] getGlobalTransactionId() {
          return (byte[]) globalId.clone();
      }
  
      public byte[] getBranchQualifier() {
          return (byte[]) branchId.clone();
      }
  
      public boolean equals(Object obj) {
          if (obj instanceof XidImpl == false) {
              return false;
          }
          XidImpl other = (XidImpl) obj;
          return Arrays.equals(globalId, other.globalId) && Arrays.equals(branchId, other.branchId);
      }
  
      public int hashCode() {
          return hash;
      }
  
      public String toString() {
          StringBuffer s = new StringBuffer();
          s.append("[globalId=");
          for (int i = 0; i < globalId.length; i++) {
              s.append(Integer.toHexString(globalId[i]));
          }
          s.append(",branchId=");
          for (int i = 0; i < branchId.length; i++) {
              s.append(Integer.toHexString(branchId[i]));
          }
          s.append("]");
          return s.toString();
      }
  }
  
  
  
  1.1                  incubator-geronimo/modules/transaction/src/test/org/apache/geronimo/transaction/manager/MockResource.java
  
  Index: MockResource.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Geronimo" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Geronimo", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
  package org.apache.geronimo.transaction.manager;
  
  import javax.transaction.xa.XAException;
  import javax.transaction.xa.XAResource;
  import javax.transaction.xa.Xid;
  
  /**
   *
   *
   * @version $Revision: 1.1 $ $Date: 2004/01/23 18:54:16 $
   */
  public class MockResource implements XAResource {
      private Xid xid;
      private MockResourceManager manager;
      private int timeout = 0;
  
      public MockResource(MockResourceManager manager) {
          this.manager = manager;
      }
  
      public int getTransactionTimeout() throws XAException {
          return timeout;
      }
  
      public boolean setTransactionTimeout(int seconds) throws XAException {
          return false;
      }
  
      public Xid getXid() {
          return xid;
      }
  
      public void start(Xid xid, int flags) throws XAException {
          if (this.xid != null) {
              throw new XAException(XAException.XAER_PROTO);
          }
          if ((flags & XAResource.TMJOIN) != 0) {
              manager.join(xid, this);
          } else {
              manager.newTx(xid, this);
          }
          this.xid = xid;
      }
  
      public void end(Xid xid, int flags) throws XAException {
          if (this.xid != xid) {
              throw new XAException(XAException.XAER_INVAL);
          }
          this.xid = null;
      }
  
      public int prepare(Xid xid) throws XAException {
          return 0;
      }
  
      public void commit(Xid xid, boolean onePhase) throws XAException {
      }
  
      public void rollback(Xid xid) throws XAException {
          manager.forget(xid, this);
      }
  
      public boolean isSameRM(XAResource xaResource) throws XAException {
          if (xaResource instanceof MockResource) {
              return manager == ((MockResource) xaResource).manager;
          }
          return false;
      }
  
      public void forget(Xid xid) throws XAException {
          throw new UnsupportedOperationException();
      }
  
      public Xid[] recover(int flag) throws XAException {
          throw new UnsupportedOperationException();
      }
  
  }
  
  
  
  1.1                  incubator-geronimo/modules/transaction/src/test/org/apache/geronimo/transaction/manager/MockResourceManager.java
  
  Index: MockResourceManager.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Geronimo" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Geronimo", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
  package org.apache.geronimo.transaction.manager;
  
  import java.util.HashMap;
  import java.util.HashSet;
  import java.util.Map;
  import java.util.Set;
  import javax.transaction.xa.XAException;
  import javax.transaction.xa.XAResource;
  import javax.transaction.xa.Xid;
  
  /**
   *
   *
   * @version $Revision: 1.1 $ $Date: 2004/01/23 18:54:16 $
   */
  public class MockResourceManager {
      private boolean willCommit;
      private Map xids = new HashMap();
  
      public MockResourceManager(boolean willCommit) {
          this.willCommit = willCommit;
      }
  
      public MockResource getResource() {
          return new MockResource(this);
      }
  
      public void join(Xid xid, XAResource xaRes) throws XAException {
          Set resSet = (Set) xids.get(xid);
          if (resSet == null) {
              throw new XAException(XAException.XAER_NOTA);
          }
          resSet.add(xaRes);
      }
  
      public void newTx(Xid xid, XAResource xaRes) throws XAException {
          if (xids.containsKey(xid)) {
              throw new XAException(XAException.XAER_DUPID);
          }
          Set resSet = new HashSet();
          resSet.add(xaRes);
          xids.put(xid, resSet);
      }
  
      public void forget(Xid xid, XAResource xaRes) throws XAException {
          if (xids.remove(xid) == null) {
              throw new XAException(XAException.XAER_NOTA);
          }
      }
  }
  
  
  
  1.1                  incubator-geronimo/modules/transaction/src/test/org/apache/geronimo/transaction/manager/TestTransactionManager.java
  
  Index: TestTransactionManager.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Geronimo" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Geronimo", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
  package org.apache.geronimo.transaction.manager;
  
  import javax.transaction.Status;
  import javax.transaction.Transaction;
  import javax.transaction.TransactionManager;
  import javax.transaction.xa.XAResource;
  
  import junit.framework.TestCase;
  
  /**
   *
   *
   * @version $Revision: 1.1 $ $Date: 2004/01/23 18:54:16 $
   */
  public class TestTransactionManager extends TestCase {
      TransactionManager tm;
      MockResourceManager rm1, rm2, rm3;
  
      public void testNoTransaction() throws Exception {
          assertEquals(Status.STATUS_NO_TRANSACTION, tm.getStatus());
          assertNull(tm.getTransaction());
      }
  
      public void testNoResource() throws Exception {
          Transaction tx;
          assertEquals(Status.STATUS_NO_TRANSACTION, tm.getStatus());
          tm.begin();
          assertEquals(Status.STATUS_ACTIVE, tm.getStatus());
          tx = tm.getTransaction();
          assertNotNull(tx);
          assertEquals(Status.STATUS_ACTIVE, tx.getStatus());
          tm.rollback();
          assertEquals(Status.STATUS_NO_TRANSACTION, tm.getStatus());
          assertNull(tm.getTransaction());
          assertEquals(Status.STATUS_NO_TRANSACTION, tx.getStatus());
  
          tm.begin();
          assertEquals(Status.STATUS_ACTIVE, tm.getStatus());
          tm.rollback();
          assertEquals(Status.STATUS_NO_TRANSACTION, tm.getStatus());
      }
  
      public void testTxOp() throws Exception {
          Transaction tx;
          tm.begin();
          tx = tm.getTransaction();
          tx.rollback();
          assertEquals(Status.STATUS_NO_TRANSACTION, tx.getStatus());
          assertEquals(Status.STATUS_NO_TRANSACTION, tm.getStatus());
  
          tm.begin();
          assertFalse(tx.equals(tm.getTransaction()));
          tm.rollback();
      }
  
      public void testSuspend() throws Exception {
          Transaction tx;
          assertEquals(Status.STATUS_NO_TRANSACTION, tm.getStatus());
          tm.begin();
          assertEquals(Status.STATUS_ACTIVE, tm.getStatus());
          tx = tm.getTransaction();
          assertNotNull(tx);
          assertEquals(Status.STATUS_ACTIVE, tx.getStatus());
  
          tx = tm.suspend();
          assertEquals(Status.STATUS_NO_TRANSACTION, tm.getStatus());
          assertNull(tm.getTransaction());
  
          tm.resume(tx);
          assertEquals(Status.STATUS_ACTIVE, tm.getStatus());
          assertEquals(tx, tm.getTransaction());
  
          tm.rollback();
          assertEquals(Status.STATUS_NO_TRANSACTION, tm.getStatus());
          assertNull(tm.getTransaction());
      }
  
      public void testOneResource() throws Exception {
          Transaction tx;
          MockResource res1 = rm1.getResource();
          tm.begin();
          tx = tm.getTransaction();
          assertNull(res1.getXid());
          assertTrue(tx.enlistResource(res1));
          assertNotNull(res1.getXid());
          assertTrue(tx.delistResource(res1, XAResource.TMFAIL));
          assertNull(res1.getXid());
          tm.rollback();
  
          tm.begin();
          tx = tm.getTransaction();
          assertTrue(tx.enlistResource(res1));
          tm.rollback();
          assertNull(res1.getXid());
      }
  
      protected void setUp() throws Exception {
          tm = new TransactionManagerImpl();
          rm1 = new MockResourceManager(true);
          rm2 = new MockResourceManager(true);
          rm3 = new MockResourceManager(false);
      }
  }
  
  
  
  1.1                  incubator-geronimo/modules/transaction/src/test/org/apache/geronimo/transaction/manager/XATransactionTester.java
  
  Index: XATransactionTester.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Geronimo" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Geronimo", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
  package org.apache.geronimo.transaction.manager;
  
  import java.sql.Connection;
  import java.sql.Statement;
  import java.io.IOException;
  import javax.sql.XAConnection;
  import javax.sql.XADataSource;
  import javax.transaction.TransactionManager;
  import javax.transaction.xa.XAResource;
  import javax.transaction.xa.Xid;
  import javax.transaction.xa.XAException;
  
  /**
   *
   *
   *
   * @version $Revision: 1.1 $ $Date: 2004/01/23 18:54:16 $
   */
  public class XATransactionTester {
      private TransactionLog log;
      private TransactionManager manager;
      private XADataSource ds;
      private Xid xid;
  
      public static void main(String[] args) throws Exception {
          new XATransactionTester().run(args);
      }
  
      public void run(String[] args) throws Exception {
          ds = getDataSource(args);
          XAConnection xaConn = ds.getXAConnection("test", "test");
          XAResource xaRes = xaConn.getXAResource();
          log = new DummyLog();
          manager = new TransactionManagerImpl(log);
          Connection c = xaConn.getConnection();
          Statement s = c.createStatement();
  
          manager.begin();
          manager.getTransaction().enlistResource(xaRes);
          s.execute("UPDATE XA_TEST SET X=X+1");
          manager.getTransaction().delistResource(xaRes, XAResource.TMSUCCESS);
          manager.commit();
  
  /*
          manager.begin();
          manager.getTransaction().enlistResource(xaRes);
          xid = new XidImpl(xid, 1);
          System.out.println("xid = " + xid);
          s.execute("UPDATE XA_TEST SET X=X+1");
  
          xaRes.end(xid, XAResource.TMSUCCESS);
          xaRes.prepare(xid);
          c.close();
  */
  
  /*
          Xid[] prepared = xaRes.recover(XAResource.TMNOFLAGS);
          for (int i = 0; i < prepared.length; i++) {
              Xid xid = prepared[i];
              StringBuffer s = new StringBuffer();
              s.append(Integer.toHexString(xid.getFormatId())).append('.');
              byte[] globalId = xid.getGlobalTransactionId();
              for (int j = 0; j < globalId.length; j++) {
                  s.append(Integer.toHexString(globalId[j]));
              }
  
              System.out.println("recovery = " + s);
              xaRes.forget(xid);
          }
  */
  
      }
  
      /*
       * @todo get something that loads this from a file
       */
      private XADataSource getDataSource(String[] args) throws Exception {
  //        oracle.jdbc.xa.client.OracleXADataSource ds = new oracle.jdbc.xa.client.OracleXADataSource();
  //        ds.setURL("jdbc:oracle:thin:@localhost:1521:ABU");
  //        return ds;
          return null;
      }
  
      private class DummyLog implements TransactionLog {
  
          public void begin(Xid xid) throws IOException {
              XATransactionTester.this.xid = xid;
          }
  
          public void prepare(Xid xid) throws IOException {
          }
  
          public void commit(Xid xid) throws IOException {
          }
  
          public void rollback(Xid xid) throws IOException {
          }
      }
  }
  
  
  

Mime
View raw message