mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
修正Oracle Driver下 FilterChainImpl的unwrap的bug
git-svn-id: http://code.alibabatech.com/svn/druid/trunk@323 b9813039-fb51-4c41-a8b9-e21c2acb5095
This commit is contained in:
+10
-5
@@ -36,11 +36,16 @@ public class MySqlValidConnectionChecker implements ValidConnectionChecker, Seri
|
||||
|
||||
public boolean isValidConnection(Connection c) {
|
||||
Connection conn = null;
|
||||
try {
|
||||
conn = (Connection) c.unwrap(clazz);
|
||||
} catch (SQLException e) {
|
||||
LOG.warn("Unexpected error in ping", e);
|
||||
return false;
|
||||
|
||||
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
|
||||
|
||||
+15
-13
@@ -32,13 +32,13 @@ import com.alibaba.druid.util.DruidLoaderUtils;
|
||||
|
||||
public class OracleValidConnectionChecker implements ValidConnectionChecker, Serializable {
|
||||
|
||||
private static final long serialVersionUID = -2227528634302168877L;
|
||||
private static final long serialVersionUID = -2227528634302168877L;
|
||||
|
||||
private static final Log LOG = LogFactory.getLog(OracleValidConnectionChecker.class);
|
||||
private static final Log LOG = LogFactory.getLog(OracleValidConnectionChecker.class);
|
||||
|
||||
private final Class<?> clazz;
|
||||
private final Method ping;
|
||||
private final static Object[] params = new Object[] { new Integer(5000) };
|
||||
private final Class<?> clazz;
|
||||
private final Method ping;
|
||||
private final static Object[] params = new Object[] { new Integer(5000) };
|
||||
|
||||
public OracleValidConnectionChecker(){
|
||||
try {
|
||||
@@ -52,15 +52,17 @@ public class OracleValidConnectionChecker implements ValidConnectionChecker, Ser
|
||||
public boolean isValidConnection(Connection c) {
|
||||
try {
|
||||
// unwrap
|
||||
Connection conn = (Connection) c.unwrap(clazz);
|
||||
if (conn != null) {
|
||||
c = conn;
|
||||
|
||||
Integer status = (Integer) ping.invoke(c, params);
|
||||
if (!clazz.isAssignableFrom(c.getClass())) {
|
||||
Connection conn = (Connection) c.unwrap(clazz);
|
||||
if (conn != null) {
|
||||
c = conn;
|
||||
|
||||
// Error
|
||||
if (status.intValue() < 0) {
|
||||
return false;
|
||||
Integer status = (Integer) ping.invoke(c, params);
|
||||
|
||||
// Error
|
||||
if (status.intValue() < 0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
||||
@@ -23,7 +23,7 @@ public class TestOracle extends TestCase {
|
||||
dataSource.setUrl(jdbcUrl);
|
||||
dataSource.setUsername(user);
|
||||
dataSource.setPassword(password);
|
||||
dataSource.setFilters("stat");
|
||||
// dataSource.setFilters("stat");
|
||||
dataSource.setExceptionSoter(MySqlExceptionSorter.class.getName());
|
||||
|
||||
Connection conn = dataSource.getConnection();
|
||||
|
||||
Reference in New Issue
Block a user