try
{
// DB2 seems to close connection if SQL Error encountered, but doesn't notify
if (m_xaConnection == null || m_sqlConnection.isClosed()) // closed connection
{
throw new CommException("RDBMS connection is already closed");
}
}
catch (SQLException e)
{
throw new CommException("Unexpected RDBMS connection error", e);
}
if (m_handleSet.isEmpty() && // no active handles or XA transactions, safe to test
(m_resource == null || !m_resource.isBusy()))
{
Statement stmt = null;
try
{
if (m_factory.isAutoCommitRollbackRequired() || !m_sqlConnection.getAutoCommit())
{
m_sqlConnection.rollback(); // roll back any local transactions
}
if (m_factory.getTestSQL() != null) // execute test SQL if provided
{
m_sqlConnection.setAutoCommit(true);
stmt = m_sqlConnection.createStatement();
stmt.execute(m_factory.getTestSQL());
stmt.close();
}
}
catch (SQLException e)
{
if (stmt != null)
{
try
{
stmt.close();
}
catch (SQLException f)
{
// ignore since closing connection
}
}
try
{
destroy();
}
catch (ResourceException f)
{
// ignore since looping around
}
throw new CommException("Connection test failed", e);
}
}
return new SQLConnection(); // the empty handle will be told its managed connection
}