geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From djen...@apache.org
Subject svn commit: r149334 - geronimo/trunk/modules/connector/src/java/org/apache/geronimo/connector/outbound/TransactionCachingInterceptor.java
Date Tue, 01 Feb 2005 00:42:01 GMT
Author: djencks
Date: Mon Jan 31 16:41:59 2005
New Revision: 149334

URL: http://svn.apache.org/viewcvs?view=rev&rev=149334
Log:
GERONIMO-561  Don't add a connection to an inactive transaction context

Modified:
    geronimo/trunk/modules/connector/src/java/org/apache/geronimo/connector/outbound/TransactionCachingInterceptor.java

Modified: geronimo/trunk/modules/connector/src/java/org/apache/geronimo/connector/outbound/TransactionCachingInterceptor.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/connector/src/java/org/apache/geronimo/connector/outbound/TransactionCachingInterceptor.java?view=diff&r1=149333&r2=149334
==============================================================================
--- geronimo/trunk/modules/connector/src/java/org/apache/geronimo/connector/outbound/TransactionCachingInterceptor.java
(original)
+++ geronimo/trunk/modules/connector/src/java/org/apache/geronimo/connector/outbound/TransactionCachingInterceptor.java
Mon Jan 31 16:41:59 2005
@@ -32,18 +32,18 @@
  * TransactionCachingInterceptor.java
  * TODO: This implementation does not take account of unshareable resources
  * TODO: This implementation does not take account of application security
- *  where several connections with different security info are obtained.
+ * where several connections with different security info are obtained.
  * TODO: This implementation does not take account of container managed security where,
- *  within one transaction, a security domain boundary is crossed
+ * within one transaction, a security domain boundary is crossed
  * and connections are obtained with two (or more) different subjects.
- *
+ * <p/>
  * I suggest a state pattern, with the state set in a threadlocal upon entering a component,
  * will be a usable implementation.
- *
+ * <p/>
  * The afterCompletion method will need to move to an interface,  and that interface include
the
  * security info to distinguish connections.
- *
- *
+ * <p/>
+ * <p/>
  * Created: Mon Sep 29 15:07:07 2003
  *
  * @version 1.0
@@ -60,30 +60,32 @@
 
     public void getConnection(ConnectionInfo connectionInfo) throws ResourceException {
         TransactionContext transactionContext = transactionContextManager.getContext();
-        if (transactionContext == null) {
+        //There can be an inactive transaction context when a connection is requested in
+        //Synchronization.afterCompletion().
+        if (transactionContext == null || !transactionContext.isActive()) {
             next.getConnection(connectionInfo);
         } else {
-        ManagedConnectionInfos managedConnectionInfos = (ManagedConnectionInfos) transactionContext.getManagedConnectionInfo(this);
-        if (managedConnectionInfos == null) {
-            managedConnectionInfos = new ManagedConnectionInfos();
-            transactionContext.setManagedConnectionInfo(this, managedConnectionInfos);
-        }
-        if (connectionInfo.isUnshareable()) {
-            if (!managedConnectionInfos.containsUnshared(connectionInfo.getManagedConnectionInfo()))
{
-                next.getConnection(connectionInfo);
-                managedConnectionInfos.addUnshared(connectionInfo.getManagedConnectionInfo());
+            ManagedConnectionInfos managedConnectionInfos = (ManagedConnectionInfos) transactionContext.getManagedConnectionInfo(this);
+            if (managedConnectionInfos == null) {
+                managedConnectionInfos = new ManagedConnectionInfos();
+                transactionContext.setManagedConnectionInfo(this, managedConnectionInfos);
             }
-        } else {
-            ManagedConnectionInfo managedConnectionInfo = managedConnectionInfos.getShared();
-            if (managedConnectionInfo != null) {
-                connectionInfo.setManagedConnectionInfo(managedConnectionInfo);
-                return;
+            if (connectionInfo.isUnshareable()) {
+                if (!managedConnectionInfos.containsUnshared(connectionInfo.getManagedConnectionInfo()))
{
+                    next.getConnection(connectionInfo);
+                    managedConnectionInfos.addUnshared(connectionInfo.getManagedConnectionInfo());
+                }
             } else {
-                next.getConnection(connectionInfo);
-                managedConnectionInfos.setShared(connectionInfo.getManagedConnectionInfo());
+                ManagedConnectionInfo managedConnectionInfo = managedConnectionInfos.getShared();
+                if (managedConnectionInfo != null) {
+                    connectionInfo.setManagedConnectionInfo(managedConnectionInfo);
+                    return;
+                } else {
+                    next.getConnection(connectionInfo);
+                    managedConnectionInfos.setShared(connectionInfo.getManagedConnectionInfo());
+                }
             }
         }
-        }
     }
 
     public void returnConnection(ConnectionInfo connectionInfo, ConnectionReturnAction connectionReturnAction)
{
@@ -97,6 +99,10 @@
         if (transactionContext != null && transactionContext.isActive()) {
             return;
         }
+        internalReturn(connectionInfo, connectionReturnAction);
+    }
+
+    private void internalReturn(ConnectionInfo connectionInfo, ConnectionReturnAction connectionReturnAction)
{
         if (connectionInfo.getManagedConnectionInfo().hasConnectionHandles()) {
             return;
         }
@@ -105,7 +111,7 @@
     }
 
     public void afterCompletion(Object stuff) {
-        ManagedConnectionInfos managedConnectionInfos = (ManagedConnectionInfos)stuff;
+        ManagedConnectionInfos managedConnectionInfos = (ManagedConnectionInfos) stuff;
         ManagedConnectionInfo sharedMCI = managedConnectionInfos.getShared();
         if (sharedMCI != null) {
             returnHandle(sharedMCI);
@@ -119,7 +125,7 @@
     private void returnHandle(ManagedConnectionInfo managedConnectionInfo) {
         ConnectionInfo connectionInfo = new ConnectionInfo();
         connectionInfo.setManagedConnectionInfo(managedConnectionInfo);
-        returnConnection(connectionInfo, ConnectionReturnAction.RETURN_HANDLE);
+        internalReturn(connectionInfo, ConnectionReturnAction.RETURN_HANDLE);
     }
 
     static class ManagedConnectionInfos {



Mime
View raw message