geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From djen...@apache.org
Subject cvs commit: incubator-geronimo/modules/transaction/src/java/org/apache/geronimo/transaction/context BeanTransactionContext.java ContainerTransactionContext.java InheritableTransactionContext.java TransactionContext.java TransactionContextManager.java UnspecifiedTransactionContext.java
Date Sun, 18 Jul 2004 22:02:01 GMT
djencks     2004/07/18 15:02:01

  Modified:    modules/axis/src/java/org/apache/geronimo/axis
                        WebServiceContainer.java
               modules/transaction project.xml
               modules/transaction/src/java/org/apache/geronimo/transaction
                        TransactionManagerProxy.java
                        UserTransactionImpl.java
  Added:       modules/transaction/src/java/org/apache/geronimo/transaction/context
                        BeanTransactionContext.java
                        ContainerTransactionContext.java
                        InheritableTransactionContext.java
                        TransactionContext.java
                        TransactionContextManager.java
                        UnspecifiedTransactionContext.java
  Removed:     modules/transaction/src/java/org/apache/geronimo/transaction
                        BeanTransactionContext.java
                        ContainerTransactionContext.java
                        InheritableTransactionContext.java
                        TransactionContext.java
                        UnspecifiedTransactionContext.java
  Log:
  Centralize use of TransactionContext in a TransactionContextManagerGBean
  
  Revision  Changes    Path
  1.3       +11 -4     incubator-geronimo/modules/axis/src/java/org/apache/geronimo/axis/WebServiceContainer.java
  
  Index: WebServiceContainer.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/axis/src/java/org/apache/geronimo/axis/WebServiceContainer.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- WebServiceContainer.java	16 Jul 2004 01:09:37 -0000	1.2
  +++ WebServiceContainer.java	18 Jul 2004 22:02:01 -0000	1.3
  @@ -24,6 +24,7 @@
   import org.apache.geronimo.kernel.Kernel;
   import org.apache.geronimo.transaction.GeronimoTransactionManager;
   import org.apache.geronimo.transaction.UserTransactionImpl;
  +import org.apache.geronimo.transaction.context.TransactionContextManager;
   
   import javax.management.MBeanServer;
   import javax.management.MalformedObjectNameException;
  @@ -41,11 +42,13 @@
       private MBeanServer mbServer;
       private Set containerPatterns;
       private ObjectName tmName;
  +    private ObjectName tcmName;
       private ObjectName tcaName;
       private ObjectName appName;
       private ObjectName connectorName;
       private String webappsUrl;
       private final boolean startJetty = true;
  +    private GBeanMBean tcm;
   
       public WebServiceContainer(Kernel kernel, ObjectName axisGBeanName) {
           try {
  @@ -57,6 +60,7 @@
               connectorName = new ObjectName("geronimo.jetty:role=Connector");
               appName = new ObjectName("geronimo.jetty:app=test");
               tmName = new ObjectName("geronimo.test:role=TransactionManager");
  +            tcmName = new ObjectName("geronimo.test:role=TransactionContextManager");
               tcaName =
                       new ObjectName(
                               "geronimo.test:role=ConnectionTrackingCoordinator");
  @@ -75,15 +79,15 @@
           URL url = Thread.currentThread().getContextClassLoader().getResource(
                   "deployables/axis/");
           GBeanMBean app = new GBeanMBean(JettyWebAppContext.GBEAN_INFO);
  -        app.setAttribute("URI", URI.create(url.toString()));
  +        app.setAttribute("uri", URI.create(url.toString()));
           app.setAttribute("contextPath", "/axis");
           app.setAttribute("componentContext", null);
           UserTransactionImpl userTransaction = new UserTransactionImpl();
           app.setAttribute("userTransaction", userTransaction);
           app.setReferencePatterns("Configuration", Collections.EMPTY_SET);
           app.setReferencePatterns("JettyContainer", containerPatterns);
  -        app.setReferencePatterns("TransactionManager",
  -                Collections.singleton(tmName));
  +        app.setReferencePatterns("TransactionContextManager",
  +                Collections.singleton(tcmName));
           app.setReferencePatterns("TrackedConnectionAssociator",
                   Collections.singleton(tcaName));
           start(appName, app);
  @@ -91,7 +95,7 @@
   
       public void doStop() throws Exception {
           stop(tcaName);
  -        stop(tmName);
  +        stop(tcmName);
           stop(connectorName);
           stop(containerName);
       }
  @@ -114,6 +118,9 @@
                           "geronimo.server:j2eeType=JCAManagedConnectionFactory,*"));
           tm.setReferencePatterns("ResourceManagers", patterns);
           start(tmName, tm);
  +        tcm = new GBeanMBean(TransactionContextManager.GBEAN_INFO);
  +        tcm.setReferencePattern("TransactionManager", tmName);
  +        start(tcmName, tcm);
           ctc = new GBeanMBean(ConnectionTrackingCoordinator.GBEAN_INFO);
           start(tcaName, ctc);
       }
  
  
  
  1.20      +16 -1     incubator-geronimo/modules/transaction/project.xml
  
  Index: project.xml
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/transaction/project.xml,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- project.xml	25 Jun 2004 21:29:34 -0000	1.19
  +++ project.xml	18 Jul 2004 22:02:01 -0000	1.20
  @@ -50,6 +50,15 @@
               <version>${pom.currentVersion}</version>
           </dependency>
   
  +        <!-- thread pool, for timer -->
  +        <dependency>
  +            <groupId>geronimo</groupId>
  +            <artifactId>geronimo-core</artifactId>
  +            <version>${pom.currentVersion}</version>
  +        </dependency>
  +
  +
  +        <!-- actual tx dependencies -->
           <dependency>
               <groupId>geronimo</groupId>
               <artifactId>geronimo-kernel</artifactId>
  @@ -75,6 +84,12 @@
           </dependency>
   
           <!-- Thirdparty -->
  +
  +        <dependency>
  +            <groupId>concurrent</groupId>
  +            <artifactId>concurrent</artifactId>
  +            <version>1.3.4</version>
  +        </dependency>
   
           <dependency>
               <groupId>commons-logging</groupId>
  
  
  
  1.12      +3 -1      incubator-geronimo/modules/transaction/src/java/org/apache/geronimo/transaction/TransactionManagerProxy.java
  
  Index: TransactionManagerProxy.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/transaction/src/java/org/apache/geronimo/transaction/TransactionManagerProxy.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- TransactionManagerProxy.java	11 Jul 2004 21:25:21 -0000	1.11
  +++ TransactionManagerProxy.java	18 Jul 2004 22:02:01 -0000	1.12
  @@ -51,6 +51,8 @@
   import org.apache.geronimo.transaction.manager.Recovery;
   import org.apache.geronimo.transaction.manager.ResourceManager;
   import org.apache.geronimo.transaction.manager.XidImporter;
  +import org.apache.geronimo.transaction.context.TransactionContext;
  +import org.apache.geronimo.transaction.context.UnspecifiedTransactionContext;
   
   /**
    * A wrapper for a TransactionManager that wraps all Transactions in a TransactionProxy
  
  
  
  1.5       +20 -36    incubator-geronimo/modules/transaction/src/java/org/apache/geronimo/transaction/UserTransactionImpl.java
  
  Index: UserTransactionImpl.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/transaction/src/java/org/apache/geronimo/transaction/UserTransactionImpl.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- UserTransactionImpl.java	8 Apr 2004 05:22:15 -0000	1.4
  +++ UserTransactionImpl.java	18 Jul 2004 22:02:01 -0000	1.5
  @@ -18,19 +18,19 @@
   package org.apache.geronimo.transaction;
   
   import java.io.Serializable;
  +
  +import javax.resource.ResourceException;
   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 javax.resource.ResourceException;
   
  -import org.apache.geronimo.transaction.TrackedConnectionAssociator;
  -import org.apache.geronimo.transaction.TransactionContext;
  -import org.apache.geronimo.transaction.UnspecifiedTransactionContext;
  -import org.apache.geronimo.transaction.BeanTransactionContext;
  +import org.apache.geronimo.transaction.context.TransactionContextManager;
  +import org.apache.geronimo.transaction.context.BeanTransactionContext;
  +import org.apache.geronimo.transaction.context.TransactionContext;
  +import org.apache.geronimo.transaction.context.UnspecifiedTransactionContext;
   
   /**
    * Implementation of UserTransaction for use in an EJB.
  @@ -40,7 +40,7 @@
    * @version $Revision$ $Date$
    */
   public class UserTransactionImpl implements UserTransaction, Serializable {
  -    private transient TransactionManager txnManager;
  +    private transient TransactionContextManager transactionContextManager;
       private transient TrackedConnectionAssociator trackedConnectionAssociator;
   
       private final ThreadLocal state = new StateThreadLocal();
  @@ -54,9 +54,9 @@
           state.set(OFFLINE);
       }
   
  -    public void setUp(TransactionManager txnManager, TrackedConnectionAssociator trackedConnectionAssociator)
{
  +    public void setUp(TransactionContextManager transactionContextManager, TrackedConnectionAssociator
trackedConnectionAssociator) {
           assert !isOnline() : "Only set the tx manager when UserTransaction is offline";
  -        this.txnManager = txnManager;
  +        this.transactionContextManager = transactionContextManager;
           this.trackedConnectionAssociator = trackedConnectionAssociator;
       }
   
  @@ -66,8 +66,8 @@
   
       public void setOnline(boolean online) {
           //too bad there's no implies operation
  -        // online implies transactionManager != null
  -        assert !online || txnManager != null : "online requires a tx manager";
  +        // online implies transactionContextManager != null
  +        assert !online || transactionContextManager != null : "online requires a tx manager";
           state.set(online ? ONLINE : OFFLINE);
       }
   
  @@ -102,35 +102,19 @@
       private final UserTransaction ONLINE = new OnlineUserTransaction();
       private final class OnlineUserTransaction implements UserTransaction, Serializable
{
           public int getStatus() throws SystemException {
  -            return txnManager.getStatus();
  +            return transactionContextManager.getStatus();
           }
   
           public void setRollbackOnly() throws IllegalStateException, SystemException {
  -            txnManager.setRollbackOnly();
  +            transactionContextManager.setRollbackOnly();
           }
   
           public void setTransactionTimeout(int seconds) throws SystemException {
  -            txnManager.setTransactionTimeout(seconds);
  +            transactionContextManager.setTransactionTimeout(seconds);
           }
   
           public void begin() throws NotSupportedException, SystemException {
  -            TransactionContext ctx = TransactionContext.getContext();
  -            if (ctx instanceof UnspecifiedTransactionContext == false) {
  -                throw new NotSupportedException("Previous Transaction has not been committed");
  -            }
  -            UnspecifiedTransactionContext oldContext = (UnspecifiedTransactionContext)
ctx;
  -            BeanTransactionContext newContext = new BeanTransactionContext(txnManager,
oldContext);
  -            oldContext.suspend();
  -            try {
  -                newContext.begin();
  -            } catch (SystemException e) {
  -                oldContext.resume();
  -                throw e;
  -            } catch (NotSupportedException e) {
  -                oldContext.resume();
  -                throw e;
  -            }
  -            TransactionContext.setContext(newContext);
  +            transactionContextManager.newBeanTransactionContext();
   
               if(trackedConnectionAssociator != null) {
                   try {
  @@ -142,7 +126,7 @@
           }
   
           public void commit() throws HeuristicMixedException, HeuristicRollbackException,
IllegalStateException, RollbackException, SecurityException, SystemException {
  -            TransactionContext ctx = TransactionContext.getContext();
  +            TransactionContext ctx = transactionContextManager.getContext();
               if (ctx instanceof BeanTransactionContext == false) {
                   throw new IllegalStateException("Transaction has not been started");
               }
  @@ -151,13 +135,13 @@
                   beanContext.commit();
               } finally {
                   UnspecifiedTransactionContext oldContext = beanContext.getOldContext();
  -                TransactionContext.setContext(oldContext);
  +                transactionContextManager.setContext(oldContext);
                   oldContext.resume();
               }
           }
   
           public void rollback() throws IllegalStateException, SecurityException, SystemException
{
  -            TransactionContext ctx = TransactionContext.getContext();
  +            TransactionContext ctx = transactionContextManager.getContext();
               if (ctx instanceof BeanTransactionContext == false) {
                   throw new IllegalStateException("Transaction has not been started");
               }
  @@ -166,7 +150,7 @@
                   beanContext.rollback();
               } finally {
                   UnspecifiedTransactionContext oldContext = beanContext.getOldContext();
  -                TransactionContext.setContext(oldContext);
  +                transactionContextManager.setContext(oldContext);
                   oldContext.resume();
               }
           }
  
  
  
  1.1                  incubator-geronimo/modules/transaction/src/java/org/apache/geronimo/transaction/context/BeanTransactionContext.java
  
  Index: BeanTransactionContext.java
  ===================================================================
  /**
   *
   * Copyright 2003-2004 The Apache Software Foundation
   *
   *  Licensed under the Apache License, Version 2.0 (the "License");
   *  you may not use this file except in compliance with the License.
   *  You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
   *  Unless required by applicable law or agreed to in writing, software
   *  distributed under the License is distributed on an "AS IS" BASIS,
   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   *  See the License for the specific language governing permissions and
   *  limitations under the License.
   */
  
  package org.apache.geronimo.transaction.context;
  
  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;
  
  /**
   *
   *
   * @version $Revision: 1.1 $ $Date: 2004/07/18 22:02:01 $
   */
  public class BeanTransactionContext extends InheritableTransactionContext {
      private final TransactionManager txnManager;
      private final UnspecifiedTransactionContext oldContext;
      private Transaction transaction;
  
  
      public BeanTransactionContext(TransactionManager txnManager, UnspecifiedTransactionContext
oldContext) {
          this.txnManager = txnManager;
          this.oldContext = oldContext;
      }
  
      public UnspecifiedTransactionContext getOldContext() {
          return oldContext;
      }
  
      public void begin() throws SystemException, NotSupportedException {
          txnManager.begin();
          transaction = txnManager.getTransaction();
      }
  
      public void suspend() throws SystemException {
          Transaction suspendedTransaction = txnManager.suspend();
          assert (transaction == suspendedTransaction) : "suspend did not return our transaction";
      }
  
      public void resume() throws SystemException, InvalidTransactionException {
          txnManager.resume(transaction);
      }
  
      public void commit() throws HeuristicMixedException, HeuristicRollbackException, RollbackException,
SystemException {
          try {
              try {
                  flushState();
              } catch (Throwable t) {
                  try {
                      txnManager.rollback();
                  } catch (Throwable t1) {
                      log.error("Unable to roll back transaction", t1);
                  }
                  throw (RollbackException) new RollbackException("Could not flush state before
commit").initCause(t);
              }
              txnManager.commit();
          } finally {
              connectorAfterCommit();
              transaction = null;
          }
      }
  
      public void rollback() throws SystemException {
          try {
              txnManager.rollback();
          } finally {
              connectorAfterCommit();
              transaction = null;
          }
      }
  
      //Geronimo connector framework support
  
      public boolean isActive() {
          try {
              return txnManager.getStatus() == Status.STATUS_ACTIVE;
          } catch (SystemException e) {
              return false;
          }
      }
  
      public Transaction getTransaction() {
          return transaction;
      }
  }
  
  
  
  1.1                  incubator-geronimo/modules/transaction/src/java/org/apache/geronimo/transaction/context/ContainerTransactionContext.java
  
  Index: ContainerTransactionContext.java
  ===================================================================
  /**
   *
   * Copyright 2003-2004 The Apache Software Foundation
   *
   *  Licensed under the Apache License, Version 2.0 (the "License");
   *  you may not use this file except in compliance with the License.
   *  You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
   *  Unless required by applicable law or agreed to in writing, software
   *  distributed under the License is distributed on an "AS IS" BASIS,
   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   *  See the License for the specific language governing permissions and
   *  limitations under the License.
   */
  
  package org.apache.geronimo.transaction.context;
  
  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;
  
  /**
   *
   *
   * @version $Revision: 1.1 $ $Date: 2004/07/18 22:02:01 $
   */
  public class ContainerTransactionContext extends InheritableTransactionContext {
      private final TransactionManager txnManager;
      private Transaction transaction;
  
      public ContainerTransactionContext(TransactionManager txnManager) {
          this.txnManager = txnManager;
      }
  
      public void begin() throws SystemException, NotSupportedException {
          txnManager.begin();
          transaction = txnManager.getTransaction();
      }
  
      public void suspend() throws SystemException {
          Transaction suspendedTransaction = txnManager.suspend();
          assert (transaction == suspendedTransaction) : "suspend did not return our transaction";
      }
  
      public void resume() throws SystemException, InvalidTransactionException {
          txnManager.resume(transaction);
      }
  
      /**
       * TODO the exceptions thrown here are not all correct.  Don't throw a RollbackException
after
       * a successful commit...??
       *
       * @throws javax.transaction.HeuristicMixedException
       * @throws javax.transaction.HeuristicRollbackException
       * @throws javax.transaction.RollbackException
       * @throws javax.transaction.SystemException
       */
      public void commit() throws HeuristicMixedException, HeuristicRollbackException, RollbackException,
SystemException {
          try {
              try {
                  flushState();
              } catch (Throwable t) {
                  try {
                      txnManager.rollback();
                  } catch (Throwable t1) {
                      log.error("Unable to roll back transaction", t1);
                  }
                  throw (RollbackException) new RollbackException("Could not flush state before
commit").initCause(t);
              }
              try {
                  beforeCommit();
              } catch (Exception e) {
                  try {
                      txnManager.rollback();
                  } catch (Throwable t1) {
                      log.error("Unable to roll back transaction", t1);
                  }
                  throw (RollbackException) new RollbackException("Could not flush state before
commit").initCause(e);
              }
              txnManager.commit();
              try {
                  afterCommit(true);
              } catch (Exception e) {
                  try {
                      txnManager.rollback();
                  } catch (Throwable t1) {
                      log.error("Unable to roll back transaction", t1);
                  }
                  throw (RollbackException) new RollbackException("Could not flush state before
commit").initCause(e);
              }
          } finally {
              connectorAfterCommit();
              transaction = null;
          }
      }
  
      public void rollback() throws SystemException {
          try {
              txnManager.rollback();
          } finally {
              connectorAfterCommit();
              transaction = null;
          }
      }
  
      //Geronimo connector framework support
      public boolean isActive() {
          try {
              return txnManager.getStatus() == Status.STATUS_ACTIVE;
          } catch (SystemException e) {
              return false;
          }
      }
  
      public Transaction getTransaction() {
          return transaction;
      }
  
      public void setRollbackOnly() throws IllegalStateException, SystemException {
          if (transaction == null) {
              throw new IllegalStateException("There is no transaction in progress.");
          }
          transaction.setRollbackOnly();
      }
  
      public boolean getRollbackOnly() throws SystemException {
          if (transaction == null) {
              throw new IllegalStateException("There is no transaction in progress.");
          }
  
          int status = transaction.getStatus();
          return (status == Status.STATUS_MARKED_ROLLBACK ||
                  status == Status.STATUS_ROLLEDBACK ||
                  status == Status.STATUS_ROLLING_BACK );
      }
  }
  
  
  
  1.1                  incubator-geronimo/modules/transaction/src/java/org/apache/geronimo/transaction/context/InheritableTransactionContext.java
  
  Index: InheritableTransactionContext.java
  ===================================================================
  /**
   *
   * Copyright 2003-2004 The Apache Software Foundation
   *
   *  Licensed under the Apache License, Version 2.0 (the "License");
   *  you may not use this file except in compliance with the License.
   *  You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
   *  Unless required by applicable law or agreed to in writing, software
   *  distributed under the License is distributed on an "AS IS" BASIS,
   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   *  See the License for the specific language governing permissions and
   *  limitations under the License.
   */
  
  package org.apache.geronimo.transaction.context;
  
  import org.apache.geronimo.transaction.context.TransactionContext;
  
  /**
   *
   *
   * @version $Revision: 1.1 $ $Date: 2004/07/18 22:02:01 $
   */
  public abstract class InheritableTransactionContext extends TransactionContext {
  }
  
  
  
  1.1                  incubator-geronimo/modules/transaction/src/java/org/apache/geronimo/transaction/context/TransactionContext.java
  
  Index: TransactionContext.java
  ===================================================================
  /**
   *
   * Copyright 2003-2004 The Apache Software Foundation
   *
   *  Licensed under the Apache License, Version 2.0 (the "License");
   *  you may not use this file except in compliance with the License.
   *  You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
   *  Unless required by applicable law or agreed to in writing, software
   *  distributed under the License is distributed on an "AS IS" BASIS,
   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   *  See the License for the specific language governing permissions and
   *  limitations under the License.
   */
  
  package org.apache.geronimo.transaction.context;
  
  import java.util.ArrayList;
  import java.util.HashMap;
  import java.util.Iterator;
  import java.util.Map;
  
  import javax.transaction.HeuristicMixedException;
  import javax.transaction.HeuristicRollbackException;
  import javax.transaction.InvalidTransactionException;
  import javax.transaction.NotSupportedException;
  import javax.transaction.RollbackException;
  import javax.transaction.SystemException;
  import javax.transaction.Transaction;
  
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  import org.apache.geronimo.transaction.InstanceContext;
  import org.apache.geronimo.transaction.DoubleKeyedHashMap;
  import org.apache.geronimo.transaction.ConnectionReleaser;
  import org.tranql.cache.InTxCache;
  import org.tranql.cache.SimpleFlushStrategy;
  
  
  /**
   *
   *
   * @version $Revision: 1.1 $ $Date: 2004/07/18 22:02:01 $
   */
  public abstract class TransactionContext {
      protected static final Log log = LogFactory.getLog(TransactionContext.class);
      private static ThreadLocal CONTEXT = new ThreadLocal();
  
      public static TransactionContext getContext() {
          return (TransactionContext) CONTEXT.get();
      }
  
      public static void setContext(TransactionContext context) {
          CONTEXT.set(context);
      }
  
      private InstanceContext currentContext;
      private final DoubleKeyedHashMap associatedContexts = new DoubleKeyedHashMap();
      private final DoubleKeyedHashMap dirtyContexts = new DoubleKeyedHashMap();
      private Map managedConnections;
      private InTxCache inTxCache;
  
      public abstract void begin() throws SystemException, NotSupportedException;
  
      public abstract void suspend() throws SystemException;
  
      public abstract void resume() throws SystemException, InvalidTransactionException;
  
      public abstract void commit() throws HeuristicMixedException, HeuristicRollbackException,
RollbackException, SystemException;
  
      public abstract void rollback() throws SystemException;
  
      public final void associate(InstanceContext context) throws Throwable {
          if (associatedContexts.put(context.getContainerId(), context.getId(), context) ==
null) {
              context.associate();
          }
      }
  
      public final void unassociate(Object containerId, Object id) throws Exception {
          associatedContexts.remove(containerId, id);
          dirtyContexts.remove(containerId, id);
      }
  
      public final InstanceContext beginInvocation(InstanceContext context) {
          if (context.getId() != null) {
              dirtyContexts.put(context.getContainerId(), context.getId(), context);
          }
          InstanceContext caller = currentContext;
          currentContext = context;
          return caller;
      }
  
      public final void endInvocation(InstanceContext caller) {
          currentContext = caller;
      }
  
      public final void flushState() throws Throwable {
          while (dirtyContexts.isEmpty() == false) {
              ArrayList toFlush = new ArrayList(dirtyContexts.values());
              dirtyContexts.clear();
              for (Iterator i = toFlush.iterator(); i.hasNext();) {
                  InstanceContext context = (InstanceContext) i.next();
                  context.flush();
              }
          }
          if (currentContext != null && currentContext.getId() != null) {
              dirtyContexts.put(currentContext.getContainerId(), currentContext.getId(), currentContext);
          }
          if(inTxCache != null) {
              inTxCache.flush();
          }
      }
  
      protected void beforeCommit() throws Exception {
          // @todo allow for enrollment during pre-commit
          ArrayList toFlush = new ArrayList(associatedContexts.values());
          for (Iterator i = toFlush.iterator(); i.hasNext();) {
              InstanceContext context = (InstanceContext) i.next();
              context.beforeCommit();
          }
      }
  
      protected void afterCommit(boolean status) throws Exception {
          // @todo allow for enrollment during pre-commit
          ArrayList toFlush = new ArrayList(associatedContexts.values());
          for (Iterator i = toFlush.iterator(); i.hasNext();) {
              InstanceContext context = (InstanceContext) i.next();
              context.afterCommit(status);
          }
      }
  
      public final InstanceContext getContext(Object containerId, Object id) {
          return (InstanceContext) associatedContexts.get(containerId, id);
      }
  
      public final InTxCache getInTxCache() {
          if (inTxCache == null) {
              inTxCache = new InTxCache(new SimpleFlushStrategy());
          }
          return inTxCache;
      }
  
      //Geronimo connector framework support
      public void setManagedConnectionInfo(ConnectionReleaser key, Object info) {
          if (managedConnections == null) {
              managedConnections = new HashMap();
          }
          managedConnections.put(key, info);
      }
  
      public Object getManagedConnectionInfo(ConnectionReleaser key) {
          if (managedConnections == null) {
              return null;
          }
          return managedConnections.get(key);
      }
  
      public abstract boolean isActive();
  
      public abstract Transaction getTransaction();
  
      protected void connectorAfterCommit() {
          if (managedConnections != null) {
              for (Iterator entries = managedConnections.entrySet().iterator(); entries.hasNext();)
{
                  Map.Entry entry = (Map.Entry) entries.next();
                  ConnectionReleaser key = (ConnectionReleaser) entry.getKey();
                  key.afterCompletion(entry.getValue());
              }
              //If BeanTransactionContext never reuses the same instance for sequential BMT,
this
              //clearing is unnecessary.
              managedConnections.clear();
          }
      }
  
  }
  
  
  
  1.1                  incubator-geronimo/modules/transaction/src/java/org/apache/geronimo/transaction/context/TransactionContextManager.java
  
  Index: TransactionContextManager.java
  ===================================================================
  /**
   *
   * Copyright 2004 The Apache Software Foundation
   *
   *  Licensed under the Apache License, Version 2.0 (the "License");
   *  you may not use this file except in compliance with the License.
   *  You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
   *  Unless required by applicable law or agreed to in writing, software
   *  distributed under the License is distributed on an "AS IS" BASIS,
   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   *  See the License for the specific language governing permissions and
   *  limitations under the License.
   */
  
  package org.apache.geronimo.transaction.context;
  
  import javax.transaction.NotSupportedException;
  import javax.transaction.SystemException;
  import javax.transaction.TransactionManager;
  
  import org.apache.geronimo.gbean.GBeanInfo;
  import org.apache.geronimo.gbean.GBeanInfoFactory;
  
  /**
   *
   *
   * @version $Revision: 1.1 $ $Date: 2004/07/18 22:02:01 $
   *
   * */
  public class TransactionContextManager {
  
      private final TransactionManager transactionManager;
  
      //use as reference endpoint.
      public TransactionContextManager() {
          transactionManager = null;
      }
  
      public TransactionContextManager(TransactionManager transactionManager) {
          this.transactionManager = transactionManager;
      }
  
      public TransactionContext getContext() {
          return TransactionContext.getContext();
      }
  
      public void setContext(TransactionContext transactionContext) {
          TransactionContext.setContext(transactionContext);
      }
  
      public ContainerTransactionContext newContainerTransactionContext() throws NotSupportedException,
SystemException {
          ContainerTransactionContext transactionContext = new ContainerTransactionContext(transactionManager);
          TransactionContext.setContext(transactionContext);
          transactionContext.begin();
          return transactionContext;
      }
  
      public BeanTransactionContext newBeanTransactionContext() throws NotSupportedException,
SystemException {
          TransactionContext ctx = TransactionContext.getContext();
          if (ctx instanceof UnspecifiedTransactionContext == false) {
              throw new NotSupportedException("Previous Transaction has not been committed");
          }
          UnspecifiedTransactionContext oldContext = (UnspecifiedTransactionContext) ctx;
          BeanTransactionContext transactionContext = new BeanTransactionContext(transactionManager,
oldContext);
          oldContext.suspend();
          try {
              transactionContext.begin();
          } catch (SystemException e) {
              oldContext.resume();
              throw e;
          } catch (NotSupportedException e) {
              oldContext.resume();
              throw e;
          }
          TransactionContext.setContext(transactionContext);
          return transactionContext;
      }
  
      public UnspecifiedTransactionContext newUnspecifiedTransactionContext() {
          UnspecifiedTransactionContext transactionContext = new UnspecifiedTransactionContext();
          TransactionContext.setContext(transactionContext);
          return transactionContext;
      }
  
      public int getStatus() throws SystemException {
          return transactionManager.getStatus();
      }
  
      public void setRollbackOnly() throws SystemException {
          transactionManager.setRollbackOnly();
      }
  
      public void setTransactionTimeout(int seconds) throws SystemException {
          transactionManager.setTransactionTimeout(seconds);
      }
  
      public static final GBeanInfo GBEAN_INFO;
  
      static {
          GBeanInfoFactory infoFactory = new GBeanInfoFactory(TransactionContextManager.class);
          infoFactory.addOperation("getContext");
          infoFactory.addOperation("setContext", new Class[] {TransactionContext.class});
          infoFactory.addOperation("newContainerTransactionContext");
          infoFactory.addOperation("newBeanTransactionContext");
          infoFactory.addOperation("newUnspecifiedTransactionContext");
  
          infoFactory.addReference("TransactionManager", TransactionManager.class);
  
          infoFactory.setConstructor(new String[] {"TransactionManager"});
          GBEAN_INFO = infoFactory.getBeanInfo();
      }
  
      public static GBeanInfo getGBeanInfo() {
          return GBEAN_INFO;
      }
  
  }
  
  
  
  1.1                  incubator-geronimo/modules/transaction/src/java/org/apache/geronimo/transaction/context/UnspecifiedTransactionContext.java
  
  Index: UnspecifiedTransactionContext.java
  ===================================================================
  /**
   *
   * Copyright 2003-2004 The Apache Software Foundation
   *
   *  Licensed under the Apache License, Version 2.0 (the "License");
   *  you may not use this file except in compliance with the License.
   *  You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
   *  Unless required by applicable law or agreed to in writing, software
   *  distributed under the License is distributed on an "AS IS" BASIS,
   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   *  See the License for the specific language governing permissions and
   *  limitations under the License.
   */
  
  package org.apache.geronimo.transaction.context;
  
  import javax.transaction.Transaction;
  
  import org.apache.geronimo.transaction.ConnectionReleaser;
  import org.apache.geronimo.transaction.context.TransactionContext;
  
  
  /**
   *
   *
   * @version $Revision: 1.1 $ $Date: 2004/07/18 22:02:01 $
   */
  public class UnspecifiedTransactionContext extends TransactionContext {
      public void begin() {
      }
  
      public void suspend() {
      }
  
      public void resume() {
      }
  
      public void commit() {
          try {
              flushState();
          } catch (Error e) {
              throw e;
          } catch (RuntimeException re) {
              throw re;
          } catch (Throwable e) {
              log.error("Unable to flush state, continuing", e);
          }
      }
  
      public void rollback() {
      }
  
      //Geronimo connector framework support
      public void setManagedConnectionInfo(ConnectionReleaser key, Object info) {
      }
  
      public Object getManagedConnectionInfo(ConnectionReleaser key) {
          return null;
      }
  
      public boolean isActive() {
          return false;
      }
  
      public Transaction getTransaction() {
          return null;
      }
  }
  
  
  

Mime
View raw message