[Jboss-cvs] JBossAS SVN: r57094 - trunk/connector/src/main/org/jboss/resource/adapter/jdbc/vendor

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Sep 22 22:27:19 EDT 2006


Author: weston.price at jboss.com
Date: 2006-09-22 22:27:18 -0400 (Fri, 22 Sep 2006)
New Revision: 57094

Modified:
   trunk/connector/src/main/org/jboss/resource/adapter/jdbc/vendor/MySQLValidConnectionChecker.java
Log:
Format, cleanup, clarify.

Modified: trunk/connector/src/main/org/jboss/resource/adapter/jdbc/vendor/MySQLValidConnectionChecker.java
===================================================================
--- trunk/connector/src/main/org/jboss/resource/adapter/jdbc/vendor/MySQLValidConnectionChecker.java	2006-09-23 02:25:20 UTC (rev 57093)
+++ trunk/connector/src/main/org/jboss/resource/adapter/jdbc/vendor/MySQLValidConnectionChecker.java	2006-09-23 02:27:18 UTC (rev 57094)
@@ -43,66 +43,100 @@
  * @version $Revision$
  */
 public class MySQLValidConnectionChecker implements ValidConnectionChecker, Serializable {
-	private static final long serialVersionUID = -2227528634302168878L;
 
+
 	private static final Logger log = Logger.getLogger(MySQLValidConnectionChecker.class);
+    
+    private static final long serialVersionUID = -2227528634302168878L;
 
 	private Method ping;
-	private boolean driverHasPingMethod = false;
+	
+    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");
-			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 {
-				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;
-	}
+	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 ignore)
+            {
+            
+            }
+         }
+
+      }
+      return null;
+   }
 }




More information about the jboss-cvs-commits mailing list