Skip to content

Commit

Permalink
JBTM-2798 Properly response of Connection to isClosed after close
Browse files Browse the repository at this point in the history
  • Loading branch information
pms1 authored and Gytis Trikleris committed Dec 1, 2016
1 parent 842aa8e commit b9f88db
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -268,7 +269,7 @@ public void test() throws Exception

tx.begin();

assertFalse(conn.isClosed());
assertTrue(conn.isClosed());

if (!reuseconn)
{
Expand Down Expand Up @@ -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());
}
}

0 comments on commit b9f88db

Please sign in to comment.