mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
refactor loadClass
This commit is contained in:
@@ -56,6 +56,8 @@ import com.alibaba.druid.proxy.jdbc.DataSourceProxy;
|
||||
import com.alibaba.druid.proxy.jdbc.TransactionInfo;
|
||||
import com.alibaba.druid.stat.JdbcDataSourceStat;
|
||||
import com.alibaba.druid.stat.JdbcStatManager;
|
||||
import com.alibaba.druid.support.logging.Log;
|
||||
import com.alibaba.druid.support.logging.LogFactory;
|
||||
import com.alibaba.druid.util.ConcurrentIdentityHashMap;
|
||||
import com.alibaba.druid.util.DruidLoaderUtils;
|
||||
import com.alibaba.druid.util.Histogram;
|
||||
@@ -67,6 +69,7 @@ import com.alibaba.druid.util.JdbcUtils;
|
||||
* @author ljw<ljw2083@alibaba-inc.com>
|
||||
*/
|
||||
public abstract class DruidAbstractDataSource extends WrapperAdapter implements DruidAbstractDataSourceMBean, DataSource, DataSourceProxy, Serializable {
|
||||
private final static Log LOG = LogFactory.getLog(DruidAbstractDataSource.class);
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@@ -486,9 +489,10 @@ public abstract class DruidAbstractDataSource extends WrapperAdapter implements
|
||||
ValidConnectionChecker validConnectionChecker = null;
|
||||
if (clazz != null) {
|
||||
validConnectionChecker = (ValidConnectionChecker) clazz.newInstance();
|
||||
this.validConnectionChecker = validConnectionChecker;
|
||||
} else {
|
||||
LOG.error("load validConnectionCheckerClass error : " + validConnectionCheckerClass);
|
||||
}
|
||||
|
||||
this.validConnectionChecker = validConnectionChecker;
|
||||
}
|
||||
|
||||
public String getDbType() {
|
||||
@@ -713,6 +717,7 @@ public abstract class DruidAbstractDataSource extends WrapperAdapter implements
|
||||
if (clazz != null) {
|
||||
this.passwordCallback = (PasswordCallback) clazz.newInstance();
|
||||
} else {
|
||||
LOG.error("load passwordCallback error : " + passwordCallbackClassName);
|
||||
this.passwordCallback = null;
|
||||
}
|
||||
}
|
||||
@@ -1012,7 +1017,11 @@ public abstract class DruidAbstractDataSource extends WrapperAdapter implements
|
||||
}
|
||||
|
||||
Class<?> clazz = DruidLoaderUtils.loadClass(exceptionSorter);
|
||||
this.exceptionSorter = (ExceptionSorter) clazz.newInstance();
|
||||
if (clazz == null) {
|
||||
LOG.error("load exceptionSorter error : " + exceptionSorter);
|
||||
} else {
|
||||
this.exceptionSorter = (ExceptionSorter) clazz.newInstance();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+6
-2
@@ -49,7 +49,11 @@ public class OracleValidConnectionChecker implements ValidConnectionChecker, Ser
|
||||
public OracleValidConnectionChecker(){
|
||||
try {
|
||||
clazz = DruidLoaderUtils.loadClass("oracle.jdbc.driver.OracleConnection");
|
||||
ping = clazz.getMethod("pingDatabase", new Class[] { Integer.TYPE });
|
||||
if (clazz != null) {
|
||||
ping = clazz.getMethod("pingDatabase", new Class[] { Integer.TYPE });
|
||||
} else {
|
||||
ping = null;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Unable to resolve pingDatabase method:", e);
|
||||
}
|
||||
@@ -79,7 +83,7 @@ public class OracleValidConnectionChecker implements ValidConnectionChecker, Ser
|
||||
}
|
||||
|
||||
// unwrap
|
||||
if (clazz.isAssignableFrom(conn.getClass())) {
|
||||
if (clazz != null && clazz.isAssignableFrom(conn.getClass())) {
|
||||
Integer status = (Integer) ping.invoke(conn, params);
|
||||
|
||||
// Error
|
||||
|
||||
Reference in New Issue
Block a user