mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
测试
git-svn-id: http://code.alibabatech.com/svn/druid/trunk@494 b9813039-fb51-4c41-a8b9-e21c2acb5095
This commit is contained in:
+18
-19
@@ -9,7 +9,9 @@ import java.sql.Statement;
|
||||
|
||||
import com.alibaba.druid.logging.Log;
|
||||
import com.alibaba.druid.logging.LogFactory;
|
||||
import com.alibaba.druid.pool.PoolableConnection;
|
||||
import com.alibaba.druid.pool.ValidConnectionChecker;
|
||||
import com.alibaba.druid.proxy.jdbc.ConnectionProxy;
|
||||
import com.alibaba.druid.util.DruidLoaderUtils;
|
||||
import com.alibaba.druid.util.JdbcUtils;
|
||||
|
||||
@@ -37,27 +39,24 @@ public class MySqlValidConnectionChecker implements ValidConnectionChecker, Seri
|
||||
public boolean isValidConnection(Connection c, String valiateQuery, int validationQueryTimeout) {
|
||||
Connection conn = null;
|
||||
|
||||
if (clazz.isAssignableFrom(c.getClass())) {
|
||||
conn = c;
|
||||
} else {
|
||||
try {
|
||||
conn = (Connection) c.unwrap(clazz);
|
||||
} catch (SQLException e) {
|
||||
LOG.warn("Unexpected error in ping", e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// if there is a ping method then use it, otherwise just use a 'SELECT 1' statement
|
||||
if (conn != null && driverHasPingMethod) {
|
||||
try {
|
||||
ping.invoke(conn);
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
LOG.warn("Unexpected error in ping", e);
|
||||
return false;
|
||||
if (driverHasPingMethod) {
|
||||
if (c instanceof PoolableConnection) {
|
||||
c = ((PoolableConnection) c).getConnection();
|
||||
}
|
||||
|
||||
if (c instanceof ConnectionProxy) {
|
||||
c = ((ConnectionProxy) c).getConnectionRaw();
|
||||
}
|
||||
|
||||
if (clazz.isAssignableFrom(c.getClass())) {
|
||||
try {
|
||||
ping.invoke(conn);
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
LOG.warn("Unexpected error in ping", e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Statement stmt = null;
|
||||
|
||||
Reference in New Issue
Block a user