[jboss-cvs] JBossAS SVN: r74339 - branches/Branch_4_2/connector/src/main/org/jboss/resource/adapter/jdbc/vendor.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Jun 10 04:27:21 EDT 2008
Author: jesper.pedersen
Date: 2008-06-10 04:27:21 -0400 (Tue, 10 Jun 2008)
New Revision: 74339
Modified:
branches/Branch_4_2/connector/src/main/org/jboss/resource/adapter/jdbc/vendor/MySQLValidConnectionChecker.java
Log:
[JBAS-5612] MySQLValidConnectionChecker is not serializable
Modified: branches/Branch_4_2/connector/src/main/org/jboss/resource/adapter/jdbc/vendor/MySQLValidConnectionChecker.java
===================================================================
--- branches/Branch_4_2/connector/src/main/org/jboss/resource/adapter/jdbc/vendor/MySQLValidConnectionChecker.java 2008-06-10 08:25:28 UTC (rev 74338)
+++ branches/Branch_4_2/connector/src/main/org/jboss/resource/adapter/jdbc/vendor/MySQLValidConnectionChecker.java 2008-06-10 08:27:21 UTC (rev 74339)
@@ -43,66 +43,98 @@
* @version $Revision$
*/
public class MySQLValidConnectionChecker implements ValidConnectionChecker, Serializable {
- private static final long serialVersionUID = -2227528634302168878L;
- private static final Logger log = Logger.getLogger(MySQLValidConnectionChecker.class);
- private Method ping;
- private boolean driverHasPingMethod = false;
+ private static final Logger log = Logger.getLogger(MySQLValidConnectionChecker.class);
+
+ private static final long serialVersionUID = 1323747853035005642L;
- // The timeout (apparently the timeout is ignored?)
- private static Object[] params = new Object[] {};
+ private boolean driverHasPingMethod = false;
+
+ // The timeout (apparently the timeout is ignored?)
+ private static Object[] params = new Object[] {};
+
+ public MySQLValidConnectionChecker()
+ {
+ try
+ {
+ Class mysqlConnection = Thread.currentThread().getContextClassLoader().loadClass("com.mysql.jdbc.Connection");
+ Method ping = mysqlConnection.getMethod("ping", new Class[] {});
+ if (ping != null)
+ {
+ driverHasPingMethod = true;
+ }
+ }
+ catch (Exception e)
+ {
+ log.warn("Cannot resolve com.mysq.jdbc.Connection.ping method. Will use 'SELECT 1' instead.", e);
+ }
+ }
- public MySQLValidConnectionChecker() {
- try {
- Class mysqlConnection = Thread.currentThread().getContextClassLoader().loadClass("com.mysql.jdbc.Connection");
- ping = mysqlConnection.getMethod("ping", new Class[] {});
- if (ping != null) {
- driverHasPingMethod = true;
- }
- } catch (Exception e) {
- log.warn("Cannot resolve com.mysq.jdbc.Connection.ping method. Will use 'SELECT 1' instead.", e);
- }
- }
+ public SQLException isValidConnection(Connection c)
+ {
+ //if there is a ping method then use it, otherwise just use a 'SELECT 1' statement
+ if (driverHasPingMethod)
+ {
+ try
+ {
+ Class mysqlConnection = Thread.currentThread().getContextClassLoader().loadClass("com.mysql.jdbc.Connection");
+ Method ping = mysqlConnection.getMethod("ping", new Class[] {});
+ ping.invoke(c, params);
+ }
+ catch (Exception e)
+ {
+ if (e instanceof SQLException)
+ {
+ return (SQLException) e;
+ }
+ else
+ {
+ log.warn("Unexpected error in ping", e);
+ return new SQLException("ping failed: " + e.toString());
+ }
+ }
+ }
+ else
+ {
- public SQLException isValidConnection(Connection c) {
- //if there is a ping method then use it, otherwise just use a 'SELECT 1' statement
- if (driverHasPingMethod) {
- try {
- ping.invoke(c, params);
- } catch (Exception e) {
- if (e instanceof SQLException) {
- return (SQLException) e;
- } else {
- log.warn("Unexpected error in ping", e);
- return new SQLException("ping failed: " + e.toString());
- }
- }
-
- } else {
-
- Statement stmt = null;
- ResultSet rs = null;
- try {
- stmt = c.createStatement();
- rs = stmt.executeQuery("SELECT 1");
- } catch (Exception e) {
- if (e instanceof SQLException) {
- return (SQLException) e;
- } else {
- log.warn("Unexpected error in ping (SELECT 1)", e);
- return new SQLException("ping (SELECT 1) failed: " + e.toString());
- }
- } finally {
- //cleanup the Statment
- try {
- if (rs != null) rs.close();
- if (stmt != null) stmt.close();
- } catch (SQLException e) {
- }
- }
-
- }
- return null;
- }
+ Statement stmt = null;
+ ResultSet rs = null;
+ try
+ {
+ stmt = c.createStatement();
+ rs = stmt.executeQuery("SELECT 1");
+ }
+ catch (Exception e)
+ {
+ if (e instanceof SQLException)
+ {
+ return (SQLException) e;
+ }
+ else
+ {
+ log.warn("Unexpected error in ping (SELECT 1)", e);
+ return new SQLException("ping (SELECT 1) failed: " + e.toString());
+ }
+ }
+ finally
+ {
+ //cleanup the Statment
+ try
+ {
+ if (rs != null)
+ rs.close();
+
+ if (stmt != null)
+ stmt.close();
+ }
+ catch (SQLException ignore)
+ {
+
+ }
+ }
+
+ }
+ return null;
+ }
}
More information about the jboss-cvs-commits
mailing list