完善mock和测试

git-svn-id: http://code.alibabatech.com/svn/druid/trunk@837 b9813039-fb51-4c41-a8b9-e21c2acb5095
This commit is contained in:
wenshao
2011-09-18 07:28:26 +00:00
parent a5d592933b
commit 49625315cf
2 changed files with 57 additions and 18 deletions
@@ -799,7 +799,7 @@ public abstract class DruidAbstractDataSource extends WrapperAdapter implements
}
}
protected void validateConnection(Connection conn) throws SQLException {
public void validateConnection(Connection conn) throws SQLException {
String query = getValidationQuery();
if (conn.isClosed()) {
throw new SQLException("validateConnection: connection closed");
@@ -814,31 +814,19 @@ public abstract class DruidAbstractDataSource extends WrapperAdapter implements
if (null != query) {
Statement stmt = null;
ResultSet rset = null;
ResultSet rs = null;
try {
stmt = conn.createStatement();
if (getValidationQueryTimeout() > 0) {
stmt.setQueryTimeout(getValidationQueryTimeout());
}
rset = stmt.executeQuery(query);
if (!rset.next()) {
rs = stmt.executeQuery(query);
if (!rs.next()) {
throw new SQLException("validationQuery didn't return a row");
}
} finally {
if (rset != null) {
try {
rset.close();
} catch (Exception t) {
// ignored
}
}
if (stmt != null) {
try {
stmt.close();
} catch (Exception t) {
// ignored
}
}
JdbcUtils.close(rs);
JdbcUtils.close(stmt);
}
}
}