1 22 package org.jboss.resource.adapter.jdbc.vendor; 23 24 import java.io.Serializable ; 25 import java.lang.reflect.Method ; 26 import java.sql.Connection ; 27 import java.sql.SQLException ; 28 29 import org.jboss.logging.Logger; 30 import org.jboss.resource.adapter.jdbc.ValidConnectionChecker; 31 import org.jboss.util.NestedRuntimeException; 32 33 39 public class OracleValidConnectionChecker 40 implements ValidConnectionChecker, Serializable 41 { 42 private static final long serialVersionUID = -2227528634302168877L; 43 44 private static final Logger log = Logger.getLogger(OracleValidConnectionChecker.class); 45 46 private Method ping; 47 48 private static Object [] params = new Object [] { new Integer (5000) }; 50 51 public OracleValidConnectionChecker() 52 { 53 try 54 { 55 Class oracleConnection = Thread.currentThread().getContextClassLoader().loadClass("oracle.jdbc.driver.OracleConnection"); 56 ping = oracleConnection.getMethod("pingDatabase", new Class [] { Integer.TYPE }); 57 } 58 catch (Exception e) 59 { 60 throw new NestedRuntimeException("Unable to resolve pingDatabase method:", e); 61 } 62 } 63 64 public SQLException isValidConnection(Connection c) 65 { 66 try 67 { 68 Integer status = (Integer ) ping.invoke(c, params); 69 70 if (status.intValue() < 0) 72 return new SQLException ("pingDatabase failed status=" + status); 73 } 74 catch (Exception e) 75 { 76 log.warn("Unexpected error in pingDatabase", e); 78 } 79 80 return null; 82 } 83 } 84 | Popular Tags |