commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pste...@apache.org
Subject svn commit: r1648727 - in /commons/proper/dbcp/trunk/src: changes/changes.xml main/java/org/apache/commons/dbcp2/managed/TransactionContext.java test/java/org/apache/commons/dbcp2/managed/TestTransactionContext.java
Date Wed, 31 Dec 2014 16:01:42 GMT
Author: psteitz
Date: Wed Dec 31 16:01:41 2014
New Revision: 1648727

URL: http://svn.apache.org/r1648727
Log:
Made failed Connection enlistment in XA Transaction result in SQLException (as advertised
in javadoc) in TransactionContext#setSharedConnection.

JIRA: DBCP-428
Reported (with patch) by Vladimir Konkov 


Added:
    commons/proper/dbcp/trunk/src/test/java/org/apache/commons/dbcp2/managed/TestTransactionContext.java
  (with props)
Modified:
    commons/proper/dbcp/trunk/src/changes/changes.xml
    commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/managed/TransactionContext.java

Modified: commons/proper/dbcp/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/dbcp/trunk/src/changes/changes.xml?rev=1648727&r1=1648726&r2=1648727&view=diff
==============================================================================
--- commons/proper/dbcp/trunk/src/changes/changes.xml (original)
+++ commons/proper/dbcp/trunk/src/changes/changes.xml Wed Dec 31 16:01:41 2014
@@ -79,6 +79,9 @@ The <action> type attribute can be add,u
       <action dev="psteitz" type="add" issue="DBCP-426" due-to="Kasper Sørensen">
         Added invalidateConnection method to BasicDataSource.
       </action>
+      <action issue="DBCP-428" dev="psteitz" type="fix" due-to="Vladimir Konkov">
+        Unsuccessful Connection enlistment in XA Transaction ignored by TransactionContext.
+      </action>
     </release>
     <release version="2.0.1" date="24 May 2014" description="This is a bug fix release.">
       <action dev="markt" type="fix">

Modified: commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/managed/TransactionContext.java
URL: http://svn.apache.org/viewvc/commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/managed/TransactionContext.java?rev=1648727&r1=1648726&r2=1648727&view=diff
==============================================================================
--- commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/managed/TransactionContext.java
(original)
+++ commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/managed/TransactionContext.java
Wed Dec 31 16:01:41 2014
@@ -90,7 +90,9 @@ public class TransactionContext {
         Transaction transaction = getTransaction();
         try {
             XAResource xaResource = transactionRegistry.getXAResource(sharedConnection);
-            transaction.enlistResource(xaResource);
+            if ( !transaction.enlistResource(xaResource) ) {
+                throw new SQLException("Unable to enlist connection in transaction: enlistResource
returns 'false'.");
+            }
         } catch (RollbackException e) {
             // transaction was rolled back... proceed as if there never was a transaction
         } catch (SystemException e) {

Added: commons/proper/dbcp/trunk/src/test/java/org/apache/commons/dbcp2/managed/TestTransactionContext.java
URL: http://svn.apache.org/viewvc/commons/proper/dbcp/trunk/src/test/java/org/apache/commons/dbcp2/managed/TestTransactionContext.java?rev=1648727&view=auto
==============================================================================
--- commons/proper/dbcp/trunk/src/test/java/org/apache/commons/dbcp2/managed/TestTransactionContext.java
(added)
+++ commons/proper/dbcp/trunk/src/test/java/org/apache/commons/dbcp2/managed/TestTransactionContext.java
Wed Dec 31 16:01:41 2014
@@ -0,0 +1,68 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.commons.dbcp2.managed;
+
+import java.sql.SQLException;
+import javax.transaction.xa.XAResource;
+
+import org.junit.Test;
+import org.apache.geronimo.transaction.manager.TransactionManagerImpl;
+import org.apache.geronimo.transaction.manager.TransactionImpl;
+
+/**
+ * TestSuite for TransactionContext  
+ */
+public class TestTransactionContext {
+    
+    /**
+     * JIRA: DBCP-428
+     */
+    @Test(expected=SQLException.class)
+    public void testSetSharedConnectionEnlistFailure() throws Exception {
+        final BasicManagedDataSource basicManagedDataSource = new BasicManagedDataSource();
+        basicManagedDataSource.setTransactionManager(new TransactionManagerImpl());
+        basicManagedDataSource.setDriverClassName("org.apache.commons.dbcp2.TesterDriver");
+        basicManagedDataSource.setUrl("jdbc:apache:commons:testdriver");
+        basicManagedDataSource.setUsername("username");
+        basicManagedDataSource.setPassword("password");
+        basicManagedDataSource.setMaxIdle(1);
+        final ManagedConnection<?> conn = (ManagedConnection<?>) basicManagedDataSource.getConnection();
+        final UncooperativeTransaction transaction = new UncooperativeTransaction(); 
+        final TransactionContext transactionContext =
+                new TransactionContext(basicManagedDataSource.getTransactionRegistry(), transaction);
+        transactionContext.setSharedConnection(conn);
+    }
+    
+    /**
+     * Transaction that always fails enlistResource.
+     */
+    private class UncooperativeTransaction extends TransactionImpl {
+        public UncooperativeTransaction() {
+            super(null, null);
+        }
+        @Override
+        public synchronized boolean enlistResource(XAResource xaRes) {
+            return false;
+        }
+    }
+    
+    
+    
+
+}
+

Propchange: commons/proper/dbcp/trunk/src/test/java/org/apache/commons/dbcp2/managed/TestTransactionContext.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message