mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
extract method: resolveDriver
This commit is contained in:
@@ -883,24 +883,7 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
|
||||
|
||||
initFromSPIServiceLoader();
|
||||
|
||||
if (this.driver == null) {
|
||||
if (this.driverClass == null || this.driverClass.isEmpty()) {
|
||||
this.driverClass = JdbcUtils.getDriverClassName(this.jdbcUrl);
|
||||
}
|
||||
|
||||
if (MockDriver.class.getName().equals(driverClass)) {
|
||||
driver = MockDriver.instance;
|
||||
} else {
|
||||
if (jdbcUrl == null && (driverClass == null || driverClass.length() == 0)) {
|
||||
throw new SQLException("url not set");
|
||||
}
|
||||
driver = JdbcUtils.createDriver(driverClassLoader, driverClass);
|
||||
}
|
||||
} else {
|
||||
if (this.driverClass == null) {
|
||||
this.driverClass = driver.getClass().getName();
|
||||
}
|
||||
}
|
||||
resolveDriver();
|
||||
|
||||
initCheck();
|
||||
|
||||
@@ -1213,6 +1196,27 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
|
||||
LOG.error(errorMessage + "validationQuery not set");
|
||||
}
|
||||
|
||||
protected void resolveDriver() throws SQLException {
|
||||
if (this.driver == null) {
|
||||
if (this.driverClass == null || this.driverClass.isEmpty()) {
|
||||
this.driverClass = JdbcUtils.getDriverClassName(this.jdbcUrl);
|
||||
}
|
||||
|
||||
if (MockDriver.class.getName().equals(driverClass)) {
|
||||
driver = MockDriver.instance;
|
||||
} else {
|
||||
if (jdbcUrl == null && (driverClass == null || driverClass.length() == 0)) {
|
||||
throw new SQLException("url not set");
|
||||
}
|
||||
driver = JdbcUtils.createDriver(driverClassLoader, driverClass);
|
||||
}
|
||||
} else {
|
||||
if (this.driverClass == null) {
|
||||
this.driverClass = driver.getClass().getName();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void initCheck() throws SQLException {
|
||||
if (JdbcUtils.ORACLE.equals(this.dbType)) {
|
||||
isOracle = true;
|
||||
|
||||
Reference in New Issue
Block a user