commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r1563895 - in /commons/proper/dbcp/branches/DBCP_1_5_x_BRANCH/src: changes/ main/java/org/apache/commons/dbcp/managed/ test/java/org/apache/commons/dbcp/managed/
Date Mon, 03 Feb 2014 13:50:41 GMT
Author: markt
Date: Mon Feb  3 13:50:41 2014
New Revision: 1563895

URL: http://svn.apache.org/r1563895
Log:
Fix DBCP-355.
Ensure that the XAConnection is closed when the associated Connection is closed.
Based on a patch by Florent Guillaume.
        

Added:
    commons/proper/dbcp/branches/DBCP_1_5_x_BRANCH/src/test/java/org/apache/commons/dbcp/managed/TestDataSourceXAConnectionFactory.java
      - copied, changed from r1563892, commons/proper/dbcp/trunk/src/test/java/org/apache/commons/dbcp2/managed/TestDataSourceXAConnectionFactory.java
    commons/proper/dbcp/branches/DBCP_1_5_x_BRANCH/src/test/java/org/apache/commons/dbcp/managed/TesterBasicXAConnection.java
      - copied, changed from r1563892, commons/proper/dbcp/trunk/src/test/java/org/apache/commons/dbcp2/managed/TesterBasicXAConnection.java
Modified:
    commons/proper/dbcp/branches/DBCP_1_5_x_BRANCH/src/changes/changes.xml
    commons/proper/dbcp/branches/DBCP_1_5_x_BRANCH/src/main/java/org/apache/commons/dbcp/managed/DataSourceXAConnectionFactory.java

Modified: commons/proper/dbcp/branches/DBCP_1_5_x_BRANCH/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/dbcp/branches/DBCP_1_5_x_BRANCH/src/changes/changes.xml?rev=1563895&r1=1563894&r2=1563895&view=diff
==============================================================================
--- commons/proper/dbcp/branches/DBCP_1_5_x_BRANCH/src/changes/changes.xml (original)
+++ commons/proper/dbcp/branches/DBCP_1_5_x_BRANCH/src/changes/changes.xml Mon Feb  3 13:50:41
2014
@@ -87,6 +87,10 @@ The <action> type attribute can be add,u
         LocalXAConnectionFactory does not properly check if Xid is equal to
         currentXid when resuming which may result in an XAException.
       </action>
+      <action dev="markt" issue="DBCP-355" type="fix" due-to="Florent Guillaume">
+        Ensure that the XAConnection is closed when the associated Connection is
+        closed.
+      </action>
     </release>
     <release version="1.4.1" date="TBD" description="TBD">
       <action dev="psteitz" issue="DBCP-367" type="fix" due-to="Ken Tatsushita">

Modified: commons/proper/dbcp/branches/DBCP_1_5_x_BRANCH/src/main/java/org/apache/commons/dbcp/managed/DataSourceXAConnectionFactory.java
URL: http://svn.apache.org/viewvc/commons/proper/dbcp/branches/DBCP_1_5_x_BRANCH/src/main/java/org/apache/commons/dbcp/managed/DataSourceXAConnectionFactory.java?rev=1563895&r1=1563894&r2=1563895&view=diff
==============================================================================
--- commons/proper/dbcp/branches/DBCP_1_5_x_BRANCH/src/main/java/org/apache/commons/dbcp/managed/DataSourceXAConnectionFactory.java
(original)
+++ commons/proper/dbcp/branches/DBCP_1_5_x_BRANCH/src/main/java/org/apache/commons/dbcp/managed/DataSourceXAConnectionFactory.java
Mon Feb  3 13:50:41 2014
@@ -17,10 +17,14 @@
  */
 package org.apache.commons.dbcp.managed;
 
+import javax.sql.ConnectionEvent;
+import javax.sql.ConnectionEventListener;
+import javax.sql.PooledConnection;
 import javax.sql.XAConnection;
 import javax.sql.XADataSource;
 import javax.transaction.TransactionManager;
 import javax.transaction.xa.XAResource;
+
 import java.sql.Connection;
 import java.sql.SQLException;
 
@@ -110,6 +114,29 @@ public class DataSourceXAConnectionFacto
         // register the xa resource for the connection
         transactionRegistry.registerConnection(connection, xaResource);
 
+        // The Connection we're returning is a handle on the XAConnection.
+        // When the pool calling us closes the Connection, we need to
+        // also close the XAConnection that holds the physical connection.
+        xaConnection.addConnectionEventListener(new ConnectionEventListener() {
+
+            @Override
+            public void connectionClosed(ConnectionEvent event) {
+                PooledConnection pc = (PooledConnection) event.getSource();
+                pc.removeConnectionEventListener(this);
+                try {
+                    pc.close();
+                } catch (SQLException e) {
+                    System.err.println("Failed to close XAConnection");
+                    e.printStackTrace();
+                }
+            }
+
+            @Override
+            public void connectionErrorOccurred(ConnectionEvent event) {
+                connectionClosed(event);
+            }
+        });
+
         return connection;
     }
 }

Copied: commons/proper/dbcp/branches/DBCP_1_5_x_BRANCH/src/test/java/org/apache/commons/dbcp/managed/TestDataSourceXAConnectionFactory.java
(from r1563892, commons/proper/dbcp/trunk/src/test/java/org/apache/commons/dbcp2/managed/TestDataSourceXAConnectionFactory.java)
URL: http://svn.apache.org/viewvc/commons/proper/dbcp/branches/DBCP_1_5_x_BRANCH/src/test/java/org/apache/commons/dbcp/managed/TestDataSourceXAConnectionFactory.java?p2=commons/proper/dbcp/branches/DBCP_1_5_x_BRANCH/src/test/java/org/apache/commons/dbcp/managed/TestDataSourceXAConnectionFactory.java&p1=commons/proper/dbcp/trunk/src/test/java/org/apache/commons/dbcp2/managed/TestDataSourceXAConnectionFactory.java&r1=1563892&r2=1563895&rev=1563895&view=diff
==============================================================================
--- commons/proper/dbcp/trunk/src/test/java/org/apache/commons/dbcp2/managed/TestDataSourceXAConnectionFactory.java
(original)
+++ commons/proper/dbcp/branches/DBCP_1_5_x_BRANCH/src/test/java/org/apache/commons/dbcp/managed/TestDataSourceXAConnectionFactory.java
Mon Feb  3 13:50:41 2014
@@ -15,7 +15,7 @@
  *  See the License for the specific language governing permissions and
  *  limitations under the License.
  */
-package org.apache.commons.dbcp2.managed;
+package org.apache.commons.dbcp.managed;
 
 import java.lang.reflect.InvocationHandler;
 import java.lang.reflect.InvocationTargetException;
@@ -31,7 +31,7 @@ import javax.sql.XADataSource;
 import junit.framework.Test;
 import junit.framework.TestSuite;
 
-import org.apache.commons.dbcp2.TestBasicDataSource;
+import org.apache.commons.dbcp.TestBasicDataSource;
 import org.apache.geronimo.transaction.manager.TransactionManagerImpl;
 
 /**

Copied: commons/proper/dbcp/branches/DBCP_1_5_x_BRANCH/src/test/java/org/apache/commons/dbcp/managed/TesterBasicXAConnection.java
(from r1563892, commons/proper/dbcp/trunk/src/test/java/org/apache/commons/dbcp2/managed/TesterBasicXAConnection.java)
URL: http://svn.apache.org/viewvc/commons/proper/dbcp/branches/DBCP_1_5_x_BRANCH/src/test/java/org/apache/commons/dbcp/managed/TesterBasicXAConnection.java?p2=commons/proper/dbcp/branches/DBCP_1_5_x_BRANCH/src/test/java/org/apache/commons/dbcp/managed/TesterBasicXAConnection.java&p1=commons/proper/dbcp/trunk/src/test/java/org/apache/commons/dbcp2/managed/TesterBasicXAConnection.java&r1=1563892&r2=1563895&rev=1563895&view=diff
==============================================================================
--- commons/proper/dbcp/trunk/src/test/java/org/apache/commons/dbcp2/managed/TesterBasicXAConnection.java
(original)
+++ commons/proper/dbcp/branches/DBCP_1_5_x_BRANCH/src/test/java/org/apache/commons/dbcp/managed/TesterBasicXAConnection.java
Mon Feb  3 13:50:41 2014
@@ -15,7 +15,7 @@
  *  See the License for the specific language governing permissions and
  *  limitations under the License.
  */
-package org.apache.commons.dbcp2.managed;
+package org.apache.commons.dbcp.managed;
 
 import java.lang.reflect.InvocationHandler;
 import java.lang.reflect.InvocationTargetException;
@@ -46,7 +46,7 @@ public class TesterBasicXAConnection imp
 
     public ConnectionHandle handle;
 
-    public List<ConnectionEventListener> listeners = new LinkedList<>();
+    public List<ConnectionEventListener> listeners = new LinkedList<ConnectionEventListener>();
 
     public AtomicInteger closeCounter;
 
@@ -139,7 +139,7 @@ public class TesterBasicXAConnection imp
 
     protected void notifyConnectionClosed() {
         ConnectionEvent event = new ConnectionEvent(this);
-        List<ConnectionEventListener> copy = new ArrayList<>(
+        List<ConnectionEventListener> copy = new ArrayList<ConnectionEventListener>(
                 listeners);
         for (ConnectionEventListener listener : copy) {
             listener.connectionClosed(event);
@@ -148,7 +148,7 @@ public class TesterBasicXAConnection imp
 
     protected void notifyConnectionErrorOccurred(SQLException e) {
         ConnectionEvent event = new ConnectionEvent(this, e);
-        List<ConnectionEventListener> copy = new ArrayList<>(
+        List<ConnectionEventListener> copy = new ArrayList<ConnectionEventListener>(
                 listeners);
         for (ConnectionEventListener listener : copy) {
             listener.connectionErrorOccurred(event);



Mime
View raw message