mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
refactor
This commit is contained in:
@@ -493,6 +493,10 @@ public abstract class DruidAbstractDataSource extends WrapperAdapter implements
|
||||
public String getDbType() {
|
||||
return dbType;
|
||||
}
|
||||
|
||||
public void setDbType(String dbType) {
|
||||
this.dbType = dbType;
|
||||
}
|
||||
|
||||
public void addConnectionProperty(String name, String value) {
|
||||
if (inited) {
|
||||
|
||||
@@ -291,8 +291,10 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
|
||||
}
|
||||
}
|
||||
|
||||
this.dbType = JdbcUtils.getDbType(jdbcUrl, driverClass.getClass().getName());
|
||||
|
||||
if (this.dbType == null || this.dbType.length() == 0) {
|
||||
this.dbType = JdbcUtils.getDbType(jdbcUrl, driverClass.getClass().getName());
|
||||
}
|
||||
|
||||
if ("oracle".equals(this.dbType)) {
|
||||
isOracle = true;
|
||||
|
||||
|
||||
@@ -40,30 +40,28 @@ public class WallFilter extends FilterAdapter implements WallFilterMBean {
|
||||
public void init(DataSourceProxy dataSource) {
|
||||
this.dataSource = dataSource;
|
||||
|
||||
String dbType = this.dbType;
|
||||
|
||||
if (this.dbType == null || this.dbType.trim().length() == 0) {
|
||||
this.dbType = dataSource.getDbType();
|
||||
}
|
||||
|
||||
if (JdbcUtils.MYSQL.equals(dbType)) {
|
||||
provider = new MySqlWallProvider(config);
|
||||
|
||||
if (config == null) {
|
||||
config = new WallConfig(MySqlWallProvider.DEFAULT_CONFIG_DIR);
|
||||
}
|
||||
|
||||
provider = new MySqlWallProvider(config);
|
||||
} else if (JdbcUtils.ORACLE.equals(dbType)) {
|
||||
provider = new OracleWallProvider(config);
|
||||
|
||||
if (config == null) {
|
||||
config = new WallConfig(OracleWallProvider.DEFAULT_CONFIG_DIR);
|
||||
}
|
||||
|
||||
provider = new OracleWallProvider(config);
|
||||
} else if (JdbcUtils.SQL_SERVER.equals(dbType)) {
|
||||
provider = new SQLServerProvider(config);
|
||||
|
||||
if (config == null) {
|
||||
config = new WallConfig(SQLServerProvider.DEFAULT_CONFIG_DIR);
|
||||
}
|
||||
|
||||
provider = new SQLServerProvider(config);
|
||||
} else {
|
||||
throw new IllegalStateException("dbType not support : " + dbType);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.alibaba.druid.pool;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.Statement;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
@@ -14,6 +15,8 @@ public class TestMockPerf extends TestCase {
|
||||
dataSource.setInitialSize(3);
|
||||
dataSource.setMinIdle(3);
|
||||
dataSource.setMaxActive(20);
|
||||
dataSource.setDbType("mysql");
|
||||
dataSource.setFilters("stat,wall");
|
||||
dataSource.init();
|
||||
}
|
||||
|
||||
@@ -29,6 +32,9 @@ public class TestMockPerf extends TestCase {
|
||||
public void perf() throws Exception {
|
||||
for (int i = 0; i < 1000 * 1000; ++i) {
|
||||
Connection conn = dataSource.getConnection();
|
||||
Statement stmt = conn.createStatement();
|
||||
stmt.execute("SELECT 1");
|
||||
stmt.close();
|
||||
conn.close();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user