diff --git a/ArjunaJTA/jdbc/classes/com/arjuna/ats/internal/jdbc/ConnectionImple.java b/ArjunaJTA/jdbc/classes/com/arjuna/ats/internal/jdbc/ConnectionImple.java index 8ec8b9cf67..8a5ab031bb 100644 --- a/ArjunaJTA/jdbc/classes/com/arjuna/ats/internal/jdbc/ConnectionImple.java +++ b/ArjunaJTA/jdbc/classes/com/arjuna/ats/internal/jdbc/ConnectionImple.java @@ -386,7 +386,7 @@ public void close() throws SQLException void closeImpl() throws SQLException { try { ConnectionManager.remove(this); - if (!_theConnection.isClosed()) { + if (_theConnection != null && !_theConnection.isClosed()) { _theConnection.close(); } if (_transactionalDriverXAConnectionConnection != null) { @@ -405,7 +405,9 @@ public boolean isClosed() throws SQLException * bound it to a different transaction. */ - if (_theConnection == null) + if (_transactionalDriverXAConnectionConnection == null) + return true; // closeImpl was explicitly called + else if (_theConnection == null) return false; // not opened yet. // TODO why don't we return true here else return _theConnection.isClosed(); diff --git a/ArjunaJTA/jdbc/tests/classes/com/hp/mwtests/ts/jdbc/basic/JDBC2Test.java b/ArjunaJTA/jdbc/tests/classes/com/hp/mwtests/ts/jdbc/basic/JDBC2Test.java index 2273a8a6c1..3b5a6902fa 100644 --- a/ArjunaJTA/jdbc/tests/classes/com/hp/mwtests/ts/jdbc/basic/JDBC2Test.java +++ b/ArjunaJTA/jdbc/tests/classes/com/hp/mwtests/ts/jdbc/basic/JDBC2Test.java @@ -32,6 +32,7 @@ package com.hp.mwtests.ts.jdbc.basic; import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import java.sql.Connection; @@ -268,7 +269,7 @@ public void test() throws Exception tx.begin(); - assertFalse(conn.isClosed()); + assertTrue(conn.isClosed()); if (!reuseconn) { @@ -328,4 +329,30 @@ public void test() throws Exception { } } + + @Test + public void testCloseUnused() throws Exception { + assertFalse(conn.isClosed()); + + conn.close(); + + assertTrue(conn.isClosed()); + } + + @Test + public void testCloseUsed() throws Exception { + javax.transaction.UserTransaction tx = com.arjuna.ats.jta.UserTransaction.userTransaction(); + + assertFalse(conn.isClosed()); + + tx.begin(); + conn.createStatement().close(); + + assertFalse(conn.isClosed()); + + conn.close(); + tx.commit(); + + assertTrue(conn.isClosed()); + } }