mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
Merge pull request #215 from wenshao/master
improve error info & improve parser & performance test
This commit is contained in:
@@ -496,6 +496,13 @@
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.tomcat</groupId>
|
||||
<artifactId>tomcat-jdbc</artifactId>
|
||||
<version>7.0.33</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.ibatis</groupId>
|
||||
<artifactId>ibatis-sqlmap</artifactId>
|
||||
@@ -506,7 +513,7 @@
|
||||
<dependency>
|
||||
<groupId>com.h2database</groupId>
|
||||
<artifactId>h2</artifactId>
|
||||
<version>1.3.168</version>
|
||||
<version>1.3.170</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
|
||||
@@ -1325,7 +1325,7 @@ public abstract class DruidAbstractDataSource extends WrapperAdapter implements
|
||||
conn = createPhysicalConnection(url, physicalConnectProperties);
|
||||
|
||||
if (conn == null) {
|
||||
throw new SQLException("connect error, url " + url);
|
||||
throw new SQLException("connect error, url " + url + ", driverClass " + this.driverClass);
|
||||
}
|
||||
|
||||
initPhysicalConnection(conn);
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.alibaba.druid.sql.ast.statement;
|
||||
|
||||
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
|
||||
public class SQLColumnPrimaryKey extends SQLConstaintImpl implements SQLColumnConstraint {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Override
|
||||
protected void accept0(SQLASTVisitor visitor) {
|
||||
if (visitor.visit(this)) {
|
||||
acceptChild(visitor, this.getName());
|
||||
}
|
||||
visitor.endVisit(this);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.alibaba.druid.sql.ast.statement;
|
||||
|
||||
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
|
||||
public class SQLColumnUniqueIndex extends SQLConstaintImpl implements SQLColumnConstraint {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Override
|
||||
protected void accept0(SQLASTVisitor visitor) {
|
||||
if (visitor.visit(this)) {
|
||||
acceptChild(visitor, this.getName());
|
||||
}
|
||||
visitor.endVisit(this);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -62,6 +62,7 @@ import com.alibaba.druid.sql.ast.statement.NotNullConstraint;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAssignItem;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLCharactorDataType;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLColumnDefinition;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLColumnPrimaryKey;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLPrimaryKey;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLSelect;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLSelectOrderByItem;
|
||||
@@ -1232,6 +1233,20 @@ public class SQLExprParser extends SQLParser {
|
||||
column.setDefaultExpr(new SQLNullExpr());
|
||||
return parseColumnRest(column);
|
||||
}
|
||||
|
||||
if (lexer.token == Token.PRIMARY) {
|
||||
lexer.nextToken();
|
||||
accept(Token.KEY);
|
||||
column.getConstaints().add(new SQLColumnPrimaryKey());
|
||||
return parseColumnRest(column);
|
||||
}
|
||||
|
||||
if (lexer.token == Token.UNION) {
|
||||
lexer.nextToken();
|
||||
accept(Token.KEY);
|
||||
column.getConstaints().add(new SQLColumnPrimaryKey());
|
||||
return parseColumnRest(column);
|
||||
}
|
||||
|
||||
return column;
|
||||
}
|
||||
|
||||
@@ -59,12 +59,17 @@ import com.alibaba.druid.sql.ast.expr.SQLUnaryExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLVariantRefExpr;
|
||||
import com.alibaba.druid.sql.ast.statement.NotNullConstraint;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableAddColumn;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableAddPrimaryKey;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableDropColumnItem;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableDropIndex;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAssignItem;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLCallStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLColumnConstraint;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLColumnDefinition;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLColumnPrimaryKey;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLColumnUniqueIndex;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLCommentStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLCreateDatabaseStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLCreateTableStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLDeleteStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLDropIndexStatement;
|
||||
@@ -75,9 +80,6 @@ import com.alibaba.druid.sql.ast.statement.SQLInsertStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLInsertStatement.ValuesClause;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLJoinTableSource;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLJoinTableSource.JoinType;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableAddPrimaryKey;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableDropIndex;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLCreateDatabaseStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLReleaseSavePointStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLRollbackStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLSavePointStatement;
|
||||
@@ -1179,4 +1181,16 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLColumnPrimaryKey x) {
|
||||
print(" PRIMARY KEY");
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLColumnUniqueIndex x) {
|
||||
print(" UNIQUE INDEX");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,6 +60,8 @@ import com.alibaba.druid.sql.ast.statement.SQLAlterTableDropIndex;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAssignItem;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLCallStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLColumnDefinition;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLColumnPrimaryKey;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLColumnUniqueIndex;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLCommentStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLCreateDatabaseStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLCreateTableStatement;
|
||||
@@ -395,4 +397,12 @@ public interface SQLASTVisitor {
|
||||
void endVisit(SQLOver x);
|
||||
|
||||
boolean visit(SQLOver x);
|
||||
|
||||
void endVisit(SQLColumnPrimaryKey x);
|
||||
|
||||
boolean visit(SQLColumnPrimaryKey x);
|
||||
|
||||
void endVisit(SQLColumnUniqueIndex x);
|
||||
|
||||
boolean visit(SQLColumnUniqueIndex x);
|
||||
}
|
||||
|
||||
@@ -60,6 +60,8 @@ import com.alibaba.druid.sql.ast.statement.SQLAlterTableDropIndex;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAssignItem;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLCallStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLColumnDefinition;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLColumnPrimaryKey;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLColumnUniqueIndex;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLCommentStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLCreateDatabaseStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLCreateTableStatement;
|
||||
@@ -714,4 +716,23 @@ public class SQLASTVisitorAdapter implements SQLASTVisitor {
|
||||
public boolean visit(SQLOver x) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(SQLColumnPrimaryKey x) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLColumnPrimaryKey x) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(SQLColumnUniqueIndex x) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLColumnUniqueIndex x) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,7 +63,7 @@ public class WallFilter extends FilterAdapter implements WallFilterMBean {
|
||||
dbType = JdbcUtils.getDbType(dataSource.getUrl(), null);
|
||||
}
|
||||
|
||||
if (JdbcUtils.MYSQL.equals(dbType)) {
|
||||
if (JdbcUtils.MYSQL.equals(dbType) || JdbcUtils.H2.equals(dbType)) {
|
||||
if (config == null) {
|
||||
config = new WallConfig(MySqlWallProvider.DEFAULT_CONFIG_DIR);
|
||||
}
|
||||
|
||||
@@ -26,10 +26,12 @@ import javax.sql.DataSource;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.apache.commons.dbcp.BasicDataSource;
|
||||
import org.logicalcobwebs.proxool.ProxoolDataSource;
|
||||
|
||||
import com.alibaba.druid.TestUtil;
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
import com.jolbox.bonecp.BoneCPDataSource;
|
||||
import com.mchange.v2.c3p0.ComboPooledDataSource;
|
||||
|
||||
public class Case0 extends TestCase {
|
||||
|
||||
@@ -59,7 +61,7 @@ public class Case0 extends TestCase {
|
||||
// password = "dragoon";
|
||||
}
|
||||
|
||||
public void test_0() throws Exception {
|
||||
public void test_druid() throws Exception {
|
||||
DruidDataSource dataSource = new DruidDataSource();
|
||||
|
||||
dataSource.setInitialSize(initialSize);
|
||||
@@ -82,7 +84,7 @@ public class Case0 extends TestCase {
|
||||
System.out.println();
|
||||
}
|
||||
|
||||
public void test_1() throws Exception {
|
||||
public void f_test_1() throws Exception {
|
||||
final BasicDataSource dataSource = new BasicDataSource();
|
||||
|
||||
dataSource.setInitialSize(initialSize);
|
||||
@@ -105,7 +107,7 @@ public class Case0 extends TestCase {
|
||||
System.out.println();
|
||||
}
|
||||
|
||||
public void test_2() throws Exception {
|
||||
public void f_test_2() throws Exception {
|
||||
BoneCPDataSource dataSource = new BoneCPDataSource();
|
||||
// dataSource.(10);
|
||||
// dataSource.setMaxActive(50);
|
||||
@@ -126,6 +128,66 @@ public class Case0 extends TestCase {
|
||||
}
|
||||
System.out.println();
|
||||
}
|
||||
|
||||
public void f_test_c3p0() throws Exception {
|
||||
ComboPooledDataSource dataSource = new ComboPooledDataSource();
|
||||
// dataSource.(10);
|
||||
// dataSource.setMaxActive(50);
|
||||
dataSource.setMinPoolSize(minIdle);
|
||||
dataSource.setMaxPoolSize(maxIdle);
|
||||
|
||||
dataSource.setDriverClass(driverClass);
|
||||
dataSource.setJdbcUrl(jdbcUrl);
|
||||
// dataSource.setPoolPreparedStatements(true);
|
||||
// dataSource.setMaxOpenPreparedStatements(100);
|
||||
dataSource.setUser(user);
|
||||
dataSource.setPassword(password);
|
||||
|
||||
for (int i = 0; i < LOOP_COUNT; ++i) {
|
||||
p0(dataSource, "c3p0");
|
||||
}
|
||||
System.out.println();
|
||||
}
|
||||
|
||||
public void f_test_proxool() throws Exception {
|
||||
ProxoolDataSource dataSource = new ProxoolDataSource();
|
||||
// dataSource.(10);
|
||||
// dataSource.setMaxActive(50);
|
||||
dataSource.setMinimumConnectionCount(minIdle);
|
||||
dataSource.setMaximumConnectionCount(maxIdle);
|
||||
|
||||
dataSource.setDriver(driverClass);
|
||||
dataSource.setDriverUrl(jdbcUrl);
|
||||
// dataSource.setPoolPreparedStatements(true);
|
||||
// dataSource.setMaxOpenPreparedStatements(100);
|
||||
dataSource.setUser(user);
|
||||
dataSource.setPassword(password);
|
||||
|
||||
for (int i = 0; i < LOOP_COUNT; ++i) {
|
||||
p0(dataSource, "proxool");
|
||||
}
|
||||
System.out.println();
|
||||
}
|
||||
|
||||
public void f_test_tomcat_jdbc() throws Exception {
|
||||
org.apache.tomcat.jdbc.pool.DataSource dataSource = new org.apache.tomcat.jdbc.pool.DataSource();
|
||||
// dataSource.(10);
|
||||
// dataSource.setMaxActive(50);
|
||||
dataSource.setMinIdle(minIdle);
|
||||
dataSource.setMaxActive(maxIdle);
|
||||
|
||||
dataSource.setDriverClassName(driverClass);
|
||||
dataSource.setUrl(jdbcUrl);
|
||||
// dataSource.setPoolPreparedStatements(true);
|
||||
// dataSource.setMaxOpenPreparedStatements(100);
|
||||
dataSource.setUsername(user);
|
||||
dataSource.setPassword(password);
|
||||
|
||||
for (int i = 0; i < LOOP_COUNT; ++i) {
|
||||
p0(dataSource, "tomcat-jdbc");
|
||||
}
|
||||
System.out.println();
|
||||
}
|
||||
|
||||
private void p0(DataSource dataSource, String name) throws SQLException {
|
||||
long startMillis = System.currentTimeMillis();
|
||||
@@ -134,7 +196,7 @@ public class Case0 extends TestCase {
|
||||
|
||||
for (int i = 0; i < COUNT; ++i) {
|
||||
Connection conn = dataSource.getConnection();
|
||||
// Statement stmt = conn.createStatement();
|
||||
Statement stmt = conn.createStatement();
|
||||
// ResultSet rs = stmt.executeQuery("SELECT 1");
|
||||
// rs.close();
|
||||
// stmt.close();
|
||||
|
||||
@@ -26,10 +26,12 @@ import javax.sql.DataSource;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.apache.commons.dbcp.BasicDataSource;
|
||||
import org.logicalcobwebs.proxool.ProxoolDataSource;
|
||||
|
||||
import com.alibaba.druid.TestUtil;
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
import com.jolbox.bonecp.BoneCPDataSource;
|
||||
import com.mchange.v2.c3p0.ComboPooledDataSource;
|
||||
|
||||
/**
|
||||
* TestOnBo 类Case1.java的实现描述:TODO 类实现描述
|
||||
@@ -47,19 +49,19 @@ public class Case1 extends TestCase {
|
||||
private int maxPoolSize = 50;
|
||||
private int maxActive = 50;
|
||||
private String validationQuery = "SELECT 1";
|
||||
private int threadCount = 5;
|
||||
private int loopCount = 3;
|
||||
final int LOOP_COUNT = 1000 * 100;
|
||||
private int threadCount = 2;
|
||||
private int loopCount = 5;
|
||||
final int LOOP_COUNT = 1000 * 500;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
jdbcUrl = "jdbc:fake:dragoon_v25masterdb";
|
||||
jdbcUrl = "jdbc:h2:mem:";
|
||||
user = "dragoon25";
|
||||
password = "dragoon25";
|
||||
driverClass = "com.alibaba.druid.mock.MockDriver";
|
||||
driverClass = "org.h2.Driver";
|
||||
}
|
||||
|
||||
public void test_0() throws Exception {
|
||||
DruidDataSource dataSource = new DruidDataSource(false);
|
||||
public void test_druid() throws Exception {
|
||||
DruidDataSource dataSource = new DruidDataSource();
|
||||
|
||||
dataSource.setInitialSize(initialSize);
|
||||
dataSource.setMaxActive(maxActive);
|
||||
@@ -80,7 +82,7 @@ public class Case1 extends TestCase {
|
||||
System.out.println();
|
||||
}
|
||||
|
||||
public void test_1() throws Exception {
|
||||
public void test_dbcp() throws Exception {
|
||||
final BasicDataSource dataSource = new BasicDataSource();
|
||||
|
||||
dataSource.setInitialSize(initialSize);
|
||||
@@ -102,7 +104,7 @@ public class Case1 extends TestCase {
|
||||
System.out.println();
|
||||
}
|
||||
|
||||
public void test_2() throws Exception {
|
||||
public void test_bonecp() throws Exception {
|
||||
BoneCPDataSource dataSource = new BoneCPDataSource();
|
||||
// dataSource.(10);
|
||||
// dataSource.setMaxActive(50);
|
||||
@@ -127,6 +129,66 @@ public class Case1 extends TestCase {
|
||||
}
|
||||
System.out.println();
|
||||
}
|
||||
|
||||
public void test_c3p0() throws Exception {
|
||||
ComboPooledDataSource dataSource = new ComboPooledDataSource();
|
||||
// dataSource.(10);
|
||||
// dataSource.setMaxActive(50);
|
||||
dataSource.setMinPoolSize(minPoolSize);
|
||||
dataSource.setMaxPoolSize(maxPoolSize);
|
||||
|
||||
dataSource.setDriverClass(driverClass);
|
||||
dataSource.setJdbcUrl(jdbcUrl);
|
||||
// dataSource.setPoolPreparedStatements(true);
|
||||
// dataSource.setMaxOpenPreparedStatements(100);
|
||||
dataSource.setUser(user);
|
||||
dataSource.setPassword(password);
|
||||
|
||||
for (int i = 0; i < loopCount; ++i) {
|
||||
p0(dataSource, "c3p0", threadCount);
|
||||
}
|
||||
System.out.println();
|
||||
}
|
||||
|
||||
public void test_proxool() throws Exception {
|
||||
ProxoolDataSource dataSource = new ProxoolDataSource();
|
||||
// dataSource.(10);
|
||||
// dataSource.setMaxActive(50);
|
||||
dataSource.setMinimumConnectionCount(minPoolSize);
|
||||
dataSource.setMaximumConnectionCount(maxPoolSize);
|
||||
|
||||
dataSource.setDriver(driverClass);
|
||||
dataSource.setDriverUrl(jdbcUrl);
|
||||
// dataSource.setPoolPreparedStatements(true);
|
||||
// dataSource.setMaxOpenPreparedStatements(100);
|
||||
dataSource.setUser(user);
|
||||
dataSource.setPassword(password);
|
||||
|
||||
for (int i = 0; i < loopCount; ++i) {
|
||||
p0(dataSource, "proxool", threadCount);
|
||||
}
|
||||
System.out.println();
|
||||
}
|
||||
|
||||
public void test_tomcat_jdbc() throws Exception {
|
||||
org.apache.tomcat.jdbc.pool.DataSource dataSource = new org.apache.tomcat.jdbc.pool.DataSource();
|
||||
// dataSource.(10);
|
||||
dataSource.setMaxIdle(maxPoolSize);
|
||||
dataSource.setMinIdle(minPoolSize);
|
||||
dataSource.setMaxActive(maxPoolSize);
|
||||
|
||||
dataSource.setDriverClassName(driverClass);
|
||||
dataSource.setUrl(jdbcUrl);
|
||||
// dataSource.setPoolPreparedStatements(true);
|
||||
// dataSource.setMaxOpenPreparedStatements(100);
|
||||
dataSource.setUsername(user);
|
||||
dataSource.setPassword(password);
|
||||
|
||||
for (int i = 0; i < loopCount; ++i) {
|
||||
p0(dataSource, "tomcat-jdbc", threadCount);
|
||||
}
|
||||
System.out.println();
|
||||
}
|
||||
|
||||
private void p0(final DataSource dataSource, String name, int threadCount) throws Exception {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user