From: Date: June 16 2006 10:58pm Subject: Connector/J commit: r5402 - in branches: branch_5_0/connector-j branch_5_0/connector-j/src/com/mysql/jdbc/integration/jboss branch_5_0/connector-j/src/com/mysql/jdbc/jdbc2/optional branch_5_0/connector-j/src/testsuite/regression branch_5_1/connector-j branch_5_1/connector-j/src/com/mysql/jdbc/integration/jboss branch_5_1/connector-j/src/com/mysql/jdbc/jdbc2/optional branch_5_1/connector-j/src/testsuite/regression List-Archive: http://lists.mysql.com/commits/7783 X-Bug: 19169 Message-Id: <200606162058.k5GKwd15020110@bk-internal.mysql.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Modified: branches/branch_5_0/connector-j/CHANGES branches/branch_5_0/connector-j/src/com/mysql/jdbc/integration/jboss/MysqlValidConnectionChecker.java branches/branch_5_0/connector-j/src/com/mysql/jdbc/jdbc2/optional/ConnectionWrapper.java branches/branch_5_0/connector-j/src/testsuite/regression/DataSourceRegressionTest.java branches/branch_5_1/connector-j/CHANGES branches/branch_5_1/connector-j/src/com/mysql/jdbc/integration/jboss/MysqlValidConnectionChecker.java branches/branch_5_1/connector-j/src/com/mysql/jdbc/jdbc2/optional/ConnectionWrapper.java branches/branch_5_1/connector-j/src/testsuite/regression/DataSourceRegressionTest.java Log: Fixed BUG#19169 - ConnectionProperties (and thus some subclasses) are not serializable, even though some J2EE containers expect them to be. Modified: branches/branch_5_0/connector-j/CHANGES =================================================================== --- branches/branch_5_0/connector-j/CHANGES 2006-06-16 20:23:21 UTC (rev 5401) +++ branches/branch_5_0/connector-j/CHANGES 2006-06-16 20:58:36 UTC (rev 5402) @@ -17,6 +17,9 @@ - Fixed BUG#19169 - ConnectionProperties (and thus some subclasses) are not serializable, even though some J2EE containers expect them to be. + + - Fixed BUG#20242 - MysqlValidConnectionChecker for JBoss doesn't + work with MySQLXADataSources. 12-23-05 - Version 5.0.0-beta Modified: branches/branch_5_0/connector-j/src/com/mysql/jdbc/integration/jboss/MysqlValidConnectionChecker.java =================================================================== --- branches/branch_5_0/connector-j/src/com/mysql/jdbc/integration/jboss/MysqlValidConnectionChecker.java 2006-06-16 20:23:21 UTC (rev 5401) +++ branches/branch_5_0/connector-j/src/com/mysql/jdbc/integration/jboss/MysqlValidConnectionChecker.java 2006-06-16 20:58:36 UTC (rev 5402) @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2005 MySQL AB + Copyright (C) 2002-2006 MySQL AB This program is free software; you can redistribute it and/or modify it under the terms of version 2 of the GNU General Public License as @@ -44,6 +44,8 @@ private static final long serialVersionUID = 3258689922776119348L; private Method pingMethod; + + private Method pingMethodWrapped; private final static Object[] NO_ARGS_OBJECT_ARRAY = new Object[0]; @@ -55,6 +57,12 @@ "com.mysql.jdbc.Connection"); pingMethod = mysqlConnection.getMethod("ping", null); + + Class mysqlConnectionWrapper = Thread.currentThread() + .getContextClassLoader().loadClass( + "com.mysql.jdbc.jdbc2.optional.ConnectionWrapper"); + + pingMethodWrapped = mysqlConnectionWrapper.getMethod("ping", null); } catch (Exception ex) { // Punt, we'll use 'SELECT 1' to do the check } @@ -66,18 +74,34 @@ * @see org.jboss.resource.adapter.jdbc.ValidConnectionChecker#isValidConnection(java.sql.Connection) */ public SQLException isValidConnection(Connection conn) { - if (pingMethod != null) { - try { - this.pingMethod.invoke(conn, NO_ARGS_OBJECT_ARRAY); - - return null; - } catch (Exception ex) { - if (ex instanceof SQLException) { - return (SQLException) ex; + if (conn instanceof com.mysql.jdbc.Connection) { + if (pingMethod != null) { + try { + this.pingMethod.invoke(conn, NO_ARGS_OBJECT_ARRAY); + + return null; + } catch (Exception ex) { + if (ex instanceof SQLException) { + return (SQLException) ex; + } + + return SQLError.createSQLException("Ping failed: " + ex.toString()); } - - return SQLError.createSQLException("Ping failed: " + ex.toString()); } + } else if (conn instanceof com.mysql.jdbc.jdbc2.optional.ConnectionWrapper) { + if (pingMethodWrapped != null) { + try { + this.pingMethodWrapped.invoke(conn, NO_ARGS_OBJECT_ARRAY); + + return null; + } catch (Exception ex) { + if (ex instanceof SQLException) { + return (SQLException) ex; + } + + return SQLError.createSQLException("Ping failed: " + ex.toString()); + } + } } // Punt and use 'SELECT 1' Modified: branches/branch_5_0/connector-j/src/com/mysql/jdbc/jdbc2/optional/ConnectionWrapper.java =================================================================== --- branches/branch_5_0/connector-j/src/com/mysql/jdbc/jdbc2/optional/ConnectionWrapper.java 2006-06-16 20:23:21 UTC (rev 5401) +++ branches/branch_5_0/connector-j/src/com/mysql/jdbc/jdbc2/optional/ConnectionWrapper.java 2006-06-16 20:58:36 UTC (rev 5402) @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2004 MySQL AB + Copyright (C) 2002-2006 MySQL AB This program is free software; you can redistribute it and/or modify it under the terms of version 2 of the GNU General Public License as @@ -831,4 +831,10 @@ protected void setInGlobalTx(boolean flag) { this.mc.setInGlobalTx(flag); } + + public void ping() throws SQLException { + if (this.mc != null) { + this.mc.ping(); + } + } } Modified: branches/branch_5_0/connector-j/src/testsuite/regression/DataSourceRegressionTest.java =================================================================== --- branches/branch_5_0/connector-j/src/testsuite/regression/DataSourceRegressionTest.java 2006-06-16 20:23:21 UTC (rev 5401) +++ branches/branch_5_0/connector-j/src/testsuite/regression/DataSourceRegressionTest.java 2006-06-16 20:58:36 UTC (rev 5402) @@ -52,9 +52,11 @@ import testsuite.simple.DataSourceTest; import com.mysql.jdbc.NonRegisteringDriver; +import com.mysql.jdbc.integration.jboss.MysqlValidConnectionChecker; import com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource; import com.mysql.jdbc.jdbc2.optional.MysqlDataSource; import com.mysql.jdbc.jdbc2.optional.MysqlDataSourceFactory; +import com.mysql.jdbc.jdbc2.optional.MysqlXADataSource; /** * Tests fixes for bugs related to datasources. @@ -313,6 +315,28 @@ assertEquals(testIntFlag, thawedDs.getBlobSendChunkSize()); } + /** + * Tests fix for BUG#20242 - MysqlValidConnectionChecker for JBoss doesn't + * work with MySQLXADataSources. + * + * @throws Exception if the test fails. + */ + public void testBug20242() throws Exception { + if (versionMeetsMinimum(5, 0)) { + try { + Class.forName("org.jboss.resource.adapter.jdbc.ValidConnectionChecker"); + } catch (Exception ex) { + return; // class not available for testing + } + + MysqlXADataSource xaDs = new MysqlXADataSource(); + xaDs.setUrl(dbUrl); + + MysqlValidConnectionChecker checker = new MysqlValidConnectionChecker(); + assertNull(checker.isValidConnection(xaDs.getXAConnection().getConnection())); + } + } + private void bindDataSource(String name, DataSource ds) throws Exception { this.ctx.bind(this.tempDir.getAbsolutePath() + name, ds); } Modified: branches/branch_5_1/connector-j/CHANGES =================================================================== --- branches/branch_5_1/connector-j/CHANGES 2006-06-16 20:23:21 UTC (rev 5401) +++ branches/branch_5_1/connector-j/CHANGES 2006-06-16 20:58:36 UTC (rev 5402) @@ -19,6 +19,9 @@ - Fixed BUG#19169 - ConnectionProperties (and thus some subclasses) are not serializable, even though some J2EE containers expect them to be. + + - Fixed BUG#20242 - MysqlValidConnectionChecker for JBoss doesn't + work with MySQLXADataSources. 12-23-05 - Version 5.0.0-beta Modified: branches/branch_5_1/connector-j/src/com/mysql/jdbc/integration/jboss/MysqlValidConnectionChecker.java =================================================================== --- branches/branch_5_1/connector-j/src/com/mysql/jdbc/integration/jboss/MysqlValidConnectionChecker.java 2006-06-16 20:23:21 UTC (rev 5401) +++ branches/branch_5_1/connector-j/src/com/mysql/jdbc/integration/jboss/MysqlValidConnectionChecker.java 2006-06-16 20:58:36 UTC (rev 5402) @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2005 MySQL AB + Copyright (C) 2002-2006 MySQL AB This program is free software; you can redistribute it and/or modify it under the terms of version 2 of the GNU General Public License as @@ -44,6 +44,8 @@ private static final long serialVersionUID = 3258689922776119348L; private Method pingMethod; + + private Method pingMethodWrapped; private final static Object[] NO_ARGS_OBJECT_ARRAY = new Object[0]; @@ -55,6 +57,12 @@ "com.mysql.jdbc.Connection"); pingMethod = mysqlConnection.getMethod("ping", null); + + Class mysqlConnectionWrapper = Thread.currentThread() + .getContextClassLoader().loadClass( + "com.mysql.jdbc.jdbc2.optional.ConnectionWrapper"); + + pingMethodWrapped = mysqlConnectionWrapper.getMethod("ping", null); } catch (Exception ex) { // Punt, we'll use 'SELECT 1' to do the check } @@ -66,18 +74,34 @@ * @see org.jboss.resource.adapter.jdbc.ValidConnectionChecker#isValidConnection(java.sql.Connection) */ public SQLException isValidConnection(Connection conn) { - if (pingMethod != null) { - try { - this.pingMethod.invoke(conn, NO_ARGS_OBJECT_ARRAY); - - return null; - } catch (Exception ex) { - if (ex instanceof SQLException) { - return (SQLException) ex; + if (conn instanceof com.mysql.jdbc.Connection) { + if (pingMethod != null) { + try { + this.pingMethod.invoke(conn, NO_ARGS_OBJECT_ARRAY); + + return null; + } catch (Exception ex) { + if (ex instanceof SQLException) { + return (SQLException) ex; + } + + return SQLError.createSQLException("Ping failed: " + ex.toString()); } - - return SQLError.createSQLException("Ping failed: " + ex.toString()); } + } else if (conn instanceof com.mysql.jdbc.jdbc2.optional.ConnectionWrapper) { + if (pingMethodWrapped != null) { + try { + this.pingMethodWrapped.invoke(conn, NO_ARGS_OBJECT_ARRAY); + + return null; + } catch (Exception ex) { + if (ex instanceof SQLException) { + return (SQLException) ex; + } + + return SQLError.createSQLException("Ping failed: " + ex.toString()); + } + } } // Punt and use 'SELECT 1' Modified: branches/branch_5_1/connector-j/src/com/mysql/jdbc/jdbc2/optional/ConnectionWrapper.java =================================================================== --- branches/branch_5_1/connector-j/src/com/mysql/jdbc/jdbc2/optional/ConnectionWrapper.java 2006-06-16 20:23:21 UTC (rev 5401) +++ branches/branch_5_1/connector-j/src/com/mysql/jdbc/jdbc2/optional/ConnectionWrapper.java 2006-06-16 20:58:36 UTC (rev 5402) @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2004 MySQL AB + Copyright (C) 2002-2006 MySQL AB This program is free software; you can redistribute it and/or modify it under the terms of version 2 of the GNU General Public License as @@ -877,4 +877,10 @@ public boolean isWrapperFor(Class arg0) throws SQLException { throw new ToBeImplementedException(); } + + public void ping() throws SQLException { + if (this.mc != null) { + this.mc.ping(); + } + } } Modified: branches/branch_5_1/connector-j/src/testsuite/regression/DataSourceRegressionTest.java =================================================================== --- branches/branch_5_1/connector-j/src/testsuite/regression/DataSourceRegressionTest.java 2006-06-16 20:23:21 UTC (rev 5401) +++ branches/branch_5_1/connector-j/src/testsuite/regression/DataSourceRegressionTest.java 2006-06-16 20:58:36 UTC (rev 5402) @@ -52,9 +52,11 @@ import testsuite.simple.DataSourceTest; import com.mysql.jdbc.NonRegisteringDriver; +import com.mysql.jdbc.integration.jboss.MysqlValidConnectionChecker; import com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource; import com.mysql.jdbc.jdbc2.optional.MysqlDataSource; import com.mysql.jdbc.jdbc2.optional.MysqlDataSourceFactory; +import com.mysql.jdbc.jdbc2.optional.MysqlXADataSource; /** * Tests fixes for bugs related to datasources. @@ -447,4 +449,26 @@ } } } + + /** + * Tests fix for BUG#20242 - MysqlValidConnectionChecker for JBoss doesn't + * work with MySQLXADataSources. + * + * @throws Exception if the test fails. + */ + public void testBug20242() throws Exception { + if (versionMeetsMinimum(5, 0)) { + try { + Class.forName("org.jboss.resource.adapter.jdbc.ValidConnectionChecker"); + } catch (Exception ex) { + return; // class not available for testing + } + + MysqlXADataSource xaDs = new MysqlXADataSource(); + xaDs.setUrl(dbUrl); + + MysqlValidConnectionChecker checker = new MysqlValidConnectionChecker(); + assertNull(checker.isValidConnection(xaDs.getXAConnection().getConnection())); + } + } }