--- /home/mkishore/ConnectionImple-orig.java 2008-12-09 19:22:42.000000000 -0500 +++ src/com/arjuna/ats/internal/jdbc/ConnectionImple.java 2009-05-01 16:36:42.000000000 -0400 @@ -54,6 +54,7 @@ import java.sql.*; import javax.transaction.RollbackException; import java.sql.SQLException; +import java.lang.reflect.Method; /** * A transactional JDBC 2.0 connection. This wraps the real connection and @@ -331,10 +332,10 @@ * connection is enlisted with! */ - if (tx != null) - { - if (_recoveryConnection.validTransaction(tx)) + // modified by mohan - to ensure we close the mysql XA connection properly + if (tx != null && _recoveryConnection.validTransaction(tx)) { + try { XAResource xares = _recoveryConnection.getResource(); if (!tx.delistResource(xares, XAResource.TMSUCCESS)) @@ -357,16 +358,17 @@ _theConnection, _recoveryConnection)); _theConnection = null; } + } catch (Exception e) { + // mohan - put everything in a try-catch, and ensure we close the xaconn + doCloseConnectionAndRecoveryConnection(); + throw e; } } else { - _recoveryConnection.closeCloseCurrentConnection(); - if (_theConnection != null && !_theConnection.isClosed()) - _theConnection.close(); - - _theConnection = null; + doCloseConnectionAndRecoveryConnection(); } + // end - modifications by mohan // what about connections without xaCon? } @@ -388,6 +390,15 @@ } } + // added by mohan - to ensure we close the mysql XA connection properly + private void doCloseConnectionAndRecoveryConnection() throws SQLException { + _recoveryConnection.closeCloseCurrentConnection(); + if (_theConnection != null && !_theConnection.isClosed()) + _theConnection.close(); + + _theConnection = null; + } + public boolean isClosed() throws SQLException { /* @@ -952,4 +963,66 @@ } } + // added by mohan - to ensure we are able to access the underlying OracleConnection - if needed + public T unwrap(java.lang.Class iface) throws java.sql.SQLException { + try { + if (iface != null) { + if (iface.isInstance(this)) { + return (T) this; + } else { + Connection conn = getConnection(); + if (conn != null) { + if (iface.isInstance(conn)) { + return (T) conn; + } else if (UNWRAP != null) { + return (T) UNWRAP.invoke(conn, iface); + } + } + } + } + return null; + } catch (Exception e) { + throw new SQLException("Error evaluating unwrap: " + iface.getName()); + } + } + + // added by mohan - to ensure we are able to access the underlying OracleConnection - if needed + public boolean isWrapperFor(java.lang.Class iface) throws java.sql.SQLException { + try { + if (iface != null) { + if (iface.isInstance(this)) { + return true; + } else { + Connection conn = getConnection(); + if (conn != null) { + if (iface.isInstance(conn)) { + return true; + } else if (IS_WRAPPER_FOR != null) { + return (Boolean) IS_WRAPPER_FOR.invoke(conn, iface); + } + } + } + } + return false; + } catch (Exception e) { + throw new SQLException("Error evaluating isWrapperFor: " + iface.getName()); + } + } + + // added by mohan - to ensure we are able to access the underlying OracleConnection - if needed + private static Method IS_WRAPPER_FOR, UNWRAP; + static { + try { + IS_WRAPPER_FOR = Connection.class.getMethod("isWrapperFor", Class.class); + } catch (NoSuchMethodException e) { + // ignore + } + try { + UNWRAP = Connection.class.getMethod("unwrap", Class.class); + } catch (NoSuchMethodException e) { + // ignore + } + } + + }