Skip to content

Commit

Permalink
Do not null the actual connection when delaying close. That means whe…
Browse files Browse the repository at this point in the history
…n getConnection is called again after .close for this thread it allow the connection to be reused and finally closed by the Sync.
  • Loading branch information
tomjenkinson committed Jun 15, 2016
1 parent c7627e0 commit 46a955c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -369,9 +369,7 @@ public void close() throws SQLException
tx.registerSynchronization(new ConnectionSynchronization(null, _transactionalDriverXAConnectionConnection));
if (delayClose)
{
tx.registerSynchronization(new ConnectionSynchronization(_theConnection, null));

_theConnection = null;
tx.registerSynchronization(new ConnectionSynchronization(this, null));
}
}
else
Expand All @@ -382,11 +380,7 @@ public void close() throws SQLException

if (!delayClose) // close now
{
if (!_theConnection.isClosed()) {
_theConnection.close();
}

_theConnection = null;
closeImpl();
}

// what about connections without xaCon?
Expand All @@ -407,6 +401,16 @@ public void close() throws SQLException
}
}

void closeImpl() throws SQLException {
try {
if (!_theConnection.isClosed()) {
_theConnection.close();
}
} finally {
_theConnection = null;
}
}

public boolean isClosed() throws SQLException
{
/*
Expand Down Expand Up @@ -860,16 +864,11 @@ final void reset()
{
try
{
if (_theConnection != null)
_theConnection.close();
closeImpl();
}
catch (Exception ex)
{
}
finally
{
_theConnection = null;
}
}

final java.sql.Connection getConnection() throws SQLException
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
public class ConnectionSynchronization implements Synchronization
{

public ConnectionSynchronization (Connection conn, TransactionalDriverXAConnection rxac)
public ConnectionSynchronization (ConnectionImple conn, TransactionalDriverXAConnection rxac)
{
_theConnection = conn;
_recoveryConnection = rxac;
Expand All @@ -57,8 +57,8 @@ public void afterCompletion(int status)
{
try
{
if (_theConnection != null && !_theConnection.isClosed()) {
_theConnection.close();
if (_theConnection != null) {
_theConnection.closeImpl();
}
}
catch (Exception ex)
Expand All @@ -79,7 +79,7 @@ public void beforeCompletion()
{
}

private Connection _theConnection = null;
private ConnectionImple _theConnection = null;
private TransactionalDriverXAConnection _recoveryConnection;
}

0 comments on commit 46a955c

Please sign in to comment.