Return-Path: X-Original-To: apmail-commons-commits-archive@minotaur.apache.org Delivered-To: apmail-commons-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 777B410EBB for ; Wed, 31 Dec 2014 16:01:48 +0000 (UTC) Received: (qmail 55125 invoked by uid 500); 31 Dec 2014 16:01:48 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 55064 invoked by uid 500); 31 Dec 2014 16:01:48 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 55054 invoked by uid 99); 31 Dec 2014 16:01:48 -0000 Received: from eris.apache.org (HELO hades.apache.org) (140.211.11.105) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 31 Dec 2014 16:01:48 +0000 Received: from hades.apache.org (localhost [127.0.0.1]) by hades.apache.org (ASF Mail Server at hades.apache.org) with ESMTP id 9646EAC08CB; Wed, 31 Dec 2014 16:01:46 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 -0000 To: commits@commons.apache.org From: psteitz@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20141231160147.9646EAC08CB@hades.apache.org> 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 type attribute can be add,u Added invalidateConnection method to BasicDataSource. + + Unsuccessful Connection enlistment in XA Transaction ignored by TransactionContext. + 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