You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by dj...@apache.org on 2004/04/06 02:21:21 UTC

cvs commit: incubator-geronimo/modules/transaction/src/java/org/apache/geronimo/transaction/manager UserTransactionImpl.java

djencks     2004/04/05 17:21:21

  Modified:    modules/connector/src/test/org/apache/geronimo/connector/outbound/connectiontracking
                        ConnectionTrackingCoordinatorTest.java
               modules/connector/src/java/org/apache/geronimo/connector/outbound
                        ConnectionTrackingInterceptor.java
                        ManagedConnectionInfo.java
                        TransactionCachingInterceptor.java
                        TransactionEnlistingInterceptor.java
               modules/connector/src/java/org/apache/geronimo/connector/outbound/connectiontracking
                        ConnectionTracker.java
                        ConnectionTrackingCoordinator.java
               modules/connector/src/test/org/apache/geronimo/connector/outbound
                        ConnectionManagerTest.java
                        ConnectionManagerTestUtils.java
                        TransactionCachingInterceptorTest.java
                        TransactionEnlistingInterceptorTest.java
               modules/jetty/src/java/org/apache/geronimo/jetty
                        JettyWebApplicationContext.java
               modules/jetty/src/test/org/apache/geronimo/jetty
                        ApplicationTest.java
  Added:       modules/connector/src/test/org/apache/geronimo/connector/outbound/connectiontracking
                        DefaultComponentInterceptor.java
                        DefaultInterceptor.java
               modules/transaction/src/java/org/apache/geronimo/transaction
                        TrackedConnectionAssociator.java
                        UserTransactionImpl.java
  Removed:     modules/connector/src/java/org/apache/geronimo/connector/outbound/connectiontracking
                        TrackedConnectionAssociator.java
               modules/connector/src/java/org/apache/geronimo/connector/outbound/connectiontracking/defaultimpl
                        DefaultComponentInterceptor.java
                        DefaultInterceptor.java
                        DefaultTransactionContext.java
               modules/transaction/src/java/org/apache/geronimo/transaction/manager
                        UserTransactionImpl.java
  Log:
  Move openejb EJBUserTransaction to geronimo UserTransactionImpl (approved by Jeremy Boynes and Dain Sundstrom, the other EJBUserTransaction committers).  Refactor ConnectionTrackingCoordinator to use global TransactionContext.  Make UserTransactionImpl enroll existing connections in the new tx
  
  Revision  Changes    Path
  1.5       +19 -46    incubator-geronimo/modules/connector/src/test/org/apache/geronimo/connector/outbound/connectiontracking/ConnectionTrackingCoordinatorTest.java
  
  Index: ConnectionTrackingCoordinatorTest.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/connector/src/test/org/apache/geronimo/connector/outbound/connectiontracking/ConnectionTrackingCoordinatorTest.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- ConnectionTrackingCoordinatorTest.java	10 Mar 2004 09:58:34 -0000	1.4
  +++ ConnectionTrackingCoordinatorTest.java	6 Apr 2004 00:21:20 -0000	1.5
  @@ -20,21 +20,16 @@
   import java.util.HashSet;
   import java.util.Map;
   import java.util.Set;
  +
   import javax.security.auth.Subject;
  -import javax.transaction.Transaction;
  -import javax.transaction.TransactionManager;
   
  +import junit.framework.TestCase;
   import org.apache.geronimo.connector.outbound.ConnectionInfo;
   import org.apache.geronimo.connector.outbound.ConnectionTrackingInterceptor;
   import org.apache.geronimo.connector.outbound.ManagedConnectionInfo;
   import org.apache.geronimo.connector.outbound.connectiontracking.defaultimpl.DefaultComponentContext;
  -import org.apache.geronimo.connector.outbound.connectiontracking.defaultimpl.DefaultTransactionContext;
   import org.apache.geronimo.security.bridge.RealmBridge;
  -import org.apache.geronimo.transaction.manager.TransactionManagerImpl;
  -import org.apache.geronimo.transaction.InstanceContext;
  -import org.apache.geronimo.transaction.TransactionContext;
  -
  -import junit.framework.TestCase;
  +import org.apache.geronimo.transaction.TrackedConnectionAssociator;
   
   /**
    *
  @@ -52,44 +47,39 @@
       private ConnectionTrackingInterceptor key2;
       private Subject subject = null;
       private Set unshareableResources;
  -    private TransactionManager transactionManager;
  -
   
       protected void setUp() throws Exception {
           connectionTrackingCoordinator = new ConnectionTrackingCoordinator();
           key1 = new ConnectionTrackingInterceptor(null, name1, connectionTrackingCoordinator, this);
           key2 = new ConnectionTrackingInterceptor(null, name2, connectionTrackingCoordinator, this);
           unshareableResources = new HashSet();
  -        connectionTrackingCoordinator.setUnshareableResources(unshareableResources);
  -        transactionManager = new TransactionManagerImpl();
       }
   
       protected void tearDown() throws Exception {
           connectionTrackingCoordinator = null;
           key1 = null;
           key2 = null;
  -        transactionManager = null;
       }
   
       public void testSimpleComponentContextLifecyle() throws Exception {
           DefaultComponentContext componentContext = new DefaultComponentContext();
  -        InstanceContext oldComponentContext = connectionTrackingCoordinator.enter(componentContext);
  -        assertNull("Expected old component context to be null", oldComponentContext);
  +        TrackedConnectionAssociator.ConnectorContextInfo connectorContext = connectionTrackingCoordinator.enter(componentContext, unshareableResources);
  +        assertNull("Expected old component context to be null", connectorContext.getInstanceContext());
           //give the context a ConnectionInfo
           ManagedConnectionInfo managedConnectionInfo = new ManagedConnectionInfo(null, null);
           ConnectionInfo connectionInfo = new ConnectionInfo(managedConnectionInfo);
           connectionTrackingCoordinator.handleObtained(key1, connectionInfo);
  -        connectionTrackingCoordinator.exit(oldComponentContext, unshareableResources);
  +        connectionTrackingCoordinator.exit(connectorContext);
           Map connectionManagerMap = componentContext.getConnectionManagerMap();
           Set infos = (Set) connectionManagerMap.get(key1);
           assertEquals("Expected one connection for key1", 1, infos.size());
           assertTrue("Expected to get supplied ConnectionInfo from infos", connectionInfo == infos.iterator().next());
   
           //Enter again, and close the handle
  -        oldComponentContext = connectionTrackingCoordinator.enter(componentContext);
  -        assertNull("Expected old component context to be null", oldComponentContext);
  +        connectorContext = connectionTrackingCoordinator.enter(componentContext, unshareableResources);
  +        assertNull("Expected old component context to be null", connectorContext.getInstanceContext());
           connectionTrackingCoordinator.handleReleased(key1, connectionInfo);
  -        connectionTrackingCoordinator.exit(oldComponentContext, unshareableResources);
  +        connectionTrackingCoordinator.exit(connectorContext);
           connectionManagerMap = componentContext.getConnectionManagerMap();
           infos = (Set) connectionManagerMap.get(key1);
           assertEquals("Expected no connection set for key1", null, infos);
  @@ -97,8 +87,8 @@
   
       public void testNestedComponentContextLifecyle() throws Exception {
           DefaultComponentContext componentContext1 = new DefaultComponentContext();
  -        InstanceContext oldComponentContext1 = connectionTrackingCoordinator.enter(componentContext1);
  -        assertNull("Expected old component context to be null", oldComponentContext1);
  +        TrackedConnectionAssociator.ConnectorContextInfo oldConnectorContext1 = connectionTrackingCoordinator.enter(componentContext1, unshareableResources);
  +        assertNull("Expected old component context to be null", oldConnectorContext1.getInstanceContext());
           //give the context a ConnectionInfo
           ManagedConnectionInfo managedConnectionInfo1 = new ManagedConnectionInfo(null, null);
           ConnectionInfo connectionInfo1 = new ConnectionInfo(managedConnectionInfo1);
  @@ -106,14 +96,14 @@
   
           //Simulate calling another component
           DefaultComponentContext componentContext2 = new DefaultComponentContext();
  -        InstanceContext oldComponentContext2 = connectionTrackingCoordinator.enter(componentContext2);
  -        assertTrue("Expected returned component context to be componentContext1", oldComponentContext2 == componentContext1);
  +        TrackedConnectionAssociator.ConnectorContextInfo oldConnectorContext2 = connectionTrackingCoordinator.enter(componentContext2, unshareableResources);
  +        assertTrue("Expected returned component context to be componentContext1", oldConnectorContext2.getInstanceContext() == componentContext1);
           //give the context a ConnectionInfo
           ManagedConnectionInfo managedConnectionInfo2 = new ManagedConnectionInfo(null, null);
           ConnectionInfo connectionInfo2 = new ConnectionInfo(managedConnectionInfo2);
           connectionTrackingCoordinator.handleObtained(key2, connectionInfo2);
   
  -        connectionTrackingCoordinator.exit(oldComponentContext2, unshareableResources);
  +        connectionTrackingCoordinator.exit(oldConnectorContext2);
           Map connectionManagerMap2 = componentContext2.getConnectionManagerMap();
           Set infos2 = (Set) connectionManagerMap2.get(key2);
           assertEquals("Expected one connection for key2", 1, infos2.size());
  @@ -121,7 +111,7 @@
           assertEquals("Expected no connection for key1", null, connectionManagerMap2.get(key1));
   
   
  -        connectionTrackingCoordinator.exit(oldComponentContext1, unshareableResources);
  +        connectionTrackingCoordinator.exit(oldConnectorContext1);
           Map connectionManagerMap1 = componentContext1.getConnectionManagerMap();
           Set infos1 = (Set) connectionManagerMap1.get(key1);
           assertEquals("Expected one connection for key1", 1, infos1.size());
  @@ -129,30 +119,13 @@
           assertEquals("Expected no connection for key2", null, connectionManagerMap1.get(key2));
   
           //Enter again, and close the handle
  -        oldComponentContext1 = connectionTrackingCoordinator.enter(componentContext1);
  -        assertNull("Expected old component context to be null", oldComponentContext1);
  +        oldConnectorContext1 = connectionTrackingCoordinator.enter(componentContext1, unshareableResources);
  +        assertNull("Expected old component context to be null", oldConnectorContext1.getInstanceContext());
           connectionTrackingCoordinator.handleReleased(key1, connectionInfo1);
  -        connectionTrackingCoordinator.exit(oldComponentContext1, unshareableResources);
  +        connectionTrackingCoordinator.exit(oldConnectorContext1);
           connectionManagerMap1 = componentContext1.getConnectionManagerMap();
           infos1 = (Set) connectionManagerMap1.get(key1);
           assertEquals("Expected no connection set for key1", null, infos1);
  -    }
  -
  -    public void testSimpleTransactionContextLifecycle() throws Exception {
  -        DefaultComponentContext componentContext = new DefaultComponentContext();
  -        InstanceContext oldComponentContext = connectionTrackingCoordinator.enter(componentContext);
  -        transactionManager.begin();
  -        Transaction transaction = transactionManager.getTransaction();
  -        DefaultTransactionContext transactionContext = new DefaultTransactionContext(transaction);
  -        TransactionContext oldTransactionContext = connectionTrackingCoordinator.setTransactionContext(transactionContext);
  -        assertNull("Expected no old transactionContext", oldTransactionContext);
  -        TransactionContext availableTransactionContext = connectionTrackingCoordinator.getTransactionContext();
  -        assertTrue("Expected the same transactionContext as we sent in", transactionContext == availableTransactionContext);
  -
  -        TransactionContext exitingTransactionContext = connectionTrackingCoordinator.setTransactionContext(null);
  -        assertTrue("Expected the same transactionContext as we sent in", transactionContext == exitingTransactionContext);
  -        TransactionContext availableTransactionContext2 = connectionTrackingCoordinator.getTransactionContext();
  -        assertNull("Expected no transactionContext", availableTransactionContext2);
       }
   
       public Subject mapSubject(Subject sourceSubject) {
  
  
  
  1.1                  incubator-geronimo/modules/connector/src/test/org/apache/geronimo/connector/outbound/connectiontracking/DefaultComponentInterceptor.java
  
  Index: DefaultComponentInterceptor.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.connector.outbound.connectiontracking;
  
  import java.util.Set;
  
  import org.apache.geronimo.transaction.InstanceContext;
  import org.apache.geronimo.transaction.TrackedConnectionAssociator;
  import org.apache.geronimo.transaction.TransactionContext;
  import org.apache.geronimo.transaction.UnspecifiedTransactionContext;
  
  /**
   *
   *
   * @version $Revision: 1.1 $ $Date: 2004/04/06 00:21:20 $
   *
   * */
  public class DefaultComponentInterceptor implements DefaultInterceptor {
  
      private final DefaultInterceptor next;
      private final TrackedConnectionAssociator cachedConnectionAssociator;
      private final Set unshareableResources;
  
      public DefaultComponentInterceptor(DefaultInterceptor next,
              TrackedConnectionAssociator cachedConnectionManager,
              Set unshareableResources) {
          this.next = next;
          this.cachedConnectionAssociator = cachedConnectionManager;
          this.unshareableResources = unshareableResources;
      }
  
      public Object invoke(InstanceContext newInstanceContext) throws Throwable {
          if (TransactionContext.getContext() == null) {
              TransactionContext.setContext(new UnspecifiedTransactionContext());
          }
          TrackedConnectionAssociator.ConnectorContextInfo oldConnectorContext = cachedConnectionAssociator.enter(newInstanceContext, unshareableResources);
          try {
              return next.invoke(newInstanceContext);
          } finally {
              cachedConnectionAssociator.exit(oldConnectorContext);
          }
      }
  }
  
  
  
  1.1                  incubator-geronimo/modules/connector/src/test/org/apache/geronimo/connector/outbound/connectiontracking/DefaultInterceptor.java
  
  Index: DefaultInterceptor.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.connector.outbound.connectiontracking;
  
  import org.apache.geronimo.transaction.InstanceContext;
  
  
  /**
   *
   *
   * @version $Revision: 1.1 $ $Date: 2004/04/06 00:21:20 $
   *
   * */
  public interface DefaultInterceptor {
  
      Object invoke(InstanceContext newInstanceContext) throws Throwable;
  }
  
  
  
  1.1                  incubator-geronimo/modules/transaction/src/java/org/apache/geronimo/transaction/TrackedConnectionAssociator.java
  
  Index: TrackedConnectionAssociator.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;
  
  import java.util.Set;
  
  import javax.resource.ResourceException;
  
  /**
   *
   *
   * @version $Revision: 1.1 $ $Date: 2004/04/06 00:21:20 $
   *
   * */
  public interface TrackedConnectionAssociator {
  
      ConnectorContextInfo enter(InstanceContext newInstanceContext,
                                 Set unshareableResources)
              throws ResourceException;
  
      void newTransaction() throws ResourceException;
  
      void exit(ConnectorContextInfo connectorContext)
              throws ResourceException;
  
      class ConnectorContextInfo {
          private final InstanceContext instanceContext;
          private final Set unshareableResources;
  
          public ConnectorContextInfo(InstanceContext instanceContext, Set unshareableResources) {
              this.instanceContext = instanceContext;
              this.unshareableResources = unshareableResources;
          }
  
          public InstanceContext getInstanceContext() {
              return instanceContext;
          }
  
          public Set getUnshareableResources() {
              return unshareableResources;
          }
      }
  }
  
  
  
  1.1                  incubator-geronimo/modules/transaction/src/java/org/apache/geronimo/transaction/UserTransactionImpl.java
  
  Index: UserTransactionImpl.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;
  
  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;
  
  /**
   * Implementation of UserTransaction for use in an EJB.
   * This adds the ability to enable or disable the operations depending on
   * the lifecycle of the EJB instance.
   *
   * @version $Revision: 1.1 $ $Date: 2004/04/06 00:21:20 $
   */
  public class UserTransactionImpl implements UserTransaction {
      private TransactionManager txnManager;
      private TrackedConnectionAssociator trackedConnectionAssociator;
      private final ThreadLocal state = new ThreadLocal() {
          protected Object initialValue() {
              return OFFLINE;
          }
      };
  
      public UserTransactionImpl() {
          state.set(OFFLINE);
      }
  
      public void setUp(TransactionManager txnManager, TrackedConnectionAssociator trackedConnectionAssociator) {
          assert !isOnline() : "Only set the tx manager when UserTransaction is offline";
          this.txnManager = txnManager;
          this.trackedConnectionAssociator = trackedConnectionAssociator;
      }
  
      public boolean isOnline() {
          return state.get() == ONLINE;
      }
  
      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";
          state.set(online ? ONLINE : OFFLINE);
      }
  
      private UserTransaction getUserTransaction() {
          return (UserTransaction) state.get();
      }
  
      public void begin() throws NotSupportedException, SystemException {
          getUserTransaction().begin();
      }
  
      public void commit() throws HeuristicMixedException, HeuristicRollbackException, IllegalStateException, RollbackException, SecurityException, SystemException {
          getUserTransaction().commit();
      }
  
      public int getStatus() throws SystemException {
          return getUserTransaction().getStatus();
      }
  
      public void rollback() throws IllegalStateException, SecurityException, SystemException {
          getUserTransaction().rollback();
      }
  
      public void setRollbackOnly() throws IllegalStateException, SystemException {
          getUserTransaction().setRollbackOnly();
      }
  
      public void setTransactionTimeout(int timeout) throws SystemException {
          getUserTransaction().setTransactionTimeout(timeout);
      }
  
      private final UserTransaction ONLINE = new UserTransaction() {
          public int getStatus() throws SystemException {
              return txnManager.getStatus();
          }
  
          public void setRollbackOnly() throws IllegalStateException, SystemException {
              txnManager.setRollbackOnly();
          }
  
          public void setTransactionTimeout(int seconds) throws SystemException {
              txnManager.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);
              try {
                  trackedConnectionAssociator.newTransaction();
              } catch (ResourceException e) {
                  throw (SystemException)new SystemException().initCause(e);
              }
          }
  
          public void commit() throws HeuristicMixedException, HeuristicRollbackException, IllegalStateException, RollbackException, SecurityException, SystemException {
              TransactionContext ctx = TransactionContext.getContext();
              if (ctx instanceof BeanTransactionContext == false) {
                  throw new IllegalStateException("Transaction has not been started");
              }
              BeanTransactionContext beanContext = (BeanTransactionContext) ctx;
              try {
                  beanContext.commit();
              } finally {
                  UnspecifiedTransactionContext oldContext = beanContext.getOldContext();
                  TransactionContext.setContext(oldContext);
                  oldContext.resume();
              }
          }
  
          public void rollback() throws IllegalStateException, SecurityException, SystemException {
              TransactionContext ctx = TransactionContext.getContext();
              if (ctx instanceof BeanTransactionContext == false) {
                  throw new IllegalStateException("Transaction has not been started");
              }
              BeanTransactionContext beanContext = (BeanTransactionContext) ctx;
              try {
                  beanContext.rollback();
              } finally {
                  UnspecifiedTransactionContext oldContext = beanContext.getOldContext();
                  TransactionContext.setContext(oldContext);
                  oldContext.resume();
              }
          }
      };
  
      private static final UserTransaction OFFLINE = new UserTransaction() {
          public void begin() throws NotSupportedException, SystemException {
              throw new IllegalStateException("Cannot use UserTransaction methods in this state");
          }
  
          public void commit() throws HeuristicMixedException, HeuristicRollbackException, IllegalStateException, RollbackException, SecurityException, SystemException {
              throw new IllegalStateException("Cannot use UserTransaction methods in this state");
          }
  
          public int getStatus() throws SystemException {
              throw new IllegalStateException("Cannot use UserTransaction methods in this state");
          }
  
          public void rollback() throws IllegalStateException, SecurityException, SystemException {
              throw new IllegalStateException("Cannot use UserTransaction methods in this state");
          }
  
          public void setRollbackOnly() throws IllegalStateException, SystemException {
              throw new IllegalStateException("Cannot use UserTransaction methods in this state");
          }
  
          public void setTransactionTimeout(int seconds) throws SystemException {
              throw new IllegalStateException("Cannot use UserTransaction methods in this state");
          }
      };
  }
  
  
  
  1.6       +4 -5      incubator-geronimo/modules/connector/src/java/org/apache/geronimo/connector/outbound/ConnectionTrackingInterceptor.java
  
  Index: ConnectionTrackingInterceptor.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/connector/src/java/org/apache/geronimo/connector/outbound/ConnectionTrackingInterceptor.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- ConnectionTrackingInterceptor.java	10 Mar 2004 09:58:32 -0000	1.5
  +++ ConnectionTrackingInterceptor.java	6 Apr 2004 00:21:21 -0000	1.6
  @@ -20,6 +20,7 @@
   import java.util.Collection;
   import java.util.Iterator;
   import java.util.Set;
  +
   import javax.resource.ResourceException;
   import javax.resource.spi.DissociatableManagedConnection;
   import javax.resource.spi.ManagedConnection;
  @@ -27,8 +28,8 @@
   import javax.security.auth.login.LoginException;
   
   import org.apache.geronimo.connector.outbound.connectiontracking.ConnectionTracker;
  -import org.apache.geronimo.security.bridge.RealmBridge;
   import org.apache.geronimo.security.ContextManager;
  +import org.apache.geronimo.security.bridge.RealmBridge;
   
   /**
    * ConnectionTrackingInterceptor.java handles communication with the
  @@ -68,8 +69,6 @@
        * @throws ResourceException
        */
       public void getConnection(ConnectionInfo connectionInfo) throws ResourceException {
  -        ManagedConnectionInfo managedConnectionInfo = connectionInfo.getManagedConnectionInfo();
  -        managedConnectionInfo.setTransactionContext(connectionTracker.getTransactionContext());
           next.getConnection(connectionInfo);
           connectionTracker.handleObtained(this, connectionInfo);
       }
  @@ -117,7 +116,7 @@
           }
           for (Iterator i = connectionInfos.iterator(); i.hasNext();) {
               ConnectionInfo connectionInfo = (ConnectionInfo) i.next();
  -            getConnection(connectionInfo);
  +            next.getConnection(connectionInfo);
           }
   
       }
  
  
  
  1.5       +0 -11     incubator-geronimo/modules/connector/src/java/org/apache/geronimo/connector/outbound/ManagedConnectionInfo.java
  
  Index: ManagedConnectionInfo.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/connector/src/java/org/apache/geronimo/connector/outbound/ManagedConnectionInfo.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- ManagedConnectionInfo.java	10 Mar 2004 09:58:32 -0000	1.4
  +++ ManagedConnectionInfo.java	6 Apr 2004 00:21:21 -0000	1.5
  @@ -23,8 +23,6 @@
   import javax.security.auth.Subject;
   import javax.transaction.xa.XAResource;
   
  -import org.apache.geronimo.transaction.TransactionContext;
  -
   /**
    * ConnectionRequest.java
    *
  @@ -38,7 +36,6 @@
       private ManagedConnectionFactory managedConnectionFactory;
       private ConnectionRequestInfo connectionRequestInfo;
       private Subject subject;
  -    private TransactionContext transactionContext;
       private ManagedConnection managedConnection;
       private XAResource xares;
       private long lastUsed;
  @@ -75,14 +72,6 @@
   
       public void setSubject(Subject subject) {
           this.subject = subject;
  -    }
  -
  -    public TransactionContext getTransactionContext() {
  -        return transactionContext;
  -    }
  -
  -    public void setTransactionContext(TransactionContext transactionContext) {
  -        this.transactionContext = transactionContext;
       }
   
       public ManagedConnection getManagedConnection() {
  
  
  
  1.5       +2 -2      incubator-geronimo/modules/connector/src/java/org/apache/geronimo/connector/outbound/TransactionCachingInterceptor.java
  
  Index: TransactionCachingInterceptor.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/connector/src/java/org/apache/geronimo/connector/outbound/TransactionCachingInterceptor.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- TransactionCachingInterceptor.java	10 Mar 2004 09:58:32 -0000	1.4
  +++ TransactionCachingInterceptor.java	6 Apr 2004 00:21:21 -0000	1.5
  @@ -54,7 +54,7 @@
       }
   
       public void getConnection(ConnectionInfo connectionInfo) throws ResourceException {
  -        TransactionContext transactionContext = connectionTracker.getTransactionContext();
  +        TransactionContext transactionContext = TransactionContext.getContext();
           ManagedConnectionInfo managedConnectionInfo = (ManagedConnectionInfo)transactionContext.getManagedConnectionInfo(this);
           if (managedConnectionInfo != null) {
               connectionInfo.setManagedConnectionInfo(managedConnectionInfo);
  @@ -71,7 +71,7 @@
               next.returnConnection(connectionInfo, connectionReturnAction);
           }
   
  -        TransactionContext transactionContext = connectionTracker.getTransactionContext();
  +        TransactionContext transactionContext = TransactionContext.getContext();
           if (transactionContext.isActive()) {
               return;
           }
  
  
  
  1.5       +2 -3      incubator-geronimo/modules/connector/src/java/org/apache/geronimo/connector/outbound/TransactionEnlistingInterceptor.java
  
  Index: TransactionEnlistingInterceptor.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/connector/src/java/org/apache/geronimo/connector/outbound/TransactionEnlistingInterceptor.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- TransactionEnlistingInterceptor.java	10 Mar 2004 09:58:32 -0000	1.4
  +++ TransactionEnlistingInterceptor.java	6 Apr 2004 00:21:21 -0000	1.5
  @@ -46,7 +46,7 @@
           next.getConnection(connectionInfo);
           try {
               ManagedConnectionInfo mci = connectionInfo.getManagedConnectionInfo();
  -            TransactionContext transactionContext = mci.getTransactionContext();
  +            TransactionContext transactionContext = TransactionContext.getContext();
               if (transactionContext.isActive()) {
                   XAResource xares = mci.getXAResource();
                   transactionContext.getTransaction().enlistResource(xares);
  @@ -75,11 +75,10 @@
               ConnectionReturnAction connectionReturnAction) {
           try {
               ManagedConnectionInfo mci = connectionInfo.getManagedConnectionInfo();
  -            TransactionContext transactionContext = mci.getTransactionContext();
  +            TransactionContext transactionContext = TransactionContext.getContext();
               if (transactionContext.isActive()) {
                   XAResource xares = mci.getXAResource();
                   transactionContext.getTransaction().delistResource(xares, XAResource.TMSUSPEND);
  -                mci.setTransactionContext(null);
               }
   
           } catch (SystemException e) {
  
  
  
  1.4       +1 -2      incubator-geronimo/modules/connector/src/java/org/apache/geronimo/connector/outbound/connectiontracking/ConnectionTracker.java
  
  Index: ConnectionTracker.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/connector/src/java/org/apache/geronimo/connector/outbound/connectiontracking/ConnectionTracker.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- ConnectionTracker.java	25 Feb 2004 09:57:11 -0000	1.3
  +++ ConnectionTracker.java	6 Apr 2004 00:21:21 -0000	1.4
  @@ -36,5 +36,4 @@
               ConnectionTrackingInterceptor connectionTrackingInterceptor,
               ConnectionInfo connectionInfo);
   
  -    TransactionContext getTransactionContext();
   }
  
  
  
  1.6       +30 -45    incubator-geronimo/modules/connector/src/java/org/apache/geronimo/connector/outbound/connectiontracking/ConnectionTrackingCoordinator.java
  
  Index: ConnectionTrackingCoordinator.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/connector/src/java/org/apache/geronimo/connector/outbound/connectiontracking/ConnectionTrackingCoordinator.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- ConnectionTrackingCoordinator.java	10 Mar 2004 09:58:33 -0000	1.5
  +++ ConnectionTrackingCoordinator.java	6 Apr 2004 00:21:21 -0000	1.6
  @@ -21,15 +21,15 @@
   import java.util.Iterator;
   import java.util.Map;
   import java.util.Set;
  +
   import javax.resource.ResourceException;
   
   import org.apache.geronimo.connector.outbound.ConnectionInfo;
   import org.apache.geronimo.connector.outbound.ConnectionTrackingInterceptor;
   import org.apache.geronimo.gbean.GBeanInfo;
   import org.apache.geronimo.gbean.GBeanInfoFactory;
  -import org.apache.geronimo.gbean.GOperationInfo;
  -import org.apache.geronimo.transaction.TransactionContext;
   import org.apache.geronimo.transaction.InstanceContext;
  +import org.apache.geronimo.transaction.TrackedConnectionAssociator;
   
   /**
    * ConnectionTrackingCoordinator tracks connections that are in use by
  @@ -52,59 +52,54 @@
       public final static GBeanInfo GBEAN_INFO;
   
       private final ThreadLocal currentInstanceContexts = new ThreadLocal();
  -    private final ThreadLocal currentConnectorTransactionContexts = new ThreadLocal();
       private final ThreadLocal currentUnshareableResources = new ThreadLocal();
   
  -    public InstanceContext enter(InstanceContext newInstanceContext)
  +    public ConnectorContextInfo enter(InstanceContext newInstanceContext, Set newUnshareableResources)
               throws ResourceException {
           InstanceContext oldInstanceContext = (InstanceContext) currentInstanceContexts.get();
  +        Set oldUnshareableResources = (Set)currentUnshareableResources.get();
  +        notifyConnections(newInstanceContext, newUnshareableResources);
           currentInstanceContexts.set(newInstanceContext);
  -        return oldInstanceContext;
  +        currentUnshareableResources.set(newUnshareableResources);
  +        return new TrackedConnectionAssociator.ConnectorContextInfo(oldInstanceContext, oldUnshareableResources);
       }
   
  -    public void exit(InstanceContext reenteringInstanceContext,
  -            Set unshareableResources)
  -            throws ResourceException {
  -        InstanceContext oldInstanceContext = (InstanceContext) currentInstanceContexts.get();
  -        Map resources = oldInstanceContext.getConnectionManagerMap();
  -        for (Iterator i = resources.entrySet().iterator(); i.hasNext();) {
  +    private void notifyConnections(InstanceContext oldInstanceContext, Set newUnshareableResources) throws ResourceException {
  +        Map connectionManagerToManagedConnectionInfoMap = oldInstanceContext.getConnectionManagerMap();
  +        for (Iterator i = connectionManagerToManagedConnectionInfoMap.entrySet().iterator(); i.hasNext();) {
               Map.Entry entry = (Map.Entry) i.next();
               ConnectionTrackingInterceptor mcci =
                       (ConnectionTrackingInterceptor) entry.getKey();
               Set connections = (Set) entry.getValue();
  -            mcci.exit(connections, unshareableResources);
  -            if (connections.isEmpty()) {
  -                i.remove();
  -            }
  +            mcci.enter(connections, newUnshareableResources);
           }
  -        currentInstanceContexts.set(reenteringInstanceContext);
       }
   
  -    public Set setUnshareableResources(Set unshareableResources) {
  -        Set oldUnshareableResources = (Set) currentUnshareableResources.get();
  -        currentUnshareableResources.set(unshareableResources);
  -        return oldUnshareableResources;
  +    public void newTransaction() throws ResourceException {
  +        InstanceContext oldInstanceContext = (InstanceContext) currentInstanceContexts.get();
  +        Set oldUnshareableResources = (Set)currentUnshareableResources.get();
  +        notifyConnections(oldInstanceContext, oldUnshareableResources);
       }
   
  -    public TransactionContext setTransactionContext(TransactionContext newTransactionContext) throws ResourceException {
  -        TransactionContext oldConnectorTransactionContext = (TransactionContext) currentConnectorTransactionContexts.get();
  -        currentConnectorTransactionContexts.set(newTransactionContext);
  -        InstanceContext instanceContext = (InstanceContext) currentInstanceContexts.get();
  -        Set unshareableResources = (Set) currentUnshareableResources.get();
  -        Map connectionManagerToManagedConnectionInfoMap = instanceContext.getConnectionManagerMap();
  -        for (Iterator i = connectionManagerToManagedConnectionInfoMap.entrySet().iterator(); i.hasNext();) {
  +    public void exit(ConnectorContextInfo reenteringConnectorContext)
  +            throws ResourceException {
  +        InstanceContext oldInstanceContext = (InstanceContext) currentInstanceContexts.get();
  +        Set oldUnshareableResources = (Set)currentUnshareableResources.get();
  +        Map resources = oldInstanceContext.getConnectionManagerMap();
  +        for (Iterator i = resources.entrySet().iterator(); i.hasNext();) {
               Map.Entry entry = (Map.Entry) i.next();
               ConnectionTrackingInterceptor mcci =
                       (ConnectionTrackingInterceptor) entry.getKey();
               Set connections = (Set) entry.getValue();
  -            mcci.enter(connections, unshareableResources);
  +            mcci.exit(connections, oldUnshareableResources);
  +            if (connections.isEmpty()) {
  +                i.remove();
  +            }
           }
  -        return oldConnectorTransactionContext;
  +        currentInstanceContexts.set(reenteringConnectorContext.getInstanceContext());
  +        currentUnshareableResources.set(reenteringConnectorContext.getUnshareableResources());
       }
   
  -    public void resetTransactionContext(TransactionContext transactionContext) {
  -        currentConnectorTransactionContexts.set(transactionContext);
  -    }
   
       public void handleObtained(
               ConnectionTrackingInterceptor connectionTrackingInterceptor,
  @@ -135,20 +130,10 @@
           infos.remove(connectionInfo);
       }
   
  -    public TransactionContext getTransactionContext() {
  -        return (TransactionContext) currentConnectorTransactionContexts.get();
  -    }
  -
       static {
           GBeanInfoFactory infoFactory = new GBeanInfoFactory(ConnectionTrackingCoordinator.class.getName());
  -        infoFactory.addOperation(new GOperationInfo("enter", new String[]{InstanceContext.class.getName()}));
  -        infoFactory.addOperation(new GOperationInfo("exit", new String[]{InstanceContext.class.getName(), Set.class.getName()}));
  -        infoFactory.addOperation(new GOperationInfo("setTransactionContext", new String[]{TransactionContext.class.getName()}));
  -        infoFactory.addOperation(new GOperationInfo("setUnshareableResources", new String[]{Set.class.getName()}));
  -        infoFactory.addOperation(new GOperationInfo("resetTransactionContext", new String[]{TransactionContext.class.getName()}));
  -        infoFactory.addOperation(new GOperationInfo("handleObtained", new String[]{ConnectionTrackingInterceptor.class.getName(), ConnectionInfo.class.getName()}));
  -        infoFactory.addOperation(new GOperationInfo("handleReleased", new String[]{ConnectionTrackingInterceptor.class.getName(), ConnectionInfo.class.getName()}));
  -        infoFactory.addOperation(new GOperationInfo("getTransactionContext"));
  +        infoFactory.addInterface(TrackedConnectionAssociator.class);
  +        infoFactory.addInterface(ConnectionTracker.class);
           GBEAN_INFO = infoFactory.getBeanInfo();
       }
   
  
  
  
  1.7       +48 -17    incubator-geronimo/modules/connector/src/test/org/apache/geronimo/connector/outbound/ConnectionManagerTest.java
  
  Index: ConnectionManagerTest.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/connector/src/test/org/apache/geronimo/connector/outbound/ConnectionManagerTest.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- ConnectionManagerTest.java	10 Mar 2004 09:58:34 -0000	1.6
  +++ ConnectionManagerTest.java	6 Apr 2004 00:21:21 -0000	1.7
  @@ -19,6 +19,7 @@
   
   import java.util.HashSet;
   import java.util.Set;
  +
   import javax.security.auth.Subject;
   import javax.transaction.TransactionManager;
   
  @@ -29,12 +30,16 @@
   import org.apache.geronimo.connector.mock.MockXAResource;
   import org.apache.geronimo.connector.outbound.connectiontracking.ConnectionTrackingCoordinator;
   import org.apache.geronimo.connector.outbound.connectiontracking.defaultimpl.DefaultComponentContext;
  -import org.apache.geronimo.connector.outbound.connectiontracking.defaultimpl.DefaultComponentInterceptor;
  -import org.apache.geronimo.connector.outbound.connectiontracking.defaultimpl.DefaultInterceptor;
  +import org.apache.geronimo.connector.outbound.connectiontracking.DefaultComponentInterceptor;
  +import org.apache.geronimo.connector.outbound.connectiontracking.DefaultInterceptor;
   import org.apache.geronimo.kernel.Kernel;
   import org.apache.geronimo.security.bridge.RealmBridge;
   import org.apache.geronimo.transaction.manager.TransactionManagerImpl;
   import org.apache.geronimo.transaction.InstanceContext;
  +import org.apache.geronimo.transaction.TransactionContext;
  +import org.apache.geronimo.transaction.ContainerTransactionContext;
  +import org.apache.geronimo.transaction.UnspecifiedTransactionContext;
  +import org.apache.geronimo.transaction.UserTransactionImpl;
   
   import junit.framework.TestCase;
   
  @@ -69,6 +74,8 @@
       protected MockManagedConnection mockManagedConnection;
       protected Subject subject;
   
  +    protected UserTransactionImpl userTransaction;
  +
       protected void setUp() throws Exception {
           connectionTrackingCoordinator = new ConnectionTrackingCoordinator();
           kernel = new Kernel("test.kernel", "testdomain");
  @@ -89,7 +96,7 @@
           connectionManagerDeployment.doStart();
           connectionFactory = (MockConnectionFactory) connectionManagerDeployment.createConnectionFactory(mockManagedConnectionFactory);
           defaultComponentContext = new DefaultComponentContext();
  -        defaultComponentInterceptor = new DefaultComponentInterceptor(this, connectionTrackingCoordinator, unshareableResources, transactionManager);
  +        defaultComponentInterceptor = new DefaultComponentInterceptor(this, connectionTrackingCoordinator, unshareableResources);
       }
   
       protected void tearDown() throws Exception {
  @@ -105,39 +112,63 @@
   
   
       public void testSingleTransactionCall() throws Throwable {
  -        transactionManager.begin();
  +        ContainerTransactionContext transactionContext = new ContainerTransactionContext(transactionManager);
  +        TransactionContext.setContext(transactionContext);
  +        transactionContext.begin();
           defaultComponentInterceptor.invoke(defaultComponentContext);
           MockXAResource mockXAResource = (MockXAResource) mockManagedConnection.getXAResource();
  -        assertTrue("XAResource should know one xid", mockXAResource.getKnownXids().size() == 1);
  -        assertTrue("Should not be committed", mockXAResource.getCommitted() == null);
  +        assertEquals("XAResource should know one xid", 1, mockXAResource.getKnownXids().size());
  +        assertNull("Should not be committed", mockXAResource.getCommitted());
           transactionManager.commit();
  -        assertTrue("Should be committed", mockXAResource.getCommitted() != null);
  +        assertNotNull("Should be committed", mockXAResource.getCommitted());
       }
   
       public void testNoTransactionCall() throws Throwable {
  +        TransactionContext.setContext(new UnspecifiedTransactionContext());
           defaultComponentInterceptor.invoke(defaultComponentContext);
           MockXAResource mockXAResource = (MockXAResource) mockManagedConnection.getXAResource();
  -        assertTrue("XAResource should know 0 xid", mockXAResource.getKnownXids().size() == 0);
  -        assertTrue("Should not be committed", mockXAResource.getCommitted() == null);
  +        assertEquals("XAResource should know 0 xid", 0, mockXAResource.getKnownXids().size());
  +        assertNull("Should not be committed", mockXAResource.getCommitted());
       }
   
       public void testOneTransactionTwoCalls() throws Throwable {
  -        transactionManager.begin();
  +        ContainerTransactionContext transactionContext = new ContainerTransactionContext(transactionManager);
  +        TransactionContext.setContext(transactionContext);
  +        transactionContext.begin();
           defaultComponentInterceptor.invoke(defaultComponentContext);
           MockXAResource mockXAResource = (MockXAResource) mockManagedConnection.getXAResource();
  -        assertTrue("XAResource should know one xid", mockXAResource.getKnownXids().size() == 1);
  -        assertTrue("Should not be committed", mockXAResource.getCommitted() == null);
  +        assertEquals("XAResource should know one xid", 1, mockXAResource.getKnownXids().size());
  +        assertNull("Should not be committed", mockXAResource.getCommitted());
           defaultComponentInterceptor.invoke(defaultComponentContext);
  -        assertTrue("Expected same XAResource", mockXAResource == mockManagedConnection.getXAResource());
  -        assertTrue("XAResource should know one xid", mockXAResource.getKnownXids().size() == 1);
  -        assertTrue("Should not be committed", mockXAResource.getCommitted() == null);
  +        assertEquals("Expected same XAResource", mockXAResource, mockManagedConnection.getXAResource());
  +        assertEquals("XAResource should know one xid", 1, mockXAResource.getKnownXids().size());
  +        assertNull("Should not be committed", mockXAResource.getCommitted());
           transactionManager.commit();
  -        assertTrue("Should be committed", mockXAResource.getCommitted() != null);
  +        assertNotNull("Should be committed", mockXAResource.getCommitted());
  +    }
  +
  +    public void testUserTransactionEnlistingExistingConnections() throws Throwable {
  +        TransactionContext.setContext(new UnspecifiedTransactionContext());
  +        userTransaction = new UserTransactionImpl();
  +        userTransaction.setUp(transactionManager, connectionTrackingCoordinator);
  +        userTransaction.setOnline(true);
  +        defaultComponentInterceptor.invoke(defaultComponentContext);
  +        MockXAResource mockXAResource = (MockXAResource) mockManagedConnection.getXAResource();
  +        assertEquals("XAResource should know 1 xid", 1, mockXAResource.getKnownXids().size());
  +        assertNotNull("Should be committed", mockXAResource.getCommitted());
       }
   
       public Object invoke(InstanceContext newInstanceContext) throws Throwable {
           MockConnection mockConnection = (MockConnection) connectionFactory.getConnection();
           mockManagedConnection = mockConnection.getManagedConnection();
  +        if (userTransaction != null) {
  +            userTransaction.begin();
  +            MockXAResource mockXAResource = (MockXAResource) mockManagedConnection.getXAResource();
  +            assertEquals("XAResource should know one xid", 1, mockXAResource.getKnownXids().size());
  +            assertNull("Should not be committed", mockXAResource.getCommitted());
  +            userTransaction.commit();
  +            assertNotNull("Should be committed", mockXAResource.getCommitted());
  +        }
           mockConnection.close();
           return null;
       }
  
  
  
  1.4       +3 -12     incubator-geronimo/modules/connector/src/test/org/apache/geronimo/connector/outbound/ConnectionManagerTestUtils.java
  
  Index: ConnectionManagerTestUtils.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/connector/src/test/org/apache/geronimo/connector/outbound/ConnectionManagerTestUtils.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- ConnectionManagerTestUtils.java	10 Mar 2004 09:58:34 -0000	1.3
  +++ ConnectionManagerTestUtils.java	6 Apr 2004 00:21:21 -0000	1.4
  @@ -20,6 +20,7 @@
   import java.io.PrintWriter;
   import java.security.Principal;
   import java.util.Set;
  +
   import javax.resource.ResourceException;
   import javax.resource.spi.ConnectionEventListener;
   import javax.resource.spi.ConnectionRequestInfo;
  @@ -28,13 +29,10 @@
   import javax.resource.spi.ManagedConnection;
   import javax.resource.spi.ManagedConnectionMetaData;
   import javax.security.auth.Subject;
  -import javax.transaction.Transaction;
   import javax.transaction.xa.XAResource;
   
  -import org.apache.geronimo.connector.outbound.connectiontracking.defaultimpl.DefaultTransactionContext;
  -import org.apache.geronimo.security.bridge.RealmBridge;
  -
   import junit.framework.TestCase;
  +import org.apache.geronimo.security.bridge.RealmBridge;
   
   /**
    *
  @@ -85,13 +83,6 @@
   
       protected ConnectionInfo makeConnectionInfo() {
           ManagedConnectionInfo managedConnectionInfo = new ManagedConnectionInfo(null, null);
  -        return new ConnectionInfo(managedConnectionInfo);
  -    }
  -
  -    protected ConnectionInfo makeConnectionInfo(Transaction transaction) throws Exception {
  -        DefaultTransactionContext transactionContext = new DefaultTransactionContext(transaction);
  -        ManagedConnectionInfo managedConnectionInfo = new ManagedConnectionInfo(null, null);
  -        managedConnectionInfo.setTransactionContext(transactionContext);
           return new ConnectionInfo(managedConnectionInfo);
       }
   
  
  
  
  1.5       +31 -39    incubator-geronimo/modules/connector/src/test/org/apache/geronimo/connector/outbound/TransactionCachingInterceptorTest.java
  
  Index: TransactionCachingInterceptorTest.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/connector/src/test/org/apache/geronimo/connector/outbound/TransactionCachingInterceptorTest.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- TransactionCachingInterceptorTest.java	10 Mar 2004 09:58:34 -0000	1.4
  +++ TransactionCachingInterceptorTest.java	6 Apr 2004 00:21:21 -0000	1.5
  @@ -18,13 +18,13 @@
   package org.apache.geronimo.connector.outbound;
   
   import javax.resource.ResourceException;
  -import javax.transaction.Transaction;
   import javax.transaction.TransactionManager;
   
   import org.apache.geronimo.connector.outbound.connectiontracking.ConnectionTracker;
  -import org.apache.geronimo.connector.outbound.connectiontracking.defaultimpl.DefaultTransactionContext;
  -import org.apache.geronimo.transaction.manager.TransactionManagerImpl;
  +import org.apache.geronimo.transaction.ContainerTransactionContext;
   import org.apache.geronimo.transaction.TransactionContext;
  +import org.apache.geronimo.transaction.UnspecifiedTransactionContext;
  +import org.apache.geronimo.transaction.manager.TransactionManagerImpl;
   
   /**
    *
  @@ -37,7 +37,6 @@
   
       private TransactionManager transactionManager;
       private TransactionCachingInterceptor transactionCachingInterceptor;
  -    private DefaultTransactionContext defaultTransactionContext;
   
       protected void setUp() throws Exception {
           super.setUp();
  @@ -52,16 +51,16 @@
       }
   
       public void testGetConnectionInTransaction() throws Exception {
  -        transactionManager.begin();
  -        Transaction transaction = transactionManager.getTransaction();
  -        defaultTransactionContext = new DefaultTransactionContext(transaction);
  +        ContainerTransactionContext transactionContext = new ContainerTransactionContext(transactionManager);
  +        TransactionContext.setContext(transactionContext);
  +        transactionContext.begin();
           ConnectionInfo connectionInfo1 = makeConnectionInfo();
           transactionCachingInterceptor.getConnection(connectionInfo1);
           assertTrue("Expected to get an initial connection", obtainedConnectionInfo != null);
           assertTrue("Expected nothing returned yet", returnedConnectionInfo == null);
           assertTrue("Expected the same ManagedConnectionInfo in the TransactionContext as was returned",
                   connectionInfo1.getManagedConnectionInfo()
  -                == defaultTransactionContext.getManagedConnectionInfo(transactionCachingInterceptor));
  +                == transactionContext.getManagedConnectionInfo(transactionCachingInterceptor));
           obtainedConnectionInfo = null;
           ConnectionInfo connectionInfo2 = new ConnectionInfo();
           transactionCachingInterceptor.getConnection(connectionInfo2);
  @@ -70,24 +69,24 @@
           assertTrue("Expected the same ManagedConnectionInfo in both ConnectionInfos",
                   connectionInfo1.getManagedConnectionInfo() == connectionInfo2.getManagedConnectionInfo());
           assertTrue("Expected the same ManagedConnectionInfo in the TransactionContext as was returned",
  -                connectionInfo1.getManagedConnectionInfo() == defaultTransactionContext.getManagedConnectionInfo(transactionCachingInterceptor));
  +                connectionInfo1.getManagedConnectionInfo() == transactionContext.getManagedConnectionInfo(transactionCachingInterceptor));
           //commit, see if connection returned.
           //we didn't create any handles, so the "ManagedConnection" should be returned.
  -        assertTrue("Expected TransactionContext to report active", defaultTransactionContext.isActive());
  -        transactionManager.commit();
  +        assertTrue("Expected TransactionContext to report active", transactionContext.isActive());
  +        transactionContext.commit();
           assertTrue("Expected connection to be returned", returnedConnectionInfo != null);
  -        assertTrue("Expected TransactionContext to report inactive", !defaultTransactionContext.isActive());
  +        assertTrue("Expected TransactionContext to report inactive", !transactionContext.isActive());
   
       }
   
       public void testGetConnectionOutsideTransaction() throws Exception {
  -        defaultTransactionContext = new DefaultTransactionContext(null);
  +        TransactionContext.setContext(new UnspecifiedTransactionContext());
           ConnectionInfo connectionInfo1 = makeConnectionInfo();
           transactionCachingInterceptor.getConnection(connectionInfo1);
           assertTrue("Expected to get an initial connection", obtainedConnectionInfo != null);
           assertTrue("Expected nothing returned yet", returnedConnectionInfo == null);
           assertTrue("Expected no ManagedConnectionInfo in the TransactionContext",
  -                null == defaultTransactionContext.getManagedConnectionInfo(transactionCachingInterceptor));
  +                null == TransactionContext.getContext().getManagedConnectionInfo(transactionCachingInterceptor));
           obtainedConnectionInfo = null;
           ConnectionInfo connectionInfo2 = makeConnectionInfo();
           transactionCachingInterceptor.getConnection(connectionInfo2);
  @@ -96,33 +95,32 @@
           assertTrue("Expected different ManagedConnectionInfo in both ConnectionInfos",
                   connectionInfo1.getManagedConnectionInfo() != connectionInfo2.getManagedConnectionInfo());
           assertTrue("Expected no ManagedConnectionInfo in the TransactionContext",
  -                null == defaultTransactionContext.getManagedConnectionInfo(transactionCachingInterceptor));
  +                null == TransactionContext.getContext().getManagedConnectionInfo(transactionCachingInterceptor));
           //we didn't create any handles, so the "ManagedConnection" should be returned.
  -        assertTrue("Expected TransactionContext to report inactive", !defaultTransactionContext.isActive());
  +        assertTrue("Expected TransactionContext to report inactive", !TransactionContext.getContext().isActive());
           transactionCachingInterceptor.returnConnection(connectionInfo1, ConnectionReturnAction.RETURN_HANDLE);
           assertTrue("Expected connection to be returned", returnedConnectionInfo != null);
           returnedConnectionInfo = null;
           transactionCachingInterceptor.returnConnection(connectionInfo2, ConnectionReturnAction.RETURN_HANDLE);
           assertTrue("Expected connection to be returned", returnedConnectionInfo != null);
   
  -        assertTrue("Expected TransactionContext to report inactive", !defaultTransactionContext.isActive());
  +        assertTrue("Expected TransactionContext to report inactive", !TransactionContext.getContext().isActive());
   
       }
   
       public void testTransactionIndependence() throws Exception {
  -        transactionManager.begin();
  -        Transaction transaction1 = transactionManager.getTransaction();
  -        defaultTransactionContext = new DefaultTransactionContext(transaction1);
  -        DefaultTransactionContext defaultTransactionContext1 = defaultTransactionContext;
  +        ContainerTransactionContext transactionContext1 = new ContainerTransactionContext(transactionManager);
  +        TransactionContext.setContext(transactionContext1);
  +        transactionContext1.begin();
           ConnectionInfo connectionInfo1 = makeConnectionInfo();
           transactionCachingInterceptor.getConnection(connectionInfo1);
           obtainedConnectionInfo = null;
   
           //start a second transaction
  -        transactionManager.suspend();
  -        transactionManager.begin();
  -        Transaction transaction2 = transactionManager.getTransaction();
  -        defaultTransactionContext = new DefaultTransactionContext(transaction2);
  +        transactionContext1.suspend();
  +        ContainerTransactionContext transactionContext2 = new ContainerTransactionContext(transactionManager);
  +        TransactionContext.setContext(transactionContext2);
  +        transactionContext2.begin();
           ConnectionInfo connectionInfo2 = makeConnectionInfo();
           transactionCachingInterceptor.getConnection(connectionInfo2);
           assertTrue("Expected to get a second connection", obtainedConnectionInfo != null);
  @@ -130,20 +128,19 @@
           assertTrue("Expected different ManagedConnectionInfo in each ConnectionInfos",
                   connectionInfo1.getManagedConnectionInfo() != connectionInfo2.getManagedConnectionInfo());
           assertTrue("Expected the same ManagedConnectionInfo in the TransactionContext as was returned",
  -                connectionInfo2.getManagedConnectionInfo() == defaultTransactionContext.getManagedConnectionInfo(transactionCachingInterceptor));
  +                connectionInfo2.getManagedConnectionInfo() == transactionContext2.getManagedConnectionInfo(transactionCachingInterceptor));
           //commit 2nd transaction, see if connection returned.
           //we didn't create any handles, so the "ManagedConnection" should be returned.
  -        assertTrue("Expected TransactionContext to report active", defaultTransactionContext.isActive());
  -        transactionManager.commit();
  +        assertTrue("Expected TransactionContext to report active", transactionContext2.isActive());
  +        transactionContext2.commit();
           assertTrue("Expected connection to be returned", returnedConnectionInfo != null);
  -        assertTrue("Expected TransactionContext to report inactive", !defaultTransactionContext.isActive());
  +        assertTrue("Expected TransactionContext to report inactive", !transactionContext2.isActive());
           returnedConnectionInfo = null;
           //resume first transaction
  -        transactionManager.resume(transaction1);
  -        defaultTransactionContext = defaultTransactionContext1;
  -        transactionManager.commit();
  +        transactionContext1.resume();
  +        transactionContext1.commit();
           assertTrue("Expected connection to be returned", returnedConnectionInfo != null);
  -        assertTrue("Expected TransactionContext to report inactive", !defaultTransactionContext.isActive());
  +        assertTrue("Expected TransactionContext to report inactive", !transactionContext1.isActive());
       }
   
   //interface implementations
  @@ -163,10 +160,5 @@
               ConnectionTrackingInterceptor connectionTrackingInterceptor,
               ConnectionInfo connectionInfo) {
       }
  -
  -    public TransactionContext getTransactionContext() {
  -        return defaultTransactionContext;
  -    }
  -
   
   }
  
  
  
  1.4       +10 -6     incubator-geronimo/modules/connector/src/test/org/apache/geronimo/connector/outbound/TransactionEnlistingInterceptorTest.java
  
  Index: TransactionEnlistingInterceptorTest.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/connector/src/test/org/apache/geronimo/connector/outbound/TransactionEnlistingInterceptorTest.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- TransactionEnlistingInterceptorTest.java	10 Mar 2004 09:58:34 -0000	1.3
  +++ TransactionEnlistingInterceptorTest.java	6 Apr 2004 00:21:21 -0000	1.4
  @@ -18,12 +18,14 @@
   package org.apache.geronimo.connector.outbound;
   
   import javax.resource.ResourceException;
  -import javax.transaction.Transaction;
   import javax.transaction.TransactionManager;
   import javax.transaction.xa.XAException;
   import javax.transaction.xa.XAResource;
   import javax.transaction.xa.Xid;
   
  +import org.apache.geronimo.transaction.ContainerTransactionContext;
  +import org.apache.geronimo.transaction.TransactionContext;
  +import org.apache.geronimo.transaction.UnspecifiedTransactionContext;
   import org.apache.geronimo.transaction.manager.TransactionManagerImpl;
   
   /**
  @@ -56,7 +58,8 @@
       }
   
       public void testNoTransaction() throws Exception {
  -        ConnectionInfo connectionInfo = makeConnectionInfo(null);
  +        ConnectionInfo connectionInfo = makeConnectionInfo();
  +        TransactionContext.setContext(new UnspecifiedTransactionContext());
           transactionEnlistingInterceptor.getConnection(connectionInfo);
           assertTrue("Expected not started", !started);
           assertTrue("Expected not ended", !ended);
  @@ -67,9 +70,10 @@
   
       public void testTransaction() throws Exception {
           TransactionManager transactionManager = new TransactionManagerImpl();
  -        transactionManager.begin();
  -        Transaction transaction = transactionManager.getTransaction();
  -        ConnectionInfo connectionInfo = makeConnectionInfo(transaction);
  +        ContainerTransactionContext transactionContext = new ContainerTransactionContext(transactionManager);
  +        TransactionContext.setContext(transactionContext);
  +        transactionContext.begin();
  +        ConnectionInfo connectionInfo = makeConnectionInfo();
           transactionEnlistingInterceptor.getConnection(connectionInfo);
           assertTrue("Expected started", started);
           assertTrue("Expected not ended", !ended);
  
  
  
  1.12      +44 -66    incubator-geronimo/modules/jetty/src/java/org/apache/geronimo/jetty/JettyWebApplicationContext.java
  
  Index: JettyWebApplicationContext.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/jetty/src/java/org/apache/geronimo/jetty/JettyWebApplicationContext.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- JettyWebApplicationContext.java	10 Mar 2004 09:58:55 -0000	1.11
  +++ JettyWebApplicationContext.java	6 Apr 2004 00:21:21 -0000	1.12
  @@ -23,34 +23,28 @@
   import java.net.URL;
   import java.util.Arrays;
   import java.util.Collections;
  -import java.util.Map;
   import java.util.Set;
  -import java.util.WeakHashMap;
  +
   import javax.resource.ResourceException;
   import javax.security.jacc.PolicyContext;
  -import javax.transaction.RollbackException;
  -import javax.transaction.SystemException;
  -import javax.transaction.Transaction;
   import javax.transaction.TransactionManager;
   
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
  -import org.apache.geronimo.connector.outbound.connectiontracking.TrackedConnectionAssociator;
   import org.apache.geronimo.connector.outbound.connectiontracking.defaultimpl.DefaultComponentContext;
  -import org.apache.geronimo.connector.outbound.connectiontracking.defaultimpl.DefaultTransactionContext;
  -import org.apache.geronimo.gbean.GAttributeInfo;
   import org.apache.geronimo.gbean.GBean;
   import org.apache.geronimo.gbean.GBeanContext;
   import org.apache.geronimo.gbean.GBeanInfo;
   import org.apache.geronimo.gbean.GBeanInfoFactory;
   import org.apache.geronimo.gbean.GConstructorInfo;
  -import org.apache.geronimo.gbean.GReferenceInfo;
   import org.apache.geronimo.gbean.WaitingException;
   import org.apache.geronimo.kernel.config.ConfigurationParent;
   import org.apache.geronimo.naming.java.ReadOnlyContext;
   import org.apache.geronimo.naming.java.RootContext;
  +import org.apache.geronimo.transaction.TrackedConnectionAssociator;
   import org.apache.geronimo.transaction.TransactionContext;
  -import org.apache.geronimo.transaction.InstanceContext;
  +import org.apache.geronimo.transaction.UnspecifiedTransactionContext;
  +import org.apache.geronimo.transaction.UserTransactionImpl;
   import org.mortbay.http.HttpException;
   import org.mortbay.http.HttpRequest;
   import org.mortbay.http.HttpResponse;
  @@ -72,14 +66,12 @@
       private final String policyContextID;
       private final TransactionManager txManager;
       private final TrackedConnectionAssociator associator;
  -
  -    // @todo this should be replaced by global tx context handling.
  -    private final Map transactionContextMap = Collections.synchronizedMap(new WeakHashMap());
  +    private final UserTransactionImpl userTransaction;
   
       // @todo get these from DD
       private final Set unshareableResources = Collections.EMPTY_SET;
   
  -    private boolean contextPriorityClassLoader=false;
  +    private boolean contextPriorityClassLoader = false;
   
       public JettyWebApplicationContext(
               ConfigurationParent config,
  @@ -88,7 +80,8 @@
               ReadOnlyContext compContext,
               String policyContextID,
               TransactionManager txManager,
  -            TrackedConnectionAssociator associator) {
  +            TrackedConnectionAssociator associator,
  +            UserTransactionImpl userTransaction) {
           super();
           this.config = config;
           this.uri = uri;
  @@ -97,12 +90,14 @@
           this.policyContextID = policyContextID;
           this.txManager = txManager;
           this.associator = associator;
  +        this.userTransaction = userTransaction;
  +        userTransaction.setUp(txManager, associator);
       }
   
   
       /** getContextPriorityClassLoader.
        * @return True if this context should give web application class in preference over the containers
  -      * classes, as per the servlet specification recommendations.
  +     * classes, as per the servlet specification recommendations.
        */
       public boolean getContextPriorityClassLoader() {
           return contextPriorityClassLoader;
  @@ -113,7 +108,7 @@
        * classes, as per the servlet specification recommendations.
        */
       public void setContextPriorityClassLoader(boolean b) {
  -        contextPriorityClassLoader= b;
  +        contextPriorityClassLoader = b;
       }
   
       /**
  @@ -121,11 +116,9 @@
        * determine if the context needs to create its own classloader.
        */
       protected void initClassLoader(boolean forceContextLoader)
  -        throws MalformedURLException, IOException
  -    {
  +            throws MalformedURLException, IOException {
           setClassLoaderJava2Compliant(!contextPriorityClassLoader);
  -        if (!contextPriorityClassLoader)
  -        {
  +        if (!contextPriorityClassLoader) {
               // TODO - once geronimo is correctly setting up the classpath, this should be uncommented.
               // At the moment, the g classloader does not appear to know about the WEB-INF classes and lib.
               // setClassLoader(Thread.currentThread().getContextClassLoader());
  @@ -133,7 +126,7 @@
           super.initClassLoader(forceContextLoader);
   
           if (log.isDebugEnabled())
  -            log.debug("classloader for "+getContextPath()+": "+getClassLoader());
  +            log.debug("classloader for " + getContextPath() + ": " + getClassLoader());
       }
   
       public void handle(String pathInContext,
  @@ -146,9 +139,8 @@
           // save previous state
           ReadOnlyContext oldComponentContext = RootContext.getComponentContext();
           String oldPolicyContextID = PolicyContext.getContextID();
  -        Set oldUnshareableResources = null;
  -        InstanceContext oldInstanceContext = null;
  -        TransactionContext oldTransactionContext = null;
  +
  +        TrackedConnectionAssociator.ConnectorContextInfo oldConnectorContext = null;
   
           try {
               // set up java:comp JNDI Context
  @@ -157,41 +149,20 @@
               // set up Security Context
               PolicyContext.setContextID(policyContextID);
   
  -            // set up Transaction Context
  -            if (txManager != null) {
  -                TransactionContext newTxContext;
  -
  -                // @todo this will not clean up properly if an exception occurs - we need to fix this API
  -                try {
  -                    Transaction tx = txManager.getTransaction();
  -                    if (tx == null) {
  -                        newTxContext = new DefaultTransactionContext(null);
  -                    } else {
  -                        newTxContext = (TransactionContext) transactionContextMap.get(tx);
  -                        if (newTxContext == null) {
  -                            newTxContext = new DefaultTransactionContext(tx);
  -                            transactionContextMap.put(tx, newTxContext);
  -                        }
  -                    }
  -                    oldUnshareableResources = associator.setUnshareableResources(unshareableResources);
  -                    oldInstanceContext = associator.enter(new DefaultComponentContext());
  -                    oldTransactionContext = associator.setTransactionContext(newTxContext);
  -                } catch (SystemException e) {
  -                    throw new RuntimeException(e);
  -                } catch (RollbackException e) {
  -                    throw new RuntimeException(e);
  -                } catch (ResourceException e) {
  -                    throw new RuntimeException(e);
  -                }
  +            if (TransactionContext.getContext() == null) {
  +                TransactionContext.setContext(new UnspecifiedTransactionContext());
  +            }
  +            try {
  +                oldConnectorContext = associator.enter(new DefaultComponentContext(), unshareableResources);
  +            } catch (ResourceException e) {
  +                throw new RuntimeException(e);
               }
   
               super.handle(pathInContext, pathParams, httpRequest, httpResponse);
           } finally {
               try {
                   if (txManager != null) {
  -                    associator.exit(oldInstanceContext, unshareableResources);
  -                    associator.resetTransactionContext(oldTransactionContext);
  -                    associator.setUnshareableResources(oldUnshareableResources);
  +                    associator.exit(oldConnectorContext);
                   }
               } catch (ResourceException e) {
                   throw new RuntimeException(e);
  @@ -211,6 +182,9 @@
           } else {
               setWAR(new URL(config.getBaseURL(), uri.toString()).toString());
           }
  +        if (userTransaction != null) {
  +            userTransaction.setOnline(true);
  +        }
           container.addContext(this);
           super.start();
       }
  @@ -225,6 +199,9 @@
               }
           }
           container.removeContext(this);
  +        if (userTransaction != null) {
  +            userTransaction.setOnline(false);
  +        }
       }
   
       public void doFail() {
  @@ -240,18 +217,19 @@
       static {
   
           GBeanInfoFactory infoFactory = new GBeanInfoFactory("Jetty WebApplication Context", JettyWebApplicationContext.class.getName());
  -        infoFactory.addAttribute(new GAttributeInfo("URI", true));
  -        infoFactory.addAttribute(new GAttributeInfo("ContextPath", true));
  -        infoFactory.addAttribute(new GAttributeInfo("ContextPriorityClassLoader", true));
  -        infoFactory.addAttribute(new GAttributeInfo("ComponentContext", true));
  -        infoFactory.addAttribute(new GAttributeInfo("PolicyContextID", true));
  -        infoFactory.addReference(new GReferenceInfo("Configuration", ConfigurationParent.class.getName()));
  -        infoFactory.addReference(new GReferenceInfo("JettyContainer", JettyContainer.class.getName()));
  -        infoFactory.addReference(new GReferenceInfo("TransactionManager", TransactionManager.class.getName()));
  -        infoFactory.addReference(new GReferenceInfo("TrackedConnectionAssociator", TrackedConnectionAssociator.class.getName()));
  +        infoFactory.addAttribute("URI", true);
  +        infoFactory.addAttribute("ContextPath", true);
  +        infoFactory.addAttribute("ContextPriorityClassLoader", true);
  +        infoFactory.addAttribute("ComponentContext", true);
  +        infoFactory.addAttribute("PolicyContextID", true);
  +        infoFactory.addAttribute("UserTransaction", true);
  +        infoFactory.addReference("Configuration", ConfigurationParent.class);
  +        infoFactory.addReference("JettyContainer", JettyContainer.class);
  +        infoFactory.addReference("TransactionManager", TransactionManager.class);
  +        infoFactory.addReference("TrackedConnectionAssociator", TrackedConnectionAssociator.class);
           infoFactory.setConstructor(new GConstructorInfo(
  -                Arrays.asList(new Object[]{"Configuration", "URI", "JettyContainer", "ComponentContext", "PolicyContextID", "TransactionManager", "TrackedConnectionAssociator"}),
  -                Arrays.asList(new Object[]{ConfigurationParent.class, URI.class, JettyContainer.class, ReadOnlyContext.class, String.class, TransactionManager.class, TrackedConnectionAssociator.class})));
  +                Arrays.asList(new Object[]{"Configuration", "URI", "JettyContainer", "ComponentContext", "PolicyContextID", "TransactionManager", "TrackedConnectionAssociator", "UserTransaction"}),
  +                Arrays.asList(new Object[]{ConfigurationParent.class, URI.class, JettyContainer.class, ReadOnlyContext.class, String.class, TransactionManager.class, TrackedConnectionAssociator.class, UserTransactionImpl.class})));
   
           GBEAN_INFO = infoFactory.getBeanInfo();
       }
  
  
  
  1.8       +30 -12    incubator-geronimo/modules/jetty/src/test/org/apache/geronimo/jetty/ApplicationTest.java
  
  Index: ApplicationTest.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/jetty/src/test/org/apache/geronimo/jetty/ApplicationTest.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- ApplicationTest.java	10 Mar 2004 09:58:56 -0000	1.7
  +++ ApplicationTest.java	6 Apr 2004 00:21:21 -0000	1.8
  @@ -17,23 +17,24 @@
   
   package org.apache.geronimo.jetty;
   
  +import java.io.BufferedReader;
  +import java.io.InputStreamReader;
   import java.net.HttpURLConnection;
  -import java.net.URL;
   import java.net.URI;
  -import java.util.HashSet;
  -import java.util.Set;
  +import java.net.URL;
   import java.util.Collections;
  -import java.io.Reader;
  -import java.io.BufferedReader;
  -import java.io.InputStreamReader;
  +import java.util.Set;
  +
   import javax.management.MBeanServer;
   import javax.management.ObjectName;
   
  +import junit.framework.TestCase;
  +import org.apache.geronimo.connector.outbound.connectiontracking.ConnectionTrackingCoordinator;
   import org.apache.geronimo.gbean.jmx.GBeanMBean;
  -import org.apache.geronimo.kernel.Kernel;
  -import org.apache.geronimo.kernel.management.State;
   import org.apache.geronimo.jetty.connector.HTTPConnector;
  -import junit.framework.TestCase;
  +import org.apache.geronimo.kernel.Kernel;
  +import org.apache.geronimo.transaction.TransactionManagerProxy;
  +import org.apache.geronimo.transaction.UserTransactionImpl;
   
   /**
    *
  @@ -49,6 +50,10 @@
       private MBeanServer mbServer;
       private GBeanMBean connector;
       private ObjectName appName;
  +    private ObjectName tmName;
  +    private ObjectName tcaName;
  +    private GBeanMBean tm;
  +    private GBeanMBean ctc;
   
       public void testApplication() throws Exception {
           URL url = Thread.currentThread().getContextClassLoader().getResource("deployables/war1");
  @@ -57,12 +62,15 @@
           app.setAttribute("ContextPath", "/test");
           app.setAttribute("ComponentContext", null);
           app.setAttribute("PolicyContextID", null);
  +        UserTransactionImpl userTransaction = new UserTransactionImpl();
  +        app.setAttribute("UserTransaction", userTransaction);
           app.setReferencePatterns("Configuration", Collections.EMPTY_SET);
           app.setReferencePatterns("JettyContainer", containerPatterns);
  -        app.setReferencePatterns("TransactionManager", Collections.EMPTY_SET);
  -        app.setReferencePatterns("TrackedConnectionAssociator", Collections.EMPTY_SET);
  +        app.setReferencePatterns("TransactionManager", Collections.singleton(tmName));
  +        app.setReferencePatterns("TrackedConnectionAssociator", Collections.singleton(tcaName));
           start(appName, app);
   
  +
           HttpURLConnection connection = (HttpURLConnection) new URL("http://localhost:5678/test/hello.txt").openConnection();
           BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
           assertEquals(HttpURLConnection.HTTP_OK, connection.getResponseCode());
  @@ -86,6 +94,9 @@
           connectorName = new ObjectName("geronimo.jetty:role=Connector");
           appName = new ObjectName("geronimo.jetty:app=test");
   
  +        tmName = new ObjectName("geronimo.test:role=TransactionManager");
  +        tcaName = new ObjectName("geronimo.test:role=ConnectionTrackingCoordinator");
  +
           kernel = new Kernel("test.kernel", "test");
           kernel.boot();
           mbServer = kernel.getMBeanServer();
  @@ -97,9 +108,16 @@
   
           start(containerName, container);
           start(connectorName, connector);
  +
  +        tm = new GBeanMBean(TransactionManagerProxy.GBEAN_INFO);
  +        start(tmName, tm);
  +        ctc = new GBeanMBean(ConnectionTrackingCoordinator.GBEAN_INFO);
  +        start(tcaName, ctc);
       }
   
       protected void tearDown() throws Exception {
  +        stop(tcaName);
  +        stop(tmName);
           stop(connectorName);
           stop(containerName);
           kernel.shutdown();