mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
druid 1.2.0, improved sql parser.
This commit is contained in:
@@ -60,6 +60,7 @@ import javax.sql.ConnectionPoolDataSource;
|
||||
import javax.sql.PooledConnection;
|
||||
|
||||
import com.alibaba.druid.Constants;
|
||||
import com.alibaba.druid.DbType;
|
||||
import com.alibaba.druid.TransactionTimeoutException;
|
||||
import com.alibaba.druid.VERSION;
|
||||
import com.alibaba.druid.filter.AutoLoad;
|
||||
@@ -828,14 +829,15 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
|
||||
filter.init(this);
|
||||
}
|
||||
|
||||
if (this.dbType == null || this.dbType.length() == 0) {
|
||||
this.dbType = JdbcUtils.getDbType(jdbcUrl, null);
|
||||
if (this.dbTypeName == null || this.dbTypeName.length() == 0) {
|
||||
this.dbTypeName = JdbcUtils.getDbType(jdbcUrl, null);
|
||||
}
|
||||
|
||||
if (JdbcConstants.MYSQL.equals(this.dbType)
|
||||
|| JdbcConstants.MARIADB.equals(this.dbType)
|
||||
|| JdbcConstants.OCEANBASE.equals(this.dbType)
|
||||
|| JdbcConstants.ALIYUN_ADS.equals(this.dbType)) {
|
||||
DbType dbType = DbType.of(this.dbTypeName);
|
||||
if (dbType == DbType.mysql
|
||||
|| dbType == DbType.mariadb
|
||||
|| dbType == DbType.oceanbase
|
||||
|| dbType == DbType.ads) {
|
||||
boolean cacheServerConfigurationSet = false;
|
||||
if (this.connectProperties.containsKey("cacheServerConfiguration")) {
|
||||
cacheServerConfigurationSet = true;
|
||||
@@ -884,14 +886,14 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
|
||||
if (isUseGlobalDataSourceStat()) {
|
||||
dataSourceStat = JdbcDataSourceStat.getGlobal();
|
||||
if (dataSourceStat == null) {
|
||||
dataSourceStat = new JdbcDataSourceStat("Global", "Global", this.dbType);
|
||||
dataSourceStat = new JdbcDataSourceStat("Global", "Global", this.dbTypeName);
|
||||
JdbcDataSourceStat.setGlobal(dataSourceStat);
|
||||
}
|
||||
if (dataSourceStat.getDbType() == null) {
|
||||
dataSourceStat.setDbType(this.dbType);
|
||||
dataSourceStat.setDbType(this.dbTypeName);
|
||||
}
|
||||
} else {
|
||||
dataSourceStat = new JdbcDataSourceStat(this.name, this.jdbcUrl, this.dbType, this.connectProperties);
|
||||
dataSourceStat = new JdbcDataSourceStat(this.name, this.jdbcUrl, this.dbTypeName, this.connectProperties);
|
||||
}
|
||||
dataSourceStat.setResetStatEnable(this.resetStatEnable);
|
||||
|
||||
@@ -1208,7 +1210,9 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
|
||||
}
|
||||
|
||||
protected void initCheck() throws SQLException {
|
||||
if (JdbcUtils.ORACLE.equals(this.dbType)) {
|
||||
DbType dbType = DbType.of(this.dbTypeName);
|
||||
|
||||
if (dbType == DbType.oracle) {
|
||||
isOracle = true;
|
||||
|
||||
if (driver.getMajorVersion() < 10) {
|
||||
@@ -1221,10 +1225,10 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
|
||||
}
|
||||
|
||||
oracleValidationQueryCheck();
|
||||
} else if (JdbcUtils.DB2.equals(dbType)) {
|
||||
} else if (dbType == DbType.db2) {
|
||||
db2ValidationQueryCheck();
|
||||
} else if (JdbcUtils.MYSQL.equals(this.dbType)
|
||||
|| JdbcUtils.MYSQL_DRIVER_6.equals(this.dbType)) {
|
||||
} else if (dbType == DbType.mysql
|
||||
|| JdbcUtils.MYSQL_DRIVER_6.equals(this.driverClass)) {
|
||||
isMySql = true;
|
||||
}
|
||||
|
||||
@@ -1241,7 +1245,7 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
|
||||
return;
|
||||
}
|
||||
|
||||
SQLStatementParser sqlStmtParser = SQLParserUtils.createSQLStatementParser(validationQuery, this.dbType);
|
||||
SQLStatementParser sqlStmtParser = SQLParserUtils.createSQLStatementParser(validationQuery, this.dbTypeName);
|
||||
List<SQLStatement> stmtList = sqlStmtParser.parseStatementList();
|
||||
|
||||
if (stmtList.size() != 1) {
|
||||
@@ -1270,7 +1274,7 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
|
||||
return;
|
||||
}
|
||||
|
||||
SQLStatementParser sqlStmtParser = SQLParserUtils.createSQLStatementParser(validationQuery, this.dbType);
|
||||
SQLStatementParser sqlStmtParser = SQLParserUtils.createSQLStatementParser(validationQuery, this.dbTypeName);
|
||||
List<SQLStatement> stmtList = sqlStmtParser.parseStatementList();
|
||||
|
||||
if (stmtList.size() != 1) {
|
||||
@@ -1336,7 +1340,7 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
|
||||
|| realDriverClassName.equals(JdbcConstants.ORACLE_DRIVER2)) {
|
||||
this.exceptionSorter = new OracleExceptionSorter();
|
||||
} else if (realDriverClassName.equals(JdbcConstants.OCEANBASE_DRIVER)) { // 写一个真实的 TestCase
|
||||
if (JdbcUtils.OCEANBASE_ORACLE.equalsIgnoreCase(dbType)) {
|
||||
if (JdbcUtils.OCEANBASE_ORACLE.name().equalsIgnoreCase(dbTypeName)) {
|
||||
this.exceptionSorter = new OceanBaseOracleExceptionSorter();
|
||||
} else {
|
||||
this.exceptionSorter = new MySqlExceptionSorter();
|
||||
@@ -2405,7 +2409,7 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
|
||||
}
|
||||
|
||||
value.setName(this.getName());
|
||||
value.setDbType(this.dbType);
|
||||
value.setDbType(this.dbTypeName);
|
||||
value.setDriverClassName(this.getDriverClassName());
|
||||
|
||||
value.setUrl(this.getUrl());
|
||||
@@ -3477,7 +3481,7 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
|
||||
map.put("MinEvictableIdleTimeMillis", this.minEvictableIdleTimeMillis);
|
||||
map.put("ConnectErrorCount", this.getConnectErrorCount());
|
||||
map.put("CreateTimespanMillis", this.getCreateTimespanMillis());
|
||||
map.put("DbType", this.dbType);
|
||||
map.put("DbType", this.dbTypeName);
|
||||
|
||||
// 20 - 24
|
||||
map.put("ValidationQuery", this.getValidationQuery());
|
||||
@@ -3553,7 +3557,7 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
|
||||
|
||||
dataMap.put("Identity", System.identityHashCode(this));
|
||||
dataMap.put("Name", this.getName());
|
||||
dataMap.put("DbType", this.dbType);
|
||||
dataMap.put("DbType", this.dbTypeName);
|
||||
dataMap.put("DriverClassName", this.getDriverClassName());
|
||||
|
||||
dataMap.put("URL", this.getUrl());
|
||||
|
||||
Reference in New Issue
Block a user