diff --git a/SECURITY.md b/SECURITY.md
new file mode 100644
index 0000000000..d6ddf96d06
--- /dev/null
+++ b/SECURITY.md
@@ -0,0 +1,120 @@
+# 漏洞奖励计划
+## 报告
+如果您认为自己在本程序中发现了任何安全(技术)漏洞,欢迎您通过 https://security.alibaba.com 向我们提交漏洞报告。
+如果您报告任何安全漏洞,请注意您可能包含以下信息(合格报告):
+* git程序URL地址,运行的环境
+* 包含必要屏幕截图的详细说明
+* 重现漏洞的步骤以及修复漏洞的建议。
+* 其他有用信息
+
+## 处理
+ASRC(Alibaba Security Response Center阿里安全响应中心)将尽快审核并回复您的提交内容,并在我们努力修复您提交的漏洞时随时通知您。如有必要,我们可能会与您联系以获取更多信息。
+
+
+## 条款和条件
+1. 仅接受技术漏洞并对其进行评级
+2. 出于安全原因,上报者同意与ASRC合作完成他/她提交的漏洞,不向任何第三方透露任何漏洞信息
+3. 如果不止一个人报告相同的安全漏洞,奖励将给予完成合格报告的第一个人
+4. 为了保护程序的用户,请在修复之前不要直接提交git的issue,也不要在社区讨论任何漏洞信息
+5. 所有奖励和声誉积分将提供给仅向ASRC提交其安全漏洞的上报者
+6. 安全漏洞奖励的解释权利归ASRC所有
+
+## 收集范围
+我们的主要收集漏洞类别是:
+* 服务器端请求伪造(SSRF)
+* SQL注入
+* 拒绝服务攻击
+* 远程执行代码(RCE)
+* XML外部实体攻击(XXE)
+* 访问控制问题(不安全的直接对象参考问题等)
+* 敏感目录遍历问题
+* 本地文件读取(LFD)
+* 敏感信息泄露(密钥,Cookie,Session等)
+
+## 奖励
+* 可直接导致严重问题的每个漏洞奖励7000元人民币
+* 存在限制及需要一定特殊环境下才能利用的问题将给予700-5600元人民币不等的奖励,比如需要用户主动点击才会触发的问题或需要admin权限
+* 只有在指定环境下才可以运行的利用将有可能被收纳但不给予奖励,或直接被忽略,比如只在fastjson+linux特定版本才会出现的问题
+
+## 不在收集范围的报告
+* 影响过时浏览器或平台用户的漏洞
+* Self-XSS
+* 会话固定
+* 内容欺骗
+* 缺少cookie标记
+* 混合内容警告
+* SSL / TLS问题
+* Clickjacking
+* 基于Flash的漏洞
+* 反射文件下载攻击(RFD)
+* 物理或社会工程攻击
+* 未验证自动化工具或扫描仪的结果
+* 登录/注销/未认证/低影响CSRF
+* 需要MITM或物理访问用户设备的攻击
+* 与网络协议或行业标准相关的问题
+* 不能用于直接攻击的错误信息泄露
+* 缺少与安全相关的HTTP标头等
+
+
+
+
+
+# Vulnerability Reward Program
+## Reporting
+If you believe you have found any security (technical) vulnerability in the Program, you are welcomed to submit a vulnerability report to us at https://security.alibaba.com
+In case of reporting any security vulnerability, please be noted that you may including following information (Qualified Reporting):
+* The git program URL and running version
+* A detailed description with necessary screenshots
+* Steps to reappearance the vulnerability and your advice to fix it
+* Other useful information
+
+
+## Processing
+ASRC (Alibaba Security Response Center) will review and respond as quickly as possible to your submission, and keep you informed as we work to fix the vulnerability you submitted. We may contact you for further information if necessary.
+
+
+## Terms and Conditions
+1. ONLY technical vulnerabilities will be accepted and rated.
+2. With regarding to security reasons, reporters agree to cooperate with ASRC exclusively on the vulnerability he/she submitted and not disclose any information of vulnerability to any third-parties.
+3. In the case that more than one person report the same security vulnerability, the reward will be given to the first person who accomplish a Qualified Reporting.
+4. To protect users of the program, please do not directly submit issue on github or discuss anything with the community
+5. All Rewards and Reputation Credits are given to the reporters who submit his/her security vulnerabilities ONLY to ASRC.
+6. All rights for the security vulnerability rewards are reserved by ASRC.
+
+## Scope of Collecting
+The main categories of vulnerabilities that we are sincerely looking for are:
+* Server-Side Request Forgery (SSRF)
+* SQL Injection
+* Denial of Service Attack
+* Remote Code Execution (RCE)
+* XML External Entity Attacks (XXE)
+* Access Control Issues (Insecure Direct Object Reference issues, etc.)
+* Directory Traversal Issues
+* Local File Disclosure (LFD)
+* Sensitive Information Leakage (Key, Cookie, Session etc.)
+
+## Reward
+* $1,000 for one valid report
+* $100-$800 for Vuls which is limited. For example, Vuls that need user interactions or administrator authority
+* Vuls which only work on the special version will be accepted but no reward, or directly rejected. For example, Vul runs only on a special linux version
+
+## Ineligible Reports
+* Vulnerabilities affecting users of outdated browsers or platforms
+* "Self" XSS
+* Session fixation
+* Content Spoofing
+* Missing cookie flags
+* Mixed content warnings
+* SSL/TLS best practices
+* Clickjacking/UI redressing
+* Flash-based vulnerabilities
+* Reflected file download attacks (RFD)
+* Physical or social engineering attacks
+* Unverified Results of automated tools or scanners
+* Login/logout/unauthenticated/low-impact CSRF
+* Attacks requiring MITM or physical access to a user's device
+* Issues related to networking protocols or industry standards
+* Error information disclosure that cannot be used to make a direct attack
+* Missing security-related HTTP headers which do not lead directly to a vulnerability
+
+
diff --git a/lib/com/taobao/parent/1.0.1/parent-1.0.1.pom b/lib/com/taobao/parent/1.0.1/parent-1.0.1.pom
deleted file mode 100644
index 745485cd23..0000000000
--- a/lib/com/taobao/parent/1.0.1/parent-1.0.1.pom
+++ /dev/null
@@ -1,179 +0,0 @@
-
- 4.0.0
- com.taobao
- parent
- pom
- 1.0.1
- parent pom for tb
-
-
-
- central
- http://mvnrepo.taobao.ali.com/mvn/repository
-
- true
-
-
- false
-
-
-
- snapshots
- http://mvnrepo.taobao.ali.com/mvn/repository
-
- false
-
-
- true
-
-
-
-
-
- central
- http://mvnrepo.taobao.ali.com/mvn/repository
-
- true
-
-
- false
-
-
-
- snapshots
- http://mvnrepo.taobao.ali.com/mvn/repository
-
- false
-
-
- true
-
-
-
-
-
- releases
- http://mvnrepo.taobao.ali.com/mvn/releases
-
-
- snapshots
- http://mvnrepo.taobao.ali.com/mvn/snapshots
-
-
-
-
-
-
- org.apache.maven.plugins
- maven-source-plugin
-
-
- attach-sources
-
- jar
-
-
-
-
-
-
-
- maven-compiler-plugin
-
- 1.5
- 1.5
- GBK
-
-
-
-
-
- org.apache.maven.plugins
- maven-javadoc-plugin
-
- UTF16
- true
-
-
-
-
-
- com.atlassian.maven.plugins
- maven-clover2-plugin
- 2.3.2
-
- ${clover.license}
- true
- GBK
-
-
-
-
- org.apache.maven.plugins
- maven-surefire-plugin
-
-
- **/*Test.java
-
-
-
-
-
-
-
- com.taobao.scm
- scm-maven-plugin
- 1.0
-
-
-
-
-
-
- src/main/resources
-
- **/*
-
-
-
-
-
- src/test/java
-
- **/*
-
-
-
- src/test/resources
-
- **/*
-
-
-
-
-
\ No newline at end of file
diff --git a/lib/com/taobao/parent/1.0.1/parent-1.0.1.pom.sha1 b/lib/com/taobao/parent/1.0.1/parent-1.0.1.pom.sha1
deleted file mode 100644
index 299bdcdbb0..0000000000
--- a/lib/com/taobao/parent/1.0.1/parent-1.0.1.pom.sha1
+++ /dev/null
@@ -1 +0,0 @@
-dc05668192b5726439cf98e75a15b1ccc2ff69c1
\ No newline at end of file
diff --git a/lib/com/taobao/tbdatasource/tbdatasource/2.0.2/tbdatasource-2.0.2-sources.jar b/lib/com/taobao/tbdatasource/tbdatasource/2.0.2/tbdatasource-2.0.2-sources.jar
deleted file mode 100644
index 4b89dc2ba4..0000000000
Binary files a/lib/com/taobao/tbdatasource/tbdatasource/2.0.2/tbdatasource-2.0.2-sources.jar and /dev/null differ
diff --git a/lib/com/taobao/tbdatasource/tbdatasource/2.0.2/tbdatasource-2.0.2-sources.jar.sha1 b/lib/com/taobao/tbdatasource/tbdatasource/2.0.2/tbdatasource-2.0.2-sources.jar.sha1
deleted file mode 100644
index 39e52fd16d..0000000000
--- a/lib/com/taobao/tbdatasource/tbdatasource/2.0.2/tbdatasource-2.0.2-sources.jar.sha1
+++ /dev/null
@@ -1 +0,0 @@
-01899596a36b40dc7d5570830248bc42a14dffd3
\ No newline at end of file
diff --git a/lib/com/taobao/tbdatasource/tbdatasource/2.0.2/tbdatasource-2.0.2.jar b/lib/com/taobao/tbdatasource/tbdatasource/2.0.2/tbdatasource-2.0.2.jar
deleted file mode 100644
index 3d121d01e4..0000000000
Binary files a/lib/com/taobao/tbdatasource/tbdatasource/2.0.2/tbdatasource-2.0.2.jar and /dev/null differ
diff --git a/lib/com/taobao/tbdatasource/tbdatasource/2.0.2/tbdatasource-2.0.2.jar.sha1 b/lib/com/taobao/tbdatasource/tbdatasource/2.0.2/tbdatasource-2.0.2.jar.sha1
deleted file mode 100644
index 5d3f2e843a..0000000000
--- a/lib/com/taobao/tbdatasource/tbdatasource/2.0.2/tbdatasource-2.0.2.jar.sha1
+++ /dev/null
@@ -1 +0,0 @@
-8be62df4341ba19690261a61b4c04d70472040bb
\ No newline at end of file
diff --git a/lib/com/taobao/tbdatasource/tbdatasource/2.0.2/tbdatasource-2.0.2.pom b/lib/com/taobao/tbdatasource/tbdatasource/2.0.2/tbdatasource-2.0.2.pom
deleted file mode 100644
index 3459678581..0000000000
--- a/lib/com/taobao/tbdatasource/tbdatasource/2.0.2/tbdatasource-2.0.2.pom
+++ /dev/null
@@ -1,122 +0,0 @@
-
-
- parent
- com.taobao
- 1.0.1
-
- 4.0.0
- com.taobao.tbdatasource
- tbdatasource
- tbdatasource
- 2.0.2
-
-
-
- org.apache.maven.plugins
- maven-source-plugin
-
-
- attach-sources
-
- jar
-
-
-
-
-
- maven-compiler-plugin
-
- 1.6
- 1.6
- GBK
-
-
-
-
-
-
- jboss.common
- jboss-common
- 1.2.1.GA
-
-
- jboss
- jboss-j2ee
- 4.2.2.GA
-
-
- log4j
- log4j
- 1.2.14
-
-
- dom4j
- dom4j
- 1.6.1
-
-
- jaxen
- jaxen
- 1.1.1
-
-
- commons-lang
- commons-lang
- 2.4
-
-
- xom
- xom
- 1.0b3
-
-
- org.springframework
- spring-core
- 2.0.7
- test
-
-
- org.springframework
- spring-beans
- 2.0.7
- test
-
-
- junit
- junit
- 4.6
- test
-
-
- hsqldb
- hsqldb
- 1.8.0.10
- test
-
-
- com.oracle
- ojdbc14
- 10.2.0.3.0
- test
-
-
- mysql
- mysql-connector-java
- 5.1.6
- test
-
-
- org.springframework
- spring-mock
- 2.0.7
- test
-
-
- org.springframework
- spring-jdbc
- 2.0.7
- test
-
-
-
\ No newline at end of file
diff --git a/lib/com/taobao/tbdatasource/tbdatasource/2.0.2/tbdatasource-2.0.2.pom.sha1 b/lib/com/taobao/tbdatasource/tbdatasource/2.0.2/tbdatasource-2.0.2.pom.sha1
deleted file mode 100644
index 2232fe194f..0000000000
--- a/lib/com/taobao/tbdatasource/tbdatasource/2.0.2/tbdatasource-2.0.2.pom.sha1
+++ /dev/null
@@ -1 +0,0 @@
-de09f1978fe0edb43cc9504e8744dc2136117423
\ No newline at end of file
diff --git a/lib/proxool/proxool-cglib/0.9.1/proxool-cglib-0.9.1.jar b/lib/proxool/proxool-cglib/0.9.1/proxool-cglib-0.9.1.jar
deleted file mode 100644
index 4fe25c136d..0000000000
Binary files a/lib/proxool/proxool-cglib/0.9.1/proxool-cglib-0.9.1.jar and /dev/null differ
diff --git a/lib/proxool/proxool/0.9.1/proxool-0.9.1-sources.jar b/lib/proxool/proxool/0.9.1/proxool-0.9.1-sources.jar
deleted file mode 100644
index a276e0d438..0000000000
Binary files a/lib/proxool/proxool/0.9.1/proxool-0.9.1-sources.jar and /dev/null differ
diff --git a/lib/proxool/proxool/0.9.1/proxool-0.9.1.jar b/lib/proxool/proxool/0.9.1/proxool-0.9.1.jar
deleted file mode 100644
index ffb163f24e..0000000000
Binary files a/lib/proxool/proxool/0.9.1/proxool-0.9.1.jar and /dev/null differ
diff --git a/pom.xml b/pom.xml
index fa4000955f..57cfe89cb2 100644
--- a/pom.xml
+++ b/pom.xml
@@ -3,7 +3,8 @@
4.0.0
com.alibaba
druid
- 1.1.20-SNAPSHOT
+ 1.1.20
+
jar
druid
@@ -463,7 +464,7 @@
mysql
mysql-connector-java
- 8.0.15
+ 8.0.17
provided
@@ -475,7 +476,7 @@
org.postgresql
postgresql
- 42.1.4
+ 42.2.6
provided
@@ -512,7 +513,7 @@
com.h2database
h2
- 1.4.191
+ 1.4.199
provided
@@ -617,18 +618,6 @@
0.8.0.RELEASE
test
-
- proxool
- proxool
- 0.9.1
- test
-
-
- proxool
- proxool-cglib
- 0.9.1
- test
-
c3p0
@@ -651,19 +640,6 @@
test
-
- com.taobao.tbdatasource
- tbdatasource
- 2.0.2
- test
-
-
- jboss
- jboss-j2ee
-
-
-
-
org.javasimon
javasimon-spring
diff --git a/src/main/java/com/alibaba/druid/VERSION.java b/src/main/java/com/alibaba/druid/VERSION.java
index 126c71d758..5870e4ab75 100644
--- a/src/main/java/com/alibaba/druid/VERSION.java
+++ b/src/main/java/com/alibaba/druid/VERSION.java
@@ -19,7 +19,7 @@ public final class VERSION {
public final static int MajorVersion = 1;
public final static int MinorVersion = 1;
- public final static int RevisionVersion = 17;
+ public final static int RevisionVersion = 20;
public static String getVersionNumber() {
return VERSION.MajorVersion + "." + VERSION.MinorVersion + "." + VERSION.RevisionVersion;
diff --git a/src/main/java/com/alibaba/druid/pool/DruidAbstractDataSource.java b/src/main/java/com/alibaba/druid/pool/DruidAbstractDataSource.java
index 747e434fea..1e76d94d27 100644
--- a/src/main/java/com/alibaba/druid/pool/DruidAbstractDataSource.java
+++ b/src/main/java/com/alibaba/druid/pool/DruidAbstractDataSource.java
@@ -280,6 +280,8 @@ public abstract class DruidAbstractDataSource extends WrapperAdapter implements
protected boolean initGlobalVariants = false;
protected volatile boolean onFatalError = false;
protected volatile int onFatalErrorMaxActive = 0;
+ protected volatile int fatalErrorCount = 0;
+ protected volatile int fatalErrorCountLastShrink = 0;
protected volatile long lastFatalErrorTimeMillis = 0;
protected volatile String lastFatalErrorSql = null;
protected volatile Throwable lastFatalError = null;
@@ -1382,6 +1384,17 @@ public abstract class DruidAbstractDataSource extends WrapperAdapter implements
Exception error = null;
try {
result = validConnectionChecker.isValidConnection(conn, validationQuery, validationQueryTimeout);
+
+ if (result && onFatalError) {
+ lock.lock();
+ try {
+ if (onFatalError) {
+ onFatalError = false;
+ }
+ } finally {
+ lock.unlock();
+ }
+ }
} catch (SQLException ex) {
throw ex;
} catch (Exception ex) {
@@ -1409,6 +1422,18 @@ public abstract class DruidAbstractDataSource extends WrapperAdapter implements
if (!rs.next()) {
throw new SQLException("validationQuery didn't return a row");
}
+
+ if (onFatalError) {
+ lock.lock();
+ try {
+ if (onFatalError) {
+ onFatalError = false;
+ }
+ }
+ finally {
+ lock.unlock();
+ }
+ }
} finally {
JdbcUtils.close(rs);
JdbcUtils.close(stmt);
@@ -1458,6 +1483,17 @@ public abstract class DruidAbstractDataSource extends WrapperAdapter implements
}
}
+ if (valid && onFatalError) {
+ lock.lock();
+ try {
+ if (onFatalError) {
+ onFatalError = false;
+ }
+ } finally {
+ lock.unlock();
+ }
+ }
+
return valid;
}
@@ -1485,6 +1521,17 @@ public abstract class DruidAbstractDataSource extends WrapperAdapter implements
JdbcUtils.close(stmt);
}
+ if (onFatalError) {
+ lock.lock();
+ try {
+ if (onFatalError) {
+ onFatalError = false;
+ }
+ } finally {
+ lock.unlock();
+ }
+ }
+
return true;
} catch (Throwable ex) {
// skip
diff --git a/src/main/java/com/alibaba/druid/pool/DruidDataSource.java b/src/main/java/com/alibaba/druid/pool/DruidDataSource.java
index b880db3b1d..7b621a2494 100644
--- a/src/main/java/com/alibaba/druid/pool/DruidDataSource.java
+++ b/src/main/java/com/alibaba/druid/pool/DruidDataSource.java
@@ -1228,7 +1228,7 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
}
if (removeAbandoned) {
- LOG.warn("removeAbandoned is true, not use in productiion.");
+ LOG.warn("removeAbandoned is true, not use in production.");
}
}
@@ -1691,6 +1691,9 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
public void handleConnectionException(DruidPooledConnection pooledConnection, Throwable t, String sql) throws SQLException {
final DruidConnectionHolder holder = pooledConnection.getConnectionHolder();
+ if (holder == null) {
+ return;
+ }
errorCountUpdater.incrementAndGet(this);
lastError = t;
@@ -1751,13 +1754,27 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
}
lastFatalErrorTimeMillis = lastErrorTimeMillis;
- onFatalError = true;
+ fatalErrorCount++;
+ if (fatalErrorCount - fatalErrorCountLastShrink > onFatalErrorMaxActive) {
+ onFatalError = true;
+ }
lastFatalError = error;
lastFatalErrorSql = sql;
} finally {
lock.unlock();
}
+ if(onFatalError && holder != null && holder.getDataSource() != null) {
+ ReentrantLock dataSourceLock = holder.getDataSource().lock;
+ dataSourceLock.lock();
+ try {
+ emptySignal();
+ }
+ finally {
+ dataSourceLock.unlock();
+ }
+ }
+
if (requireDiscard) {
if (holder.statementTrace != null) {
holder.lock.lock();
@@ -2483,6 +2500,7 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
&& (!(keepAlive && activeCount + poolingCount < minIdle)) // 在keepAlive场景不能放弃创建
&& (!initTask) // 线程池初始化时的任务不能放弃创建
&& !isFailContinuous() // failContinuous时不能放弃创建,否则会无法创建线程
+ && !isOnFatalError() // onFatalError时不能放弃创建,否则会无法创建线程
) {
clearCreateTask(taskId);
return;
@@ -2970,6 +2988,9 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
boolean needFill = false;
int evictCount = 0;
int keepAliveCount = 0;
+ int fatalErrorIncrement = fatalErrorCount - fatalErrorCountLastShrink;
+ fatalErrorCountLastShrink = fatalErrorCount;
+
try {
if (!inited) {
return;
@@ -2980,6 +3001,11 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
for (int i = 0; i < poolingCount; ++i) {
DruidConnectionHolder connection = connections[i];
+ if ((onFatalError || fatalErrorIncrement > 0) && (lastFatalErrorTimeMillis > connection.connectTimeMillis)) {
+ keepAliveConnections[keepAliveCount++] = connection;
+ continue;
+ }
+
if (checkTime) {
if (phyTimeoutMillis > 0) {
long phyConnectTimeMillis = currentTimeMillis - connection.connectTimeMillis;
@@ -3104,6 +3130,13 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
} finally {
lock.unlock();
}
+ } else if (onFatalError || fatalErrorIncrement > 0) {
+ lock.lock();
+ try {
+ emptySignal();
+ } finally {
+ lock.unlock();
+ }
}
}
@@ -3368,7 +3401,7 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
map.put("ActiveCount", this.getActiveCount());
map.put("PoolingCount", this.getPoolingCount());
map.put("LockQueueLength", this.getLockQueueLength());
- map.put("WaitThreadCount", this.getNotEmptyWaitThreadPeak());
+ map.put("WaitThreadCount", this.getNotEmptyWaitThreadCount());
// 10 - 14
map.put("InitialSize", this.getInitialSize());
diff --git a/src/main/java/com/alibaba/druid/pool/DruidPooledConnection.java b/src/main/java/com/alibaba/druid/pool/DruidPooledConnection.java
index a6b3afbda7..56f55c60ae 100644
--- a/src/main/java/com/alibaba/druid/pool/DruidPooledConnection.java
+++ b/src/main/java/com/alibaba/druid/pool/DruidPooledConnection.java
@@ -147,6 +147,7 @@ public class DruidPooledConnection extends PoolableWrapper implements javax.sql.
public void closePoolableStatement(DruidPooledPreparedStatement stmt) throws SQLException {
PreparedStatement rawStatement = stmt.getRawPreparedStatement();
+ final DruidConnectionHolder holder = this.holder;
if (holder == null) {
return;
}
@@ -1188,19 +1189,19 @@ public class DruidPooledConnection extends PoolableWrapper implements javax.sql.
}
public String getSchema() throws SQLException {
- throw new SQLFeatureNotSupportedException();
+ return conn.getSchema();
}
public void abort(Executor executor) throws SQLException {
- throw new SQLFeatureNotSupportedException();
+ conn.abort(executor);
}
public void setNetworkTimeout(Executor executor, int milliseconds) throws SQLException {
- throw new SQLFeatureNotSupportedException();
+ conn.setNetworkTimeout(executor, milliseconds);
}
public int getNetworkTimeout() throws SQLException {
- throw new SQLFeatureNotSupportedException();
+ return conn.getNetworkTimeout();
}
final void beforeExecute() {
diff --git a/src/main/java/com/alibaba/druid/pool/DruidPooledPreparedStatement.java b/src/main/java/com/alibaba/druid/pool/DruidPooledPreparedStatement.java
index 5eba33da5c..910fa4317b 100644
--- a/src/main/java/com/alibaba/druid/pool/DruidPooledPreparedStatement.java
+++ b/src/main/java/com/alibaba/druid/pool/DruidPooledPreparedStatement.java
@@ -490,7 +490,7 @@ public class DruidPooledPreparedStatement extends DruidPooledStatement implement
incrementExecuteCount();
transactionRecord(sql);
- // oracleSetRowPrefetch();
+ oracleSetRowPrefetch();
conn.beforeExecute();
try {
diff --git a/src/main/java/com/alibaba/druid/pool/DruidPooledResultSet.java b/src/main/java/com/alibaba/druid/pool/DruidPooledResultSet.java
index 8f64c92e55..c30895be8e 100644
--- a/src/main/java/com/alibaba/druid/pool/DruidPooledResultSet.java
+++ b/src/main/java/com/alibaba/druid/pool/DruidPooledResultSet.java
@@ -27,7 +27,6 @@ import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.RowId;
import java.sql.SQLException;
-import java.sql.SQLFeatureNotSupportedException;
import java.sql.SQLWarning;
import java.sql.SQLXML;
import java.sql.Statement;
@@ -1763,11 +1762,21 @@ public final class DruidPooledResultSet extends PoolableWrapper implements Resul
}
}
+ @Override
public T getObject(int columnIndex, Class type) throws SQLException {
- return rs.getObject(columnIndex, type);
+ try {
+ return rs.getObject(columnIndex, type);
+ } catch (Throwable t) {
+ throw checkException(t);
+ }
}
+ @Override
public T getObject(String columnLabel, Class type) throws SQLException {
- return rs.getObject(columnLabel, type);
+ try {
+ return rs.getObject(columnLabel, type);
+ } catch (Throwable t) {
+ throw checkException(t);
+ }
}
}
diff --git a/src/main/java/com/alibaba/druid/pool/DruidPooledStatement.java b/src/main/java/com/alibaba/druid/pool/DruidPooledStatement.java
index 32875cb8df..d2b3417064 100644
--- a/src/main/java/com/alibaba/druid/pool/DruidPooledStatement.java
+++ b/src/main/java/com/alibaba/druid/pool/DruidPooledStatement.java
@@ -98,8 +98,9 @@ public class DruidPooledStatement extends PoolableWrapper implements Statement {
DruidDataSource dataSource = null;
- if (this.conn.holder.dataSource instanceof DruidDataSource) {
- dataSource = (DruidDataSource) this.conn.holder.dataSource;
+ final DruidConnectionHolder holder = this.conn.holder;
+ if (holder.dataSource instanceof DruidDataSource) {
+ dataSource = (DruidDataSource) holder.dataSource;
}
if (dataSource == null) {
return;
diff --git a/src/main/java/com/alibaba/druid/pool/vendor/PGValidConnectionChecker.java b/src/main/java/com/alibaba/druid/pool/vendor/PGValidConnectionChecker.java
index 73f00c7577..a7e4bbcd5a 100644
--- a/src/main/java/com/alibaba/druid/pool/vendor/PGValidConnectionChecker.java
+++ b/src/main/java/com/alibaba/druid/pool/vendor/PGValidConnectionChecker.java
@@ -15,17 +15,17 @@
*/
package com.alibaba.druid.pool.vendor;
-import java.io.Serializable;
-import java.sql.Connection;
-import java.sql.ResultSet;
-import java.sql.Statement;
-
import com.alibaba.druid.pool.DruidPooledConnection;
import com.alibaba.druid.pool.ValidConnectionChecker;
import com.alibaba.druid.pool.ValidConnectionCheckerAdapter;
import com.alibaba.druid.proxy.jdbc.ConnectionProxy;
import com.alibaba.druid.util.JdbcUtils;
+import java.io.Serializable;
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.Statement;
+
public class PGValidConnectionChecker extends ValidConnectionCheckerAdapter implements ValidConnectionChecker, Serializable {
private static final long serialVersionUID = -2227528634302168877L;
@@ -61,7 +61,10 @@ public class PGValidConnectionChecker extends ValidConnectionCheckerAdapter impl
ResultSet rs = null;
try {
stmt = conn.createStatement();
- stmt.setQueryTimeout(queryTimeout);
+ if (queryTimeout >= 0) {
+ //pgsql Driver 9.0以及以下版本不支持setQueryTimeout,可通过设置queryTimeout<0兼容低版本
+ stmt.setQueryTimeout(queryTimeout);
+ }
rs = stmt.executeQuery(validateQuery);
return true;
} finally {
diff --git a/src/main/java/com/alibaba/druid/proxy/jdbc/ResultSetProxyImpl.java b/src/main/java/com/alibaba/druid/proxy/jdbc/ResultSetProxyImpl.java
index 9dfb94d9bf..7c8f2baec2 100644
--- a/src/main/java/com/alibaba/druid/proxy/jdbc/ResultSetProxyImpl.java
+++ b/src/main/java/com/alibaba/druid/proxy/jdbc/ResultSetProxyImpl.java
@@ -29,7 +29,6 @@ import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.RowId;
import java.sql.SQLException;
-import java.sql.SQLFeatureNotSupportedException;
import java.sql.SQLWarning;
import java.sql.SQLXML;
import java.sql.Statement;
@@ -1548,15 +1547,20 @@ public class ResultSetProxyImpl extends WrapperProxyImpl implements ResultSetPro
return result;
}
+ @Override
public T getObject(int columnIndex, Class type) throws SQLException {
FilterChainImpl chain = createChain();
- Object value = chain.resultSet_getObject(this, columnIndex, type);
+ T value = chain.resultSet_getObject(this, columnIndex, type);
recycleFilterChain(chain);
- return (T) value;
+ return value;
}
+ @Override
public T getObject(String columnLabel, Class type) throws SQLException {
- throw new SQLFeatureNotSupportedException();
+ FilterChainImpl chain = createChain();
+ T value = chain.resultSet_getObject(this, columnLabel, type);
+ recycleFilterChain(chain);
+ return value;
}
public int getCloseCount() {
@@ -1604,6 +1608,7 @@ public class ResultSetProxyImpl extends WrapperProxyImpl implements ResultSetPro
}
@SuppressWarnings("unchecked")
+ @Override
public T unwrap(Class iface) throws SQLException {
if (iface == ResultSetProxy.class || iface == ResultSetProxyImpl.class) {
return (T) this;
@@ -1612,6 +1617,7 @@ public class ResultSetProxyImpl extends WrapperProxyImpl implements ResultSetPro
return super.unwrap(iface);
}
+ @Override
public boolean isWrapperFor(Class> iface) throws SQLException {
if (iface == ResultSetProxy.class || iface == ResultSetProxyImpl.class) {
return true;
diff --git a/src/main/java/com/alibaba/druid/sql/PagerUtils.java b/src/main/java/com/alibaba/druid/sql/PagerUtils.java
index 38703b4f95..02cd006be5 100644
--- a/src/main/java/com/alibaba/druid/sql/PagerUtils.java
+++ b/src/main/java/com/alibaba/druid/sql/PagerUtils.java
@@ -402,6 +402,10 @@ public class PagerUtils {
if (limit != null) {
if (offset > 0) {
limit.setOffset(new SQLIntegerExpr(offset));
+ } else if (offset == 0) {
+ if (limit.getOffset() != null) {
+ limit.setOffset(new SQLIntegerExpr(offset));
+ }
}
if (check && limit.getRowCount() instanceof SQLNumericLiteralExpr) {
diff --git a/src/main/java/com/alibaba/druid/sql/ast/SQLObject.java b/src/main/java/com/alibaba/druid/sql/ast/SQLObject.java
index 2662201982..c37294767f 100644
--- a/src/main/java/com/alibaba/druid/sql/ast/SQLObject.java
+++ b/src/main/java/com/alibaba/druid/sql/ast/SQLObject.java
@@ -28,6 +28,7 @@ public interface SQLObject {
void setParent(SQLObject parent);
Map getAttributes();
+ boolean containsAttribute(String name);
Object getAttribute(String name);
void putAttribute(String name, Object value);
Map getAttributesDirect();
diff --git a/src/main/java/com/alibaba/druid/sql/ast/SQLObjectImpl.java b/src/main/java/com/alibaba/druid/sql/ast/SQLObjectImpl.java
index 8e4964d007..24e3022f71 100644
--- a/src/main/java/com/alibaba/druid/sql/ast/SQLObjectImpl.java
+++ b/src/main/java/com/alibaba/druid/sql/ast/SQLObjectImpl.java
@@ -88,6 +88,14 @@ public abstract class SQLObjectImpl implements SQLObject {
return attributes;
}
+ public boolean containsAttribute(String name) {
+ if (attributes == null) {
+ return false;
+ }
+
+ return attributes.containsKey(name);
+ }
+
public Object getAttribute(String name) {
if (attributes == null) {
return null;
diff --git a/src/main/java/com/alibaba/druid/sql/dialect/mysql/parser/MySqlStatementParser.java b/src/main/java/com/alibaba/druid/sql/dialect/mysql/parser/MySqlStatementParser.java
index 9a371211d1..52487cf070 100644
--- a/src/main/java/com/alibaba/druid/sql/dialect/mysql/parser/MySqlStatementParser.java
+++ b/src/main/java/com/alibaba/druid/sql/dialect/mysql/parser/MySqlStatementParser.java
@@ -87,6 +87,7 @@ import com.alibaba.druid.sql.ast.statement.SQLCreateProcedureStatement;
import com.alibaba.druid.sql.ast.statement.SQLCreateTableStatement;
import com.alibaba.druid.sql.ast.statement.SQLExprStatement;
import com.alibaba.druid.sql.ast.statement.SQLExprTableSource;
+import com.alibaba.druid.sql.ast.statement.SQLFetchStatement;
import com.alibaba.druid.sql.ast.statement.SQLIfStatement;
import com.alibaba.druid.sql.ast.statement.SQLInsertStatement;
import com.alibaba.druid.sql.ast.statement.SQLLoopStatement;
@@ -5542,4 +5543,33 @@ public class MySqlStatementParser extends SQLStatementParser {
return stmt;
}
+
+ /**
+ * FETCH [[NEXT] FROM] cursor_name INTO var_name [, var_name] ...
+ */
+ public SQLFetchStatement parseFetch() {
+ accept(Token.FETCH);
+
+ if (lexer.identifierEquals("NEXT")) {
+ lexer.nextToken();
+ accept(Token.FROM);
+ } else if (Token.FROM == lexer.token()) {
+ lexer.nextToken();
+ }
+
+ SQLFetchStatement stmt = new SQLFetchStatement();
+ stmt.setCursorName(this.exprParser.name());
+
+ accept(Token.INTO);
+ for (;;) {
+ stmt.getInto().add(this.exprParser.name());
+ if (lexer.token() == Token.COMMA) {
+ lexer.nextToken();
+ continue;
+ }
+ break;
+ }
+
+ return stmt;
+ }
}
diff --git a/src/main/java/com/alibaba/druid/sql/dialect/mysql/visitor/MySqlOutputVisitor.java b/src/main/java/com/alibaba/druid/sql/dialect/mysql/visitor/MySqlOutputVisitor.java
index 45573585f2..e2149b9f60 100644
--- a/src/main/java/com/alibaba/druid/sql/dialect/mysql/visitor/MySqlOutputVisitor.java
+++ b/src/main/java/com/alibaba/druid/sql/dialect/mysql/visitor/MySqlOutputVisitor.java
@@ -4412,7 +4412,7 @@ public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTV
@Override
public boolean visit(MySqlChecksumTableStatement x) {
print0(ucase ? "CHECKSUM TABLE " : "checksum table ");
- printAndAccept(x.getTables(), ",");
+ printAndAccept(x.getTables(), ", ");
return false;
}
} //
diff --git a/src/main/java/com/alibaba/druid/sql/visitor/SQLEvalVisitorUtils.java b/src/main/java/com/alibaba/druid/sql/visitor/SQLEvalVisitorUtils.java
index d91e2263df..3e5c5421c8 100644
--- a/src/main/java/com/alibaba/druid/sql/visitor/SQLEvalVisitorUtils.java
+++ b/src/main/java/com/alibaba/druid/sql/visitor/SQLEvalVisitorUtils.java
@@ -246,8 +246,8 @@ public class SQLEvalVisitorUtils {
if (function != null) {
Object result = function.eval(visitor, x);
- if (result != SQLEvalVisitor.EVAL_ERROR) {
- x.getAttributes().put(EVAL_VALUE, result);
+ if (result != SQLEvalVisitor.EVAL_ERROR && result != null) {
+ x.putAttribute(EVAL_VALUE, result);
}
return false;
}
@@ -744,7 +744,7 @@ public class SQLEvalVisitorUtils {
public static boolean visit(SQLEvalVisitor visitor, SQLInListExpr x) {
SQLExpr valueExpr = x.getExpr();
valueExpr.accept(visitor);
- if (!valueExpr.getAttributes().containsKey(EVAL_VALUE)) {
+ if (!valueExpr.containsAttribute(EVAL_VALUE)) {
return false;
}
Object value = valueExpr.getAttribute(EVAL_VALUE);
diff --git a/src/main/java/com/alibaba/druid/sql/visitor/functions/Concat.java b/src/main/java/com/alibaba/druid/sql/visitor/functions/Concat.java
index 275cffbe05..25c6259536 100644
--- a/src/main/java/com/alibaba/druid/sql/visitor/functions/Concat.java
+++ b/src/main/java/com/alibaba/druid/sql/visitor/functions/Concat.java
@@ -31,7 +31,7 @@ public class Concat implements Function {
for (SQLExpr item : x.getParameters()) {
item.accept(visitor);
- Object itemValue = item.getAttributes().get(EVAL_VALUE);
+ Object itemValue = item.getAttribute(EVAL_VALUE);
if (itemValue == null) {
return null;
}
diff --git a/src/main/java/com/alibaba/druid/sql/visitor/functions/Elt.java b/src/main/java/com/alibaba/druid/sql/visitor/functions/Elt.java
index 6f9daafbc8..35cf95dabf 100644
--- a/src/main/java/com/alibaba/druid/sql/visitor/functions/Elt.java
+++ b/src/main/java/com/alibaba/druid/sql/visitor/functions/Elt.java
@@ -41,7 +41,7 @@ public class Elt implements Function {
param0IntValue = ((Number) param0Value).intValue();
if (param0IntValue >= x.getParameters().size()) {
- return null;
+ return SQLEvalVisitor.EVAL_VALUE_NULL;
}
SQLExpr item = x.getParameters().get(param0IntValue);
diff --git a/src/main/java/com/alibaba/druid/wall/spi/WallVisitorUtils.java b/src/main/java/com/alibaba/druid/wall/spi/WallVisitorUtils.java
index 25219ff5b0..dfd9ac6fa9 100644
--- a/src/main/java/com/alibaba/druid/wall/spi/WallVisitorUtils.java
+++ b/src/main/java/com/alibaba/druid/wall/spi/WallVisitorUtils.java
@@ -288,6 +288,20 @@ public class WallVisitorUtils {
return;
}
+ List hints = x.getHintsDirect();
+ if (hints != null
+ && x.getParent() instanceof SQLUnionQuery
+ && x == ((SQLUnionQuery) x.getParent()).getRight()
+ ) {
+ for (SQLCommentHint hint : hints) {
+ String text = hint.getText();
+ if (text.startsWith("!")) {
+ addViolation(visitor, ErrorCode.UNION, "union select hint not allow", x);
+ return;
+ }
+ }
+ }
+
SQLExpr where = x.getWhere();
if (where != null) {
checkCondition(visitor, x.getWhere());
@@ -1559,7 +1573,7 @@ public class WallVisitorUtils {
}
public static Object getValue(WallVisitor visitor, SQLExpr x) {
- if (x != null && x.getAttributes().containsKey(EVAL_VALUE)) {
+ if (x != null && x.containsAttribute(EVAL_VALUE)) {
return getValueFromAttributes(visitor, x);
}
diff --git a/src/main/resources/support/http/resources/js/lang.js b/src/main/resources/support/http/resources/js/lang.js
index 690ce2c6b5..71c13dfbef 100644
--- a/src/main/resources/support/http/resources/js/lang.js
+++ b/src/main/resources/support/http/resources/js/lang.js
@@ -46,8 +46,8 @@ druid.lang = function() {
'DefaultAutoCommit' : ['DefaultAutoCommit', '默认autocommit设置'],
'DefaultReadOnly' : ['DefaultReadOnly', '默认只读设置'],
'DefaultTransactionIsolation' : ['DefaultTransactionIsolation', '默认事务隔离'],//
- 'NotEmptyWaitCount' : ['NotEmptyWaitCount', '等待次数'],//
- 'NotEmptyWaitMillis' : ['NotEmptyWaitMillis', '等待最大时长'],//
+ 'NotEmptyWaitCount' : ['NotEmptyWaitCount', '累计总次数'],//
+ 'NotEmptyWaitMillis' : ['NotEmptyWaitMillis', '等待总时长'],//
'WaitThreadCount' : ['WaitThreadCount', '等待线程数量'],
'StartTransactionCount' : ['StartTransactionCount', '事务启动数'],//
'TransactionHistogram' : ['TransactionHistogram', '事务时间分布'],//
@@ -98,8 +98,8 @@ druid.lang = function() {
'DefaultAutoCommitDesc' : ['', ''],
'DefaultReadOnlyDesc' : ['', ''],
'DefaultTransactionIsolationDesc' : ['', ''],
- 'NotEmptyWaitCountDesc' : ['Total times for wait to get a connection', '获取连接时最多等待多少次'],//
- 'NotEmptyWaitMillisDesc' : ['Total millins for wait to get a connection', '获取连接时最多等待多长时间'],
+ 'NotEmptyWaitCountDesc' : ['Total times for wait to get a connection', '获取连接时累计等待多少次'],//
+ 'NotEmptyWaitMillisDesc' : ['Total millis for wait to get a connection', '获取连接时累计等待多长时间'],
'WaitThreadCountDesc' : ['The current waiting thread count', '当前等待获取连接的线程数'],
'StartTransactionCountDesc' : ['The count of start transaction', '事务开始的个数'],
'TransactionHistogramDesc' : ['The histogram values of transaction time, [0-1 ms, 1-10 ms, 10-100 ms, 100-1 s, 1-10 s, 10-100 s, >100 s]', '事务运行时间分布,分布区间为[0-1 ms, 1-10 ms, 10-100 ms, 100-1 s, 1-10 s, 10-100 s, >100 s]'],
diff --git a/src/test/java/com/alibaba/druid/benckmark/pool/Case0.java b/src/test/java/com/alibaba/druid/benckmark/pool/Case0.java
index 286386dd12..618b560655 100644
--- a/src/test/java/com/alibaba/druid/benckmark/pool/Case0.java
+++ b/src/test/java/com/alibaba/druid/benckmark/pool/Case0.java
@@ -25,7 +25,6 @@ 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;
@@ -147,27 +146,7 @@ public class Case0 extends TestCase {
}
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);
diff --git a/src/test/java/com/alibaba/druid/benckmark/pool/Case1.java b/src/test/java/com/alibaba/druid/benckmark/pool/Case1.java
index 64cc32ad37..8d7eba3c06 100644
--- a/src/test/java/com/alibaba/druid/benckmark/pool/Case1.java
+++ b/src/test/java/com/alibaba/druid/benckmark/pool/Case1.java
@@ -30,16 +30,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.mock.MockDriver;
import com.alibaba.druid.pool.DruidDataSource;
import com.jolbox.bonecp.BoneCPDataSource;
import com.mchange.v2.c3p0.ComboPooledDataSource;
-import com.taobao.datasource.LocalTxDataSourceDO;
-import com.taobao.datasource.TaobaoDataSourceFactory;
-import com.taobao.datasource.resource.adapter.jdbc.local.LocalTxDataSource;
/**
* TestOnBo 类Case1.java的实现描述:TODO 类实现描述
@@ -116,26 +112,6 @@ public class Case1 extends TestCase {
System.out.println();
}
- public void test_jobss() throws Exception {
- LocalTxDataSourceDO dataSourceDO = new LocalTxDataSourceDO();
- dataSourceDO.setBlockingTimeoutMillis(1000 * 60);
- dataSourceDO.setMaxPoolSize(maxPoolSize);
- dataSourceDO.setMinPoolSize(minPoolSize);
-
- dataSourceDO.setDriverClass(driverClass);
- dataSourceDO.setConnectionURL(jdbcUrl);
- dataSourceDO.setUserName(user);
- dataSourceDO.setPassword(password);
-
- LocalTxDataSource tx = TaobaoDataSourceFactory.createLocalTxDataSource(dataSourceDO);
- DataSource dataSource = tx.getDatasource();
-
- for (int i = 0; i < loopCount; ++i) {
- p0(dataSource, "jboss-datasource", threadCount);
- }
- System.out.println();
- }
-
public void test_dbcp() throws Exception {
final BasicDataSource dataSource = new BasicDataSource();
@@ -204,26 +180,6 @@ public class Case1 extends TestCase {
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);
diff --git a/src/test/java/com/alibaba/druid/benckmark/pool/Case4.java b/src/test/java/com/alibaba/druid/benckmark/pool/Case4.java
deleted file mode 100644
index 6176a7ddc2..0000000000
--- a/src/test/java/com/alibaba/druid/benckmark/pool/Case4.java
+++ /dev/null
@@ -1,287 +0,0 @@
-/*
- * Copyright 1999-2018 Alibaba Group Holding Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.alibaba.druid.benckmark.pool;
-
-import java.lang.management.ManagementFactory;
-import java.lang.management.ThreadInfo;
-import java.text.NumberFormat;
-import java.util.concurrent.CountDownLatch;
-
-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.benckmark.pool.model.TableOperator;
-import com.alibaba.druid.pool.DruidDataSource;
-import com.jolbox.bonecp.BoneCPDataSource;
-import com.mchange.v2.c3p0.ComboPooledDataSource;
-import com.taobao.datasource.LocalTxDataSourceDO;
-import com.taobao.datasource.TaobaoDataSourceFactory;
-import com.taobao.datasource.resource.adapter.jdbc.local.LocalTxDataSource;
-
-/**
- * 测试各个连接池在进行批量插入时操作的性能
- *
- * @author yunnysunny[yunnysunny@gmail.com] 2013-3-18 下午01:11:40
- */
-public class Case4 extends TestCase {
-
- private String jdbcUrl;
- private String user;
- private String password;
- private String driverClass;
- private int initialSize = 10;
- private int minPoolSize = 10;
- private int maxPoolSize = 50;
- private int maxActive = 50;
- private String validationQuery = "SELECT 1";
- private int maxOpenPreparedStatements = 100;
- private int threadCount = 5;
- private int loopCount = 10;
- final int LOOP_COUNT = 100 * 1 * 1 / threadCount;
-
- protected void setUp() throws Exception {
- user = "root";
- password = "aaaaaaaa";
-
- jdbcUrl = "jdbc:mysql://localhost:3306/dragoon_v25_masterdb";
- driverClass = "com.mysql.jdbc.Driver";
- }
-
- public void test_druid() throws Exception {
- DruidDataSource dataSource = new DruidDataSource();
-
- dataSource.setInitialSize(initialSize);
- dataSource.setMaxActive(maxActive);
- dataSource.setMinIdle(minPoolSize);
- dataSource.setMaxIdle(maxPoolSize);
- dataSource.setPoolPreparedStatements(true);
- dataSource.setDriverClassName(driverClass);
- dataSource.setUrl(jdbcUrl);
- dataSource.setPoolPreparedStatements(true);
- dataSource.setMaxOpenPreparedStatements(maxOpenPreparedStatements);
- dataSource.setUsername(user);
- dataSource.setPassword(password);
- dataSource.setValidationQuery(validationQuery);
- dataSource.setTestOnBorrow(false);
-
- for (int i = 0; i < loopCount; ++i) {
- p0(dataSource, "druid", threadCount);
- }
- System.out.println();
- }
-
- public void test_jobss() throws Exception {
- LocalTxDataSourceDO dataSourceDO = new LocalTxDataSourceDO();
- dataSourceDO.setBlockingTimeoutMillis(1000 * 60);
- dataSourceDO.setMaxPoolSize(maxPoolSize);
- dataSourceDO.setMinPoolSize(minPoolSize);
-
- dataSourceDO.setDriverClass(driverClass);
- dataSourceDO.setConnectionURL(jdbcUrl);
- dataSourceDO.setUserName(user);
- dataSourceDO.setPassword(password);
-
- LocalTxDataSource tx = TaobaoDataSourceFactory.createLocalTxDataSource(dataSourceDO);
- DataSource dataSource = tx.getDatasource();
-
- for (int i = 0; i < loopCount; ++i) {
- p0(dataSource, "jboss-datasource", threadCount);
- }
- System.out.println();
- }
-
- public void test_dbcp() throws Exception {
- final BasicDataSource dataSource = new BasicDataSource();
-
- dataSource.setInitialSize(initialSize);
- dataSource.setMaxActive(maxActive);
- dataSource.setMinIdle(minPoolSize);
- dataSource.setMaxIdle(maxPoolSize);
- dataSource.setPoolPreparedStatements(true);
- dataSource.setDriverClassName(driverClass);
- dataSource.setUrl(jdbcUrl);
- dataSource.setPoolPreparedStatements(true);
- dataSource.setMaxOpenPreparedStatements(maxOpenPreparedStatements);
- dataSource.setUsername(user);
- dataSource.setPassword(password);
- dataSource.setValidationQuery("SELECT 1");
- dataSource.setTestOnBorrow(false);
-
- for (int i = 0; i < loopCount; ++i) {
- p0(dataSource, "dbcp", threadCount);
- }
- System.out.println();
- }
-
- public void test_bonecp() throws Exception {
- BoneCPDataSource dataSource = new BoneCPDataSource();
- // dataSource.(10);
- // dataSource.setMaxActive(50);
- dataSource.setMinConnectionsPerPartition(minPoolSize);
- dataSource.setMaxConnectionsPerPartition(maxPoolSize);
-
- dataSource.setDriverClass(driverClass);
- dataSource.setJdbcUrl(jdbcUrl);
- dataSource.setStatementsCacheSize(maxOpenPreparedStatements);
- dataSource.setServiceOrder("LIFO");
- // dataSource.setMaxOpenPreparedStatements(100);
- dataSource.setUsername(user);
- dataSource.setPassword(password);
- // dataSource.setConnectionTestStatement("SELECT 1");
- dataSource.setPartitionCount(1);
- dataSource.setAcquireIncrement(5);
- dataSource.setIdleConnectionTestPeriod(0L);
- // dataSource.setDisableConnectionTracking(true);
-
- for (int i = 0; i < loopCount; ++i) {
- p0(dataSource, "boneCP", threadCount);
- }
- 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.setMaxStatements(maxOpenPreparedStatements);
-
- 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.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 {
-
- final CountDownLatch startLatch = new CountDownLatch(1);
- final CountDownLatch endLatch = new CountDownLatch(threadCount);
- final CountDownLatch dumpLatch = new CountDownLatch(1);
-
- Thread[] threads = new Thread[threadCount];
- final TableOperator operator = new TableOperator();
- operator.setDataSource(dataSource);
- operator.createTable();
- for (int i = 0; i < threadCount; ++i) {
- Thread thread = new Thread() {
-
- public void run() {
- try {
- startLatch.await();
-
- for (int i = 0; i < LOOP_COUNT; ++i) {
- operator.insert();
- }
- } catch (Exception ex) {
- ex.printStackTrace();
- }
- endLatch.countDown();
-
- try {
- dumpLatch.await();
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
- };
- threads[i] = thread;
- thread.start();
- }
- long startMillis = System.currentTimeMillis();
- long startYGC = TestUtil.getYoungGC();
- long startFullGC = TestUtil.getFullGC();
- startLatch.countDown();
- endLatch.await();
-
- long[] threadIdArray = new long[threads.length];
- for (int i = 0; i < threads.length; ++i) {
- threadIdArray[i] = threads[i].getId();
- }
- ThreadInfo[] threadInfoArray = ManagementFactory.getThreadMXBean().getThreadInfo(threadIdArray);
-
- dumpLatch.countDown();
- operator.dropTable();
-
- long blockedCount = 0;
- long waitedCount = 0;
- for (int i = 0; i < threadInfoArray.length; ++i) {
- ThreadInfo threadInfo = threadInfoArray[i];
- blockedCount += threadInfo.getBlockedCount();
- waitedCount += threadInfo.getWaitedCount();
- }
-
- long millis = System.currentTimeMillis() - startMillis;
- long ygc = TestUtil.getYoungGC() - startYGC;
- long fullGC = TestUtil.getFullGC() - startFullGC;
-
- System.out.println("thread " + threadCount + " " + name + " millis : "
- + NumberFormat.getInstance().format(millis) + "; YGC " + ygc + " FGC " + fullGC
- + " blocked " + NumberFormat.getInstance().format(blockedCount) //
- + " waited " + NumberFormat.getInstance().format(waitedCount));
-
- }
-}
diff --git a/src/test/java/com/alibaba/druid/bvt/filter/wall/WallStatTest_select_2.java b/src/test/java/com/alibaba/druid/bvt/filter/wall/WallStatTest_select_2.java
new file mode 100644
index 0000000000..e34995f04c
--- /dev/null
+++ b/src/test/java/com/alibaba/druid/bvt/filter/wall/WallStatTest_select_2.java
@@ -0,0 +1,48 @@
+package com.alibaba.druid.bvt.filter.wall;
+
+import com.alibaba.druid.wall.WallContext;
+import com.alibaba.druid.wall.WallProvider;
+import com.alibaba.druid.wall.spi.MySqlWallProvider;
+import com.alibaba.druid.wall.spi.OracleWallProvider;
+import com.alibaba.druid.wall.spi.PGWallProvider;
+import com.alibaba.druid.wall.spi.SQLServerWallProvider;
+import junit.framework.TestCase;
+
+public class WallStatTest_select_2
+ extends TestCase {
+
+ private String sql = "SELECT *\n" +
+ "FROM `t`\n" +
+ "WHERE `t`.`col1` = '1'\n" +
+ " AND `t`.`col2` = 0\n" +
+ " AND CONCAT(t.col3, '_', t.col4) IN ('abc_def')";
+
+ protected void setUp() throws Exception {
+ WallContext.clearContext();
+ }
+
+ protected void tearDown() throws Exception {
+ WallContext.clearContext();
+ }
+
+ public void testMySql() throws Exception {
+ WallProvider provider = new MySqlWallProvider();
+ assertTrue(provider.checkValid(sql));
+ }
+
+ public void testOracle() throws Exception {
+ WallProvider provider = new OracleWallProvider();
+ assertTrue(provider.checkValid(sql));
+ }
+
+ public void testPG() throws Exception {
+ WallProvider provider = new PGWallProvider();
+ assertTrue(provider.checkValid(sql));
+ }
+
+ public void testSQLServer() throws Exception {
+ WallProvider provider = new SQLServerWallProvider();
+ assertTrue(provider.checkValid(sql));
+ }
+
+}
diff --git a/src/test/java/com/alibaba/druid/bvt/filter/wall/mysql/MySqlWallTest_union.java b/src/test/java/com/alibaba/druid/bvt/filter/wall/mysql/MySqlWallTest_union.java
index 78d173a53d..2989e9ab53 100644
--- a/src/test/java/com/alibaba/druid/bvt/filter/wall/mysql/MySqlWallTest_union.java
+++ b/src/test/java/com/alibaba/druid/bvt/filter/wall/mysql/MySqlWallTest_union.java
@@ -44,4 +44,21 @@ public class MySqlWallTest_union extends TestCase {
Assert.assertTrue(WallUtils.isValidateMySql("select f1, f2 from t where id=1 union select 'u1' as u1, 'u2' as u2", config)); // union select item has alias
}
+
+ public void testUnion2() throws Exception
+ {
+ assertFalse(
+ WallUtils.isValidateMySql("SELECT name, surname FROM users WHERE name='' UNION SELECT @@version, 'string1'")
+ );
+
+ assertFalse(
+ WallUtils.isValidateMySql("SELECT name, surname FROM users WHERE name='' UNION SELECT /*! @@version,*/ 'string1'")
+ );
+
+ assertFalse(
+ WallUtils.isValidateMySql("SELECT name, surname FROM users WHERE name=' ' UNION SELECT /*! (select table_name FROM information_schema.tables limit 1,1),*/ 'string1'")
+ );
+
+
+ }
}
diff --git a/src/test/java/com/alibaba/druid/bvt/pool/OnFatalErrorMaxActiveTest.java b/src/test/java/com/alibaba/druid/bvt/pool/OnFatalErrorMaxActiveTest.java
index 75f0b3e581..cfd16401bc 100644
--- a/src/test/java/com/alibaba/druid/bvt/pool/OnFatalErrorMaxActiveTest.java
+++ b/src/test/java/com/alibaba/druid/bvt/pool/OnFatalErrorMaxActiveTest.java
@@ -30,10 +30,10 @@ public class OnFatalErrorMaxActiveTest extends PoolTestCase {
Field field = DruidAbstractDataSource.class.getDeclaredField("onFatalError");
field.setAccessible(true);
- SQLException faltalError = new SQLException();
- {
+ SQLException faltalError = null;
+ for ( int i = 0; i < 2; i++) {
+ faltalError = new SQLException();
Connection conn = dataSource.getConnection();
-
Method method = DruidDataSource.class.getDeclaredMethod("handleFatalError", DruidPooledConnection.class, SQLException.class, String.class);
method.setAccessible(true);
method.invoke(dataSource, conn.unwrap(DruidPooledConnection.class), faltalError, "select 'x'");
diff --git a/src/test/java/com/alibaba/druid/bvt/pool/OnFatalErrorMaxActiveTest_1.java b/src/test/java/com/alibaba/druid/bvt/pool/OnFatalErrorMaxActiveTest_1.java
index 9df3475698..48b2c4c105 100644
--- a/src/test/java/com/alibaba/druid/bvt/pool/OnFatalErrorMaxActiveTest_1.java
+++ b/src/test/java/com/alibaba/druid/bvt/pool/OnFatalErrorMaxActiveTest_1.java
@@ -30,8 +30,9 @@ public class OnFatalErrorMaxActiveTest_1 extends PoolTestCase {
Field field = DruidAbstractDataSource.class.getDeclaredField("onFatalError");
field.setAccessible(true);
- SQLException faltalError = new SQLException();
- {
+ SQLException faltalError = null;
+ for ( int i = 0; i < 2; i++) {
+ faltalError = new SQLException();
Connection conn = dataSource.getConnection();
Method method = DruidDataSource.class.getDeclaredMethod("handleFatalError", DruidPooledConnection.class, SQLException.class, String.class);
diff --git a/src/test/java/com/alibaba/druid/bvt/sql/PagerUtilsTest_Limit_mysql_0.java b/src/test/java/com/alibaba/druid/bvt/sql/PagerUtilsTest_Limit_mysql_0.java
index 1363ae19f6..c155d78d80 100644
--- a/src/test/java/com/alibaba/druid/bvt/sql/PagerUtilsTest_Limit_mysql_0.java
+++ b/src/test/java/com/alibaba/druid/bvt/sql/PagerUtilsTest_Limit_mysql_0.java
@@ -41,4 +41,12 @@ public class PagerUtilsTest_Limit_mysql_0 extends TestCase {
"\nORDER BY id, name" + //
"\nLIMIT 20, 10", result);
}
+
+ public void test_mysql_4() throws Exception {
+ String sql = "select id, name, salary from t limit 100 offset 5";
+ String result = PagerUtils.limit(sql, JdbcConstants.MYSQL, 0, 20);
+ Assert.assertEquals("SELECT id, name, salary" + //
+ "\nFROM t" + //
+ "\nLIMIT 0, 20", result);
+ }
}
diff --git a/src/test/java/com/alibaba/druid/bvt/sql/PagerUtilsTest_Limit_mysql_question_placeholder.java b/src/test/java/com/alibaba/druid/bvt/sql/PagerUtilsTest_Limit_mysql_question_placeholder.java
index 44ec2a79f0..59204a88b7 100644
--- a/src/test/java/com/alibaba/druid/bvt/sql/PagerUtilsTest_Limit_mysql_question_placeholder.java
+++ b/src/test/java/com/alibaba/druid/bvt/sql/PagerUtilsTest_Limit_mysql_question_placeholder.java
@@ -20,7 +20,7 @@ public class PagerUtilsTest_Limit_mysql_question_placeholder extends TestCase {
}
public void testQuestionLimitPlaceholder2(){
- String sql = "select * from test_table limit ?, ?";
+ String sql = "select * from test_table limit 0, ?";
testQuestionLimitPlaceholderInternal(sql);
}
diff --git a/src/test/java/com/alibaba/druid/pool/bonecp/TestLRU.java b/src/test/java/com/alibaba/druid/pool/bonecp/TestLRU.java
index a744c2dae5..3078717683 100644
--- a/src/test/java/com/alibaba/druid/pool/bonecp/TestLRU.java
+++ b/src/test/java/com/alibaba/druid/pool/bonecp/TestLRU.java
@@ -23,7 +23,6 @@ import javax.sql.DataSource;
import junit.framework.TestCase;
import org.apache.commons.dbcp.BasicDataSource;
-import org.logicalcobwebs.proxool.ProxoolDataSource;
import com.alibaba.druid.mock.MockConnection;
import com.alibaba.druid.pool.DruidDataSource;
@@ -80,22 +79,7 @@ public class TestLRU extends TestCase {
System.out.println("--------------------------------------------");
}
}
-
- public void f_test_proxool() throws Exception {
- ProxoolDataSource ds = new ProxoolDataSource();
- ds.setDriver("com.alibaba.druid.mock.MockDriver");
- ds.setDriverUrl("jdbc:mock:test");
- ds.setMaximumConnectionCount(10);
- ds.setMinimumConnectionCount(0);
- ds.setUser("user");
- ds.setPassword("password");
-
- for (int i = 0; i < 10; ++i) {
- f(ds, 5);
- System.out.println("--------------------------------------------");
- }
- }
-
+
// public void test_jboss() throws Exception {
// LocalTxDataSource ds = new LocalTxDataSource();
// ds.setDriverClass("com.alibaba.druid.mock.MockDriver");
diff --git a/src/test/java/com/alibaba/druid/pool/bonecp/TestPSCache.java b/src/test/java/com/alibaba/druid/pool/bonecp/TestPSCache.java
index 7f22bb45e9..af75c2a6b7 100644
--- a/src/test/java/com/alibaba/druid/pool/bonecp/TestPSCache.java
+++ b/src/test/java/com/alibaba/druid/pool/bonecp/TestPSCache.java
@@ -24,7 +24,6 @@ import javax.sql.DataSource;
import junit.framework.TestCase;
import org.apache.commons.dbcp.BasicDataSource;
-import org.logicalcobwebs.proxool.ProxoolDataSource;
import com.alibaba.druid.mock.MockConnection;
import com.alibaba.druid.mock.MockPreparedStatement;
@@ -88,21 +87,6 @@ public class TestPSCache extends TestCase {
}
}
- public void f_test_proxool() throws Exception {
- ProxoolDataSource ds = new ProxoolDataSource();
- ds.setDriver("com.alibaba.druid.mock.MockDriver");
- ds.setDriverUrl("jdbc:mock:test");
- ds.setMaximumConnectionCount(10);
- ds.setMinimumConnectionCount(0);
- ds.setUser("user");
- ds.setPassword("password");
-
- for (int i = 0; i < 10; ++i) {
- f(ds, 5);
- System.out.println("--------------------------------------------");
- }
- }
-
public static void f(DataSource ds, int count) throws Exception {
Connection conn = ds.getConnection();