--- D:/workspace36/JBossTS 4.11.0/src-orig/com/arjuna/ats/internal/jdbc/ConnectionImple.java Tue Mar 30 15:14:04 2010 +++ D:/workspace36/JBossTS 4.11.0/src/com/arjuna/ats/internal/jdbc/ConnectionImple.java Tue Oct 12 09:51:25 2010 @@ -332,82 +332,45 @@ * connection is enlisted with! */ - boolean delayClose = false; - if (tx != null) { if (_recoveryConnection.validTransaction(tx)) { XAResource xares = _recoveryConnection.getResource(); + try + { if (!tx.delistResource(xares, XAResource.TMSUCCESS)) throw new SQLException( jdbcLogger.loggerI18N .getString("com.arjuna.ats.internal.jdbc.delisterror")); - - getModifier(); - - if (_theModifier == null) - { - if (jdbcLogger.loggerI18N.isInfoEnabled()) - { - jdbcLogger.loggerI18N - .info( - "com.arjuna.ats.internal.jdbc.closingconnectionnull", - new Object[] - { _theConnection }); - } - - // no indication about connections, so assume close immediately - - if (_theConnection != null && !_theConnection.isClosed()) - _theConnection.close(); - - _theConnection = null; - - return; } - else - { - if (((ConnectionModifier) _theModifier).supportsMultipleConnections()) + finally { + getModifier(); + /* - * We can't close the connection until the transaction has - * terminated, so register a Synchronization here. + * Always close the connection after transaction termination, + * except when we know for sure that the JDBC driver does not support + * multiple connections in a single transaction. */ - - if (jdbcLogger.loggerI18N.isWarnEnabled()) - { - jdbcLogger.loggerI18N - .warn( - "com.arjuna.ats.internal.jdbc.closingconnection", - new Object[] - { _theConnection }); - } - - delayClose = true; - } - } - - if (delayClose) + if(_theModifier instanceof ConnectionModifier && !((ConnectionModifier) _theModifier).supportsMultipleConnections()) + closeConnectionImmediately(); + else { tx.registerSynchronization(new ConnectionSynchronization(_theConnection, _recoveryConnection)); - _theConnection = null; } } + } else + { + closeConnectionImmediately(); throw new SQLException(jdbcLogger.loggerI18N.getString("com.arjuna.ats.internal.jdbc.closeerrorinvalidtx") + tx); } - - if (!delayClose) // close now - { - _recoveryConnection.closeCloseCurrentConnection(); - if (_theConnection != null && !_theConnection.isClosed()) - _theConnection.close(); - - _theConnection = null; } + else + closeConnectionImmediately(); // what about connections without xaCon? } @@ -427,6 +390,25 @@ sqlException.initCause(e1); throw sqlException; } + } + + /** + * Closes both the physical connection and the recovery XA connection. + * + * @throws SQLException in case of errors + */ + private void closeConnectionImmediately() throws SQLException + { + try + { + if (_theConnection != null && !_theConnection.isClosed()) + _theConnection.close(); + } + finally + { + _recoveryConnection.closeCloseCurrentConnection(); + _theConnection = null; + } } public boolean isClosed() throws SQLException