1 6 package org.logicalcobwebs.proxool; 7 8 import java.sql.Connection ; 9 import java.sql.Statement ; 10 11 import org.apache.commons.logging.Log; 12 import org.apache.commons.logging.LogFactory; 13 14 17 public class DefaultConnectionValidator implements ConnectionValidatorIF { 18 19 22 public DefaultConnectionValidator() { 23 super(); 24 } 25 26 30 33 public boolean validate(ConnectionPoolDefinitionIF cpd, Connection connection) { 34 final String testSql = cpd.getHouseKeepingTestSql(); 37 if (testSql == null || (testSql.length() == 0)) { 38 Log log = getPoolLog(cpd.getAlias()); 39 log.warn("Connection validation requested but house-keeping-test-sql not defined"); 40 return false; 41 } 42 43 44 Statement st = null; 47 try { 48 st = connection.createStatement(); 49 st.execute(testSql); 50 51 return true; 52 } 53 catch (Throwable t) { 54 Log log = getPoolLog(cpd.getAlias()); 57 if(log.isDebugEnabled()) 58 log.debug("A connection failed the validation test with error: "+t); 59 60 return false; 61 } 62 finally { 63 if (st != null) { 64 try { 65 st.close(); 66 } catch (Throwable t) { 67 return false; 69 } 70 } 71 } 72 } 73 74 75 80 private Log getPoolLog(String poolAlias) { 81 return LogFactory.getLog("org.logicalcobwebs.proxool." + poolAlias); 82 } 83 } 84 85 96 | Popular Tags |