add testcase

This commit is contained in:
wenshao
2013-06-17 00:34:41 +08:00
parent da433839ee
commit b199d3043f
81 changed files with 2493 additions and 693 deletions
@@ -16,6 +16,7 @@
package com.alibaba.druid.mock;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.Reader;
@@ -26,6 +27,7 @@ import java.sql.SQLException;
public class MockClob implements Clob {
private byte[] bytes;
private ByteArrayOutputStream out = new ByteArrayOutputStream();
public MockClob(){
this(new byte[0]);
@@ -81,7 +83,7 @@ public class MockClob implements Clob {
@Override
public OutputStream setAsciiStream(long pos) throws SQLException {
return null;
return out;
}
@Override
@@ -318,10 +318,10 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
transactionHistogram.reset();
cachedPreparedStatementDeleteCount.set(0);
recycleErrorCount.set(0);
resetCount.incrementAndGet();
}
public long getResetCount() {
return this.resetCount.get();
}
@@ -1445,19 +1445,19 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
lock.lock();
try {
value.poolingCount = this.poolingCount;
value.poolingPeak = this.poolingPeak;
value.poolingPeakTime = this.poolingPeakTime;
value.setPoolingCount(this.poolingCount);
value.setPoolingPeak(this.poolingPeak);
value.setPoolingPeakTime(this.poolingPeakTime);
value.activeCount = this.activeCount;
value.activePeak = this.activePeak;
value.activePeakTime = this.activePeakTime;
value.setActiveCount(this.activeCount);
value.setActivePeak(this.activePeak);
value.setActivePeakTime(this.activePeakTime);
value.connectCount = this.connectCount;
value.closeCount = this.closeCount;
value.waitThreadCount = lock.getWaitQueueLength(notEmpty);
value.notEmptyWaitCount = this.notEmptyWaitCount;
value.notEmptyWaitNanos = this.notEmptyWaitNanos;
value.setConnectCount(this.connectCount);
value.setCloseCount(this.closeCount);
value.setWaitThreadCount(lock.getWaitQueueLength(notEmpty));
value.setNotEmptyWaitCount(this.notEmptyWaitCount);
value.setNotEmptyWaitNanos(this.notEmptyWaitNanos);
// reset
this.poolingPeak = 0;
@@ -1473,56 +1473,56 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
lock.unlock();
}
value.name = this.getName();
value.dbType = this.getDbType();
value.driverClassName = this.getDriverClassName();
value.setName(this.getName());
value.setDbType(this.getDbType());
value.setDriverClassName(this.getDriverClassName());
value.url = this.getUrl();
value.userName = this.getUsername();
value.filterClassNames = this.getFilterClassNames();
value.setUrl(this.getUrl());
value.setUserName(this.getUsername());
value.setFilterClassNames(this.getFilterClassNames());
value.initialSize = this.getInitialSize();
value.minIdle = this.getMinIdle();
value.maxActive = this.getMaxActive();
value.setInitialSize(this.getInitialSize());
value.setMinIdle(this.getMinIdle());
value.setMaxActive(this.getMaxActive());
value.queryTimeout = this.getQueryTimeout();
value.transactionQueryTimeout = this.getTransactionQueryTimeout();
value.loginTimeout = this.getLoginTimeout();
value.validConnectionCheckerClassName = this.getValidConnectionCheckerClassName();
value.exceptionSorterClassName = this.getExceptionSorterClassName();
value.setQueryTimeout(this.getQueryTimeout());
value.setTransactionQueryTimeout(this.getTransactionQueryTimeout());
value.setLoginTimeout(this.getLoginTimeout());
value.setValidConnectionCheckerClassName(this.getValidConnectionCheckerClassName());
value.setExceptionSorterClassName(this.getExceptionSorterClassName());
value.testOnBorrow = this.isTestOnBorrow();
value.testOnReturn = this.isTestOnReturn();
value.testWhileIdle = this.isTestWhileIdle();
value.setTestOnBorrow(this.isTestOnBorrow());
value.setTestOnReturn(this.isTestOnReturn());
value.setTestWhileIdle(this.isTestWhileIdle());
value.defaultAutoCommit = this.isDefaultAutoCommit();
value.defaultReadOnly = this.isDefaultAutoCommit();
value.defaultTransactionIsolation = this.getDefaultTransactionIsolation();
value.setDefaultAutoCommit(this.isDefaultAutoCommit());
value.setDefaultReadOnly(this.isDefaultAutoCommit());
value.setDefaultTransactionIsolation(this.getDefaultTransactionIsolation());
value.logicConnectErrorCount = connectErrorCount.getAndSet(0);
value.setLogicConnectErrorCount(connectErrorCount.getAndSet(0));
value.physicalConnectCount = createCount.getAndSet(0);
value.physicalCloseCount = destroyCount.getAndSet(0);
value.physicalConnectErrorCount = createErrorCount.getAndSet(0);
value.setPhysicalConnectCount(createCount.getAndSet(0));
value.setPhysicalCloseCount(destroyCount.getAndSet(0));
value.setPhysicalConnectErrorCount(createErrorCount.getAndSet(0));
value.executeCount = this.executeCount.getAndSet(0);
value.errorCount = errorCount.getAndSet(0);
value.commitCount = commitCount.getAndSet(0);
value.rollbackCount = rollbackCount.getAndSet(0);
value.setExecuteCount(this.executeCount.getAndSet(0));
value.setErrorCount(errorCount.getAndSet(0));
value.setCommitCount(commitCount.getAndSet(0));
value.setRollbackCount(rollbackCount.getAndSet(0));
value.pstmtCacheHitCount = cachedPreparedStatementHitCount.getAndSet(0);
value.pstmtCacheMissCount = cachedPreparedStatementMissCount.getAndSet(0);
value.setPstmtCacheHitCount(cachedPreparedStatementHitCount.getAndSet(0));
value.setPstmtCacheMissCount(cachedPreparedStatementMissCount.getAndSet(0));
value.startTransactionCount = startTransactionCount.getAndSet(0);
value.transactionHistogram = this.getTransactionHistogram().toArrayAndReset();
value.setStartTransactionCount(startTransactionCount.getAndSet(0));
value.setTransactionHistogram(this.getTransactionHistogram().toArrayAndReset());
value.connectionHoldTimeHistogram = this.getDataSourceStat().getConnectionHoldHistogram().toArrayAndReset();
value.setConnectionHoldTimeHistogram(this.getDataSourceStat().getConnectionHoldHistogram().toArrayAndReset());
value.removeAbandoned = this.isRemoveAbandoned();
value.clobOpenCount = this.getDataSourceStat().getClobOpenCountAndReset();
value.blobOpenCount = this.getDataSourceStat().getBlobOpenCountAndReset();
value.setClobOpenCount(this.getDataSourceStat().getClobOpenCountAndReset());
value.setBlobOpenCount(this.getDataSourceStat().getBlobOpenCountAndReset());
value.sqlSkipCount = this.getDataSourceStat().getSkipSqlCountAndReset();
value.sqlList = this.getDataSourceStat().getSqlStatMapAndReset();
value.setSqlSkipCount(this.getDataSourceStat().getSkipSqlCountAndReset());
value.setSqlList(this.getDataSourceStat().getSqlStatMapAndReset());
return value;
}
@@ -17,10 +17,8 @@ package com.alibaba.druid.pool;
import java.util.Date;
import java.util.List;
import java.util.Map;
import com.alibaba.druid.stat.JdbcSqlStatValue;
import com.alibaba.druid.support.json.JSONUtils;
public class DruidDataSourceStatValue {
@@ -81,27 +79,6 @@ public class DruidDataSourceStatValue {
protected List<JdbcSqlStatValue> sqlList;
@SuppressWarnings("unchecked")
public void fromJSON(String json) {
// protected String dbType;
// protected String driverClassName;
// protected String url;
// protected String userName;
// protected List<String> filterClassNames;
// protected boolean removeAbandoned;
//
Map<String, Object> map = (Map<String, Object>) JSONUtils.parse(json);
fromJSON(map);
}
public void fromJSON(Map<String, Object> map) {
this.name = (String) map.get("name");
this.dbType = (String) map.get("dbType");
this.driverClassName = (String) map.get("driverClassName");
this.url = (String) map.get("url");
this.userName = (String) map.get("userName");
}
public Date getPoolingPeakTime() {
if (poolingPeakTime <= 0) {
return null;
@@ -44,18 +44,6 @@ public class SQLBetweenExpr extends SQLExprImpl implements Serializable {
this.not = not;
}
public void output(StringBuffer buf) {
this.testExpr.output(buf);
if (this.not) {
buf.append(" NOT BETWEEN ");
} else {
buf.append(" BETWEEN ");
}
this.beginExpr.output(buf);
buf.append(" AND ");
this.endExpr.output(buf);
}
protected void accept0(SQLASTVisitor visitor) {
if (visitor.visit(this)) {
acceptChild(visitor, this.testExpr);
@@ -35,29 +35,6 @@ public class SQLCaseExpr extends SQLExprImpl implements Serializable {
}
public void output(StringBuffer buf) {
buf.append("CASE ");
if (this.valueExpr != null) {
this.valueExpr.output(buf);
buf.append(" ");
}
int i = 0;
for (int size = this.items.size(); i < size; ++i) {
if (i != 0) {
buf.append(" ");
}
((Item) this.items.get(i)).output(buf);
}
if (this.elseExpr != null) {
buf.append(" ELSE ");
this.elseExpr.output(buf);
}
buf.append(" END");
}
public SQLExpr getValueExpr() {
return this.valueExpr;
}
@@ -138,13 +115,6 @@ public class SQLCaseExpr extends SQLExprImpl implements Serializable {
this.valueExpr = valueExpr;
}
public void output(StringBuffer buf) {
buf.append("WHEN ");
this.conditionExpr.output(buf);
buf.append(" THEN ");
this.valueExpr.output(buf);
}
protected void accept0(SQLASTVisitor visitor) {
if (visitor.visit(this)) {
acceptChild(visitor, this.conditionExpr);
@@ -152,6 +122,31 @@ public class SQLCaseExpr extends SQLExprImpl implements Serializable {
}
visitor.endVisit(this);
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((conditionExpr == null) ? 0 : conditionExpr.hashCode());
result = prime * result + ((valueExpr == null) ? 0 : valueExpr.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (obj == null) return false;
if (getClass() != obj.getClass()) return false;
Item other = (Item) obj;
if (conditionExpr == null) {
if (other.conditionExpr != null) return false;
} else if (!conditionExpr.equals(other.conditionExpr)) return false;
if (valueExpr == null) {
if (other.valueExpr != null) return false;
} else if (!valueExpr.equals(other.valueExpr)) return false;
return true;
}
}
@Override
@@ -32,13 +32,11 @@ public class SQLExistsExpr extends SQLExprImpl implements Serializable {
}
public SQLExistsExpr(SQLSelect subQuery){
this.subQuery = subQuery;
this.setSubQuery(subQuery);
}
public SQLExistsExpr(SQLSelect subQuery, boolean not){
this.subQuery = subQuery;
this.setSubQuery(subQuery);
this.not = not;
}
@@ -55,16 +53,10 @@ public class SQLExistsExpr extends SQLExprImpl implements Serializable {
}
public void setSubQuery(SQLSelect subQuery) {
this.subQuery = subQuery;
}
public void output(StringBuffer buf) {
if (this.not) {
buf.append("NOT ");
if (subQuery != null) {
subQuery.setParent(this);
}
buf.append("EXISTS (");
this.subQuery.output(buf);
buf.append(")");
this.subQuery = subQuery;
}
protected void accept0(SQLASTVisitor visitor) {
@@ -21,17 +21,17 @@ import com.alibaba.druid.sql.visitor.SQLASTVisitor;
public class SQLSelect extends SQLObjectImpl {
private static final long serialVersionUID = 1L;
private static final long serialVersionUID = 1L;
protected SQLWithSubqueryClause withSubQuery;
protected SQLSelectQuery query;
protected SQLOrderBy orderBy;
protected SQLSelectQuery query;
protected SQLOrderBy orderBy;
public SQLSelect(){
}
public SQLSelect(SQLSelectQuery query) {
public SQLSelect(SQLSelectQuery query){
this.setQuery(query);
}
@@ -62,15 +62,6 @@ public class SQLSelect extends SQLObjectImpl {
this.orderBy = orderBy;
}
public void output(StringBuffer buf) {
this.query.output(buf);
buf.append(" ");
if (this.orderBy != null) {
this.orderBy.output(buf);
}
}
protected void accept0(SQLASTVisitor visitor) {
if (visitor.visit(this)) {
acceptChild(visitor, this.query);
@@ -80,4 +71,32 @@ public class SQLSelect extends SQLObjectImpl {
visitor.endVisit(this);
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((orderBy == null) ? 0 : orderBy.hashCode());
result = prime * result + ((query == null) ? 0 : query.hashCode());
result = prime * result + ((withSubQuery == null) ? 0 : withSubQuery.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (obj == null) return false;
if (getClass() != obj.getClass()) return false;
SQLSelect other = (SQLSelect) obj;
if (orderBy == null) {
if (other.orderBy != null) return false;
} else if (!orderBy.equals(other.orderBy)) return false;
if (query == null) {
if (other.query != null) return false;
} else if (!query.equals(other.query)) return false;
if (withSubQuery == null) {
if (other.withSubQuery != null) return false;
} else if (!withSubQuery.equals(other.withSubQuery)) return false;
return true;
}
}
@@ -19,7 +19,6 @@ import java.util.ArrayList;
import java.util.List;
import com.alibaba.druid.sql.ast.SQLExpr;
import com.alibaba.druid.sql.ast.SQLSetQuantifier;
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
public class SQLSelectQueryBlock extends SQLSelectQuery {
@@ -103,40 +102,42 @@ public class SQLSelectQueryBlock extends SQLSelectQuery {
visitor.endVisit(this);
}
public void output(StringBuffer buf) {
buf.append("SELECT ");
if (SQLSetQuantifier.ALL == this.distionOption) {
buf.append("ALL ");
} else if (SQLSetQuantifier.DISTINCT == this.distionOption) {
buf.append("DISTINCT ");
} else if (SQLSetQuantifier.UNIQUE == this.distionOption) {
buf.append("UNIQUE ");
}
int i = 0;
for (int size = this.selectList.size(); i < size; ++i) {
if (i != 0) {
buf.append(", ");
}
((SQLSelectItem) this.selectList.get(i)).output(buf);
}
buf.append(" FROM ");
if (this.from == null) {
buf.append("DUAL");
} else {
this.from.output(buf);
}
if (this.where != null) {
buf.append(" WHERE ");
this.where.output(buf);
}
if (this.groupBy != null) {
buf.append(" ");
this.groupBy.output(buf);
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + distionOption;
result = prime * result + ((from == null) ? 0 : from.hashCode());
result = prime * result + ((groupBy == null) ? 0 : groupBy.hashCode());
result = prime * result + ((into == null) ? 0 : into.hashCode());
result = prime * result + ((selectList == null) ? 0 : selectList.hashCode());
result = prime * result + ((where == null) ? 0 : where.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (obj == null) return false;
if (getClass() != obj.getClass()) return false;
SQLSelectQueryBlock other = (SQLSelectQueryBlock) obj;
if (distionOption != other.distionOption) return false;
if (from == null) {
if (other.from != null) return false;
} else if (!from.equals(other.from)) return false;
if (groupBy == null) {
if (other.groupBy != null) return false;
} else if (!groupBy.equals(other.groupBy)) return false;
if (into == null) {
if (other.into != null) return false;
} else if (!into.equals(other.into)) return false;
if (selectList == null) {
if (other.selectList != null) return false;
} else if (!selectList.equals(other.selectList)) return false;
if (where == null) {
if (other.where != null) return false;
} else if (!where.equals(other.where)) return false;
return true;
}
}
@@ -35,5 +35,6 @@ public class MySqlBinlogStatement extends MySqlStatementImpl {
if (visitor.visit(this)) {
acceptChild(visitor, expr);
}
visitor.endVisit(this);
}
}
@@ -41,6 +41,7 @@ public class MySqlCreateUserStatement extends MySqlStatementImpl {
if (visitor.visit(this)) {
acceptChild(visitor, users);
}
visitor.endVisit(this);
}
public static class UserSpecification extends MySqlObjectImpl {
@@ -82,6 +83,7 @@ public class MySqlCreateUserStatement extends MySqlStatementImpl {
acceptChild(visitor, password);
acceptChild(visitor, authPlugin);
}
visitor.endVisit(this);
}
}
@@ -39,5 +39,6 @@ public class MySqlDropUser extends MySqlStatementImpl {
if (visitor.visit(this)) {
acceptChild(visitor, users);
}
visitor.endVisit(this);
}
}
@@ -47,5 +47,6 @@ public class MySqlKillStatement extends MySqlStatementImpl {
if (visitor.visit(this)) {
acceptChild(visitor, threadId);
}
visitor.endVisit(this);
}
}
@@ -35,5 +35,6 @@ public class MySqlResetStatement extends MySqlStatementImpl {
public void accept0(MySqlASTVisitor visitor) {
visitor.visit(this);
visitor.endVisit(this);
}
}
@@ -55,12 +55,12 @@ public class MySqlSelectQueryBlock extends SQLSelectQueryBlock implements MySqlO
public MySqlSelectQueryBlock(){
}
public int getHintsSize() {
if (hints == null) {
return 0;
}
return hints.size();
}
@@ -185,6 +185,62 @@ public class MySqlSelectQueryBlock extends SQLSelectQueryBlock implements MySqlO
this.limit = limit;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + (bigResult ? 1231 : 1237);
result = prime * result + (bufferResult ? 1231 : 1237);
result = prime * result + ((cache == null) ? 0 : cache.hashCode());
result = prime * result + (calcFoundRows ? 1231 : 1237);
result = prime * result + (forUpdate ? 1231 : 1237);
result = prime * result + (hignPriority ? 1231 : 1237);
result = prime * result + ((hints == null) ? 0 : hints.hashCode());
result = prime * result + ((limit == null) ? 0 : limit.hashCode());
result = prime * result + (lockInShareMode ? 1231 : 1237);
result = prime * result + ((orderBy == null) ? 0 : orderBy.hashCode());
result = prime * result + ((procedureArgumentList == null) ? 0 : procedureArgumentList.hashCode());
result = prime * result + ((procedureName == null) ? 0 : procedureName.hashCode());
result = prime * result + (smallResult ? 1231 : 1237);
result = prime * result + (straightJoin ? 1231 : 1237);
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (obj == null) return false;
if (getClass() != obj.getClass()) return false;
MySqlSelectQueryBlock other = (MySqlSelectQueryBlock) obj;
if (bigResult != other.bigResult) return false;
if (bufferResult != other.bufferResult) return false;
if (cache == null) {
if (other.cache != null) return false;
} else if (!cache.equals(other.cache)) return false;
if (calcFoundRows != other.calcFoundRows) return false;
if (forUpdate != other.forUpdate) return false;
if (hignPriority != other.hignPriority) return false;
if (hints == null) {
if (other.hints != null) return false;
} else if (!hints.equals(other.hints)) return false;
if (limit == null) {
if (other.limit != null) return false;
} else if (!limit.equals(other.limit)) return false;
if (lockInShareMode != other.lockInShareMode) return false;
if (orderBy == null) {
if (other.orderBy != null) return false;
} else if (!orderBy.equals(other.orderBy)) return false;
if (procedureArgumentList == null) {
if (other.procedureArgumentList != null) return false;
} else if (!procedureArgumentList.equals(other.procedureArgumentList)) return false;
if (procedureName == null) {
if (other.procedureName != null) return false;
} else if (!procedureName.equals(other.procedureName)) return false;
if (smallResult != other.smallResult) return false;
if (straightJoin != other.straightJoin) return false;
return true;
}
@Override
protected void accept0(SQLASTVisitor visitor) {
if (visitor instanceof MySqlASTVisitor) {
@@ -258,6 +314,7 @@ public class MySqlSelectQueryBlock extends SQLSelectQueryBlock implements MySqlO
acceptChild(visitor, offset);
acceptChild(visitor, rowCount);
}
mysqlVisitor.endVisit(this);
}
}
@@ -20,13 +20,12 @@ import java.util.List;
import com.alibaba.druid.sql.ast.SQLExpr;
import com.alibaba.druid.sql.ast.SQLName;
import com.alibaba.druid.sql.ast.SQLObjectImpl;
import com.alibaba.druid.sql.ast.statement.SQLTableElement;
import com.alibaba.druid.sql.dialect.mysql.ast.MySqlObjectImpl;
import com.alibaba.druid.sql.dialect.mysql.visitor.MySqlASTVisitor;
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
@SuppressWarnings("serial")
public class MySqlTableIndex extends SQLObjectImpl implements SQLTableElement {
public class MySqlTableIndex extends MySqlObjectImpl implements SQLTableElement {
private SQLName name;
private String indexType;
@@ -56,21 +55,7 @@ public class MySqlTableIndex extends SQLObjectImpl implements SQLTableElement {
return columns;
}
@Override
protected void accept0(SQLASTVisitor visitor) {
if (visitor instanceof MySqlASTVisitor) {
accept0((MySqlASTVisitor) visitor);
return;
}
if (visitor.visit(this)) {
acceptChild(visitor, name);
acceptChild(visitor, columns);
}
visitor.endVisit(this);
}
protected void accept0(MySqlASTVisitor visitor) {
public void accept0(MySqlASTVisitor visitor) {
if (visitor.visit(this)) {
acceptChild(visitor, name);
acceptChild(visitor, columns);
@@ -40,6 +40,7 @@ public class ModelClause extends OracleSQLObjectImpl {
acceptChild(visitor, referenceModelClauses);
acceptChild(visitor, mainModel);
}
visitor.endVisit(this);
}
public MainModelClause getMainModel() {
@@ -104,6 +105,7 @@ public class ModelClause extends OracleSQLObjectImpl {
@Override
public void accept0(OracleASTVisitor visitor) {
visitor.visit(this);
visitor.endVisit(this);
}
}
@@ -179,6 +181,7 @@ public class ModelClause extends OracleSQLObjectImpl {
acceptChild(visitor, dimensionByColumns);
acceptChild(visitor, measuresColumns);
}
visitor.endVisit(this);
}
}
@@ -211,6 +214,7 @@ public class ModelClause extends OracleSQLObjectImpl {
if (visitor.visit(this)) {
acceptChild(visitor, expr);
}
visitor.endVisit(this);
}
}
@@ -281,6 +285,7 @@ public class ModelClause extends OracleSQLObjectImpl {
acceptChild(visitor, modelColumnClause);
acceptChild(visitor, modelRulesClause);
}
visitor.endVisit(this);
}
}
@@ -324,6 +329,7 @@ public class ModelClause extends OracleSQLObjectImpl {
acceptChild(visitor, until);
acceptChild(visitor, cellAssignmentItems);
}
visitor.endVisit(this);
}
}
@@ -391,6 +397,7 @@ public class ModelClause extends OracleSQLObjectImpl {
acceptChild(visitor, orderBy);
acceptChild(visitor, expr);
}
visitor.endVisit(this);
}
}
@@ -419,6 +426,7 @@ public class ModelClause extends OracleSQLObjectImpl {
acceptChild(visitor, measureColumn);
acceptChild(visitor, conditions);
}
visitor.endVisit(this);
}
}
@@ -52,6 +52,7 @@ public class OracleCursorExpr extends SQLExprImpl implements OracleExpr {
if (visitor.visit(this)) {
acceptChild(visitor, query);
}
visitor.endVisit(this);
}
@Override
@@ -51,6 +51,7 @@ public class OracleIsSetExpr extends SQLExprImpl implements OracleExpr {
if (visitor.visit(this)) {
acceptChild(visitor, nestedTable);
}
visitor.endVisit(this);
}
@Override
@@ -729,6 +729,7 @@ public class OracleSelectParser extends SQLSelectParser {
if (identifierEquals("ONLY")) {
lexer.nextToken();
tableReference.setOnly(true);
accept(Token.LPAREN);
parseTableSourceQueryTableExpr(tableReference);
accept(Token.RPAREN);
@@ -179,7 +179,7 @@ public class OracleOutputVisitor extends SQLASTOutputVisitor implements OracleAS
}
public void postVisit(SQLObject x) {
if (!printPostSemi) {
if (!isPrintPostSemi()) {
return;
}
@@ -93,10 +93,8 @@ import com.alibaba.druid.sql.ast.statement.SQLSelectQueryBlock;
import com.alibaba.druid.sql.ast.statement.SQLSelectStatement;
import com.alibaba.druid.sql.ast.statement.SQLSetStatement;
import com.alibaba.druid.sql.ast.statement.SQLSubqueryTableSource;
import com.alibaba.druid.sql.ast.statement.SQLTableElement;
import com.alibaba.druid.sql.ast.statement.SQLTruncateStatement;
import com.alibaba.druid.sql.ast.statement.SQLUnionQuery;
import com.alibaba.druid.sql.ast.statement.SQLUniqueConstraint;
import com.alibaba.druid.sql.ast.statement.SQLUpdateSetItem;
import com.alibaba.druid.sql.ast.statement.SQLUpdateStatement;
import com.alibaba.druid.sql.ast.statement.SQLUseStatement;
@@ -232,10 +230,6 @@ public interface SQLASTVisitor {
void endVisit(SQLCreateTableStatement x);
boolean visit(SQLTableElement x);
void endVisit(SQLTableElement x);
boolean visit(SQLColumnDefinition x);
void endVisit(SQLColumnDefinition x);
@@ -276,10 +270,6 @@ public interface SQLASTVisitor {
void endVisit(SQLCreateViewStatement x);
boolean visit(SQLUniqueConstraint x);
void endVisit(SQLUniqueConstraint x);
boolean visit(NotNullConstraint x);
void endVisit(NotNullConstraint x);
@@ -455,7 +445,7 @@ public interface SQLASTVisitor {
boolean visit(SQLExprHint x);
void endVisit(SQLExprHint x);
boolean visit(SQLAlterTableDropConstraint x);
void endVisit(SQLAlterTableDropConstraint x);
@@ -94,10 +94,8 @@ import com.alibaba.druid.sql.ast.statement.SQLSelectQueryBlock;
import com.alibaba.druid.sql.ast.statement.SQLSelectStatement;
import com.alibaba.druid.sql.ast.statement.SQLSetStatement;
import com.alibaba.druid.sql.ast.statement.SQLSubqueryTableSource;
import com.alibaba.druid.sql.ast.statement.SQLTableElement;
import com.alibaba.druid.sql.ast.statement.SQLTruncateStatement;
import com.alibaba.druid.sql.ast.statement.SQLUnionQuery;
import com.alibaba.druid.sql.ast.statement.SQLUniqueConstraint;
import com.alibaba.druid.sql.ast.statement.SQLUpdateSetItem;
import com.alibaba.druid.sql.ast.statement.SQLUpdateStatement;
import com.alibaba.druid.sql.ast.statement.SQLUseStatement;
@@ -314,13 +312,6 @@ public class SQLASTVisitorAdapter implements SQLASTVisitor {
public void endVisit(SQLCreateTableStatement x) {
}
public boolean visit(SQLTableElement x) {
return true;
}
public void endVisit(SQLTableElement x) {
}
public boolean visit(SQLColumnDefinition x) {
return true;
}
@@ -377,13 +368,6 @@ public class SQLASTVisitorAdapter implements SQLASTVisitor {
public void endVisit(SQLCreateViewStatement x) {
}
public boolean visit(SQLUniqueConstraint x) {
return true;
}
public void endVisit(SQLUniqueConstraint x) {
}
public boolean visit(NotNullConstraint x) {
return true;
}
@@ -662,7 +646,7 @@ public class SQLASTVisitorAdapter implements SQLASTVisitor {
@Override
public void endVisit(SQLCreateDatabaseStatement x) {
}
@Override
@@ -677,7 +661,7 @@ public class SQLASTVisitorAdapter implements SQLASTVisitor {
@Override
public void endVisit(SQLAlterTableDropIndex x) {
}
@Override
@@ -687,7 +671,7 @@ public class SQLASTVisitorAdapter implements SQLASTVisitor {
@Override
public void endVisit(SQLAlterTableAddPrimaryKey x) {
}
@Override
@@ -701,7 +685,7 @@ public class SQLASTVisitorAdapter implements SQLASTVisitor {
@Override
public void endVisit(SQLColumnPrimaryKey x) {
}
@Override
@@ -717,11 +701,11 @@ public class SQLASTVisitorAdapter implements SQLASTVisitor {
public boolean visit(SQLWithSubqueryClause x) {
return true;
}
@Override
public void endVisit(SQLWithSubqueryClause.Entry x) {
}
@Override
public boolean visit(SQLWithSubqueryClause.Entry x) {
return true;
@@ -734,12 +718,12 @@ public class SQLASTVisitorAdapter implements SQLASTVisitor {
@Override
public void endVisit(SQLCharactorDataType x) {
}
@Override
public void endVisit(SQLAlterTableAlterColumn x) {
}
@Override
@@ -754,7 +738,7 @@ public class SQLASTVisitorAdapter implements SQLASTVisitor {
@Override
public void endVisit(SQLCheck x) {
}
@Override
@@ -764,17 +748,17 @@ public class SQLASTVisitorAdapter implements SQLASTVisitor {
@Override
public void endVisit(SQLAlterTableDropForeinKey x) {
}
@Override
public boolean visit(SQLAlterTableDropPrimaryKey x) {
return true;
}
@Override
public void endVisit(SQLAlterTableDropPrimaryKey x) {
}
@Override
@@ -784,7 +768,7 @@ public class SQLASTVisitorAdapter implements SQLASTVisitor {
@Override
public void endVisit(SQLAlterTableDisableKeys x) {
}
@Override
@@ -794,17 +778,17 @@ public class SQLASTVisitorAdapter implements SQLASTVisitor {
@Override
public void endVisit(SQLAlterTableEnableKeys x) {
}
@Override
public boolean visit(SQLAlterTableStatement x) {
return true;
}
@Override
public void endVisit(SQLAlterTableStatement x) {
}
@Override
@@ -814,7 +798,7 @@ public class SQLASTVisitorAdapter implements SQLASTVisitor {
@Override
public void endVisit(SQLAlterTableAddForeignKey x) {
}
@Override
@@ -824,26 +808,27 @@ public class SQLASTVisitorAdapter implements SQLASTVisitor {
@Override
public void endVisit(SQLAlterTableDisableConstraint x) {
}
@Override
public boolean visit(SQLAlterTableEnableConstraint x) {
return true;
}
@Override
public void endVisit(SQLAlterTableEnableConstraint x) {
}
@Override
public boolean visit(SQLColumnCheck x) {
return true;
}
@Override
public void endVisit(SQLColumnCheck x) {
}
@Override
@@ -853,9 +838,9 @@ public class SQLASTVisitorAdapter implements SQLASTVisitor {
@Override
public void endVisit(SQLExprHint x) {
}
@Override
public boolean visit(SQLAlterTableDropConstraint x) {
return true;
@@ -863,6 +848,6 @@ public class SQLASTVisitorAdapter implements SQLASTVisitor {
@Override
public void endVisit(SQLAlterTableDropConstraint x) {
}
}
@@ -1006,7 +1006,7 @@ public class SQLEvalVisitorUtils {
}
public static Short castToShort(Object val) {
if (val == null) {
if (val == null || val == EVAL_VALUE_NULL) {
return null;
}
@@ -1078,7 +1078,7 @@ public class SQLEvalVisitorUtils {
}
public static Float castToFloat(Object val) {
if (val == null) {
if (val == null || val == EVAL_VALUE_NULL) {
return null;
}
@@ -1090,7 +1090,7 @@ public class SQLEvalVisitorUtils {
}
public static Double castToDouble(Object val) {
if (val == null) {
if (val == null || val == EVAL_VALUE_NULL) {
return null;
}
@@ -1191,11 +1191,21 @@ public class SQLEvalVisitorUtils {
}
if (a instanceof Double || b instanceof Double) {
return castToDouble(a) / (castToDouble(b));
Double doubleA = castToDouble(a);
Double doubleB = castToDouble(b);
if (doubleA == null || doubleB == null) {
return null;
}
return doubleA / doubleB;
}
if (a instanceof Float || b instanceof Float) {
return castToFloat(a) / (castToFloat(b));
Float floatA = castToFloat(a);
Float floatB = castToFloat(b);
if (floatA == null || floatB == null) {
return null;
}
return floatA / floatB;
}
if (a instanceof BigInteger || b instanceof BigInteger) {
@@ -1559,7 +1569,14 @@ public class SQLEvalVisitorUtils {
}
if (a instanceof Short || b instanceof Short) {
return castToShort(a) * castToShort(b);
Short shortA = castToShort(a);
Short shortB = castToShort(b);
if (shortA == null || shortB == null) {
return null;
}
return shortA * shortB;
}
if (a instanceof Byte || b instanceof Byte) {
@@ -64,52 +64,6 @@ public class IPRange {
parseRange(range);
}
// -------------------------------------------------------------------------
/**
* Constructor.
*
* @param ipAddress Reference to the IP address number
* @param subnetMask Reference to the subnet mask
* @exception InvalidIPRangeException Throws this exception when the combination of the IP address and the subnet
* mask does not define a valid IP range.
* @exception InvalidIPAddressException Throws this exception if the specified IP address or subnet mask do ne
* define a valid IP number.
*/
public IPRange(IPAddress ipAddress, IPAddress subnetMask){
if ((ipAddress == null) || (subnetMask == null)) {
throw new IllegalArgumentException();
}
this.ipAddress = ipAddress;
this.ipSubnetMask = subnetMask;
extendedNetworkPrefix = computeNetworkPrefixFromMask(subnetMask);
if (extendedNetworkPrefix == -1) {
throw new IllegalArgumentException();
}
}
// -------------------------------------------------------------------------
/**
* Constructor.
*
* @param ipAddress The reference on the IP address.
* @param extendedNetworkPrefix The extended network prefix (0-32).
*/
public IPRange(IPAddress ipAddress, int extendedNetworkPrefix){
if (ipAddress == null) {
throw new IllegalArgumentException();
}
if ((extendedNetworkPrefix < 0) || (extendedNetworkPrefix > 32)) {
throw new IllegalArgumentException();
}
this.ipAddress = ipAddress;
this.extendedNetworkPrefix = extendedNetworkPrefix;
this.ipSubnetMask = computeMaskFromNetworkPrefix(extendedNetworkPrefix);
}
// -------------------------------------------------------------------------
/**
* Return the encapsulated IP address.
@@ -155,37 +109,6 @@ public class IPRange {
return result.toString();
}
/*
* (non-Javadoc)
* @see java.lang.Object#hashCode()
*/
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + extendedNetworkPrefix;
result = prime * result + ((ipAddress == null) ? 0 : ipAddress.hashCode());
result = prime * result + ((ipSubnetMask == null) ? 0 : ipSubnetMask.hashCode());
return result;
}
// -------------------------------------------------------------------------
/**
* Compare the specified IP range to the encapsulated one.
*
* @param another The IP range to be compared.
* @return Return <code>true</code> if the encapsulated IP range is the same as the specified one, otherwise return
* <code>false</code>.
*/
public boolean equals(Object another) {
if (another instanceof IPRange) {
IPRange range = (IPRange) another;
return (ipAddress.equals(range.getIPAddress()) && (extendedNetworkPrefix == range.extendedNetworkPrefix));
}
return false;
}
// -------------------------------------------------------------------------
/**
* Parse the IP range string representation.
@@ -265,7 +188,7 @@ public class IPRange {
int octet = Integer.parseInt(binary[c], 2);
decimalip.append(octet);
if (c < 3) {
decimalip.append('.');
}
}
@@ -311,7 +234,7 @@ public class IPRange {
if (ipSubnetMask == null) {
return this.ipAddress.equals(address);
}
int result1 = address.getIPAddress() & ipSubnetMask.getIPAddress();
int result2 = ipAddress.getIPAddress() & ipSubnetMask.getIPAddress();
@@ -195,6 +195,11 @@ public class JSONWriter {
}
public void writeString(String text) {
if (text == null) {
writeNull();
return;
}
write('"');
for (int i = 0; i < text.length(); ++i) {
char c = text.charAt(i);
@@ -15,15 +15,6 @@
*/
package com.alibaba.druid.support.logging;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.net.URL;
import java.net.URLConnection;
import java.nio.charset.Charset;
import java.util.Properties;
/**
* A class to simplify access to resources through the classloader.
@@ -32,11 +23,6 @@ public final class Resources extends Object {
private static ClassLoader defaultClassLoader;
/**
* Charset to use when calling getResourceAsReader. null means use the system default.
*/
private static Charset charset;
private Resources(){
}
@@ -58,212 +44,6 @@ public final class Resources extends Object {
Resources.defaultClassLoader = defaultClassLoader;
}
/**
* Returns the URL of the resource on the classpath
*
* @param resource The resource to find
* @return The resource
* @throws IOException If the resource cannot be found or read
*/
public static URL getResourceURL(String resource) throws IOException {
return getResourceURL(getClassLoader(), resource);
}
/**
* Returns the URL of the resource on the classpath
*
* @param loader The classloader used to load the resource
* @param resource The resource to find
* @return The resource
* @throws IOException If the resource cannot be found or read
*/
public static URL getResourceURL(ClassLoader loader, String resource) throws IOException {
URL url = null;
if (loader != null) {
url = loader.getResource(resource);
}
if (url == null) {
url = ClassLoader.getSystemResource(resource);
}
if (url == null) {
throw new IOException("Could not find resource " + resource);
}
return url;
}
/**
* Returns a resource on the classpath as a Stream object
*
* @param resource The resource to find
* @return The resource
* @throws IOException If the resource cannot be found or read
*/
public static InputStream getResourceAsStream(String resource) throws IOException {
return getResourceAsStream(getClassLoader(), resource);
}
/**
* Returns a resource on the classpath as a Stream object
*
* @param loader The classloader used to load the resource
* @param resource The resource to find
* @return The resource
* @throws IOException If the resource cannot be found or read
*/
public static InputStream getResourceAsStream(ClassLoader loader, String resource) throws IOException {
InputStream in = null;
if (loader != null) {
in = loader.getResourceAsStream(resource);
}
if (in == null) {
in = ClassLoader.getSystemResourceAsStream(resource);
}
if (in == null) {
throw new IOException("Could not find resource " + resource);
}
return in;
}
/**
* Returns a resource on the classpath as a Properties object
*
* @param resource The resource to find
* @return The resource
* @throws IOException If the resource cannot be found or read
*/
public static Properties getResourceAsProperties(String resource) throws IOException {
Properties props = new Properties();
InputStream in = null;
String propfile = resource;
in = getResourceAsStream(propfile);
props.load(in);
in.close();
return props;
}
/**
* Returns a resource on the classpath as a Properties object
*
* @param loader The classloader used to load the resource
* @param resource The resource to find
* @return The resource
* @throws IOException If the resource cannot be found or read
*/
public static Properties getResourceAsProperties(ClassLoader loader, String resource) throws IOException {
Properties props = new Properties();
InputStream in = null;
String propfile = resource;
in = getResourceAsStream(loader, propfile);
props.load(in);
in.close();
return props;
}
/**
* Returns a resource on the classpath as a Reader object
*
* @param resource The resource to find
* @return The resource
* @throws IOException If the resource cannot be found or read
*/
public static Reader getResourceAsReader(String resource) throws IOException {
Reader reader;
if (charset == null) {
reader = new InputStreamReader(getResourceAsStream(resource));
} else {
reader = new InputStreamReader(getResourceAsStream(resource), charset);
}
return reader;
}
/**
* Returns a resource on the classpath as a Reader object
*
* @param loader The classloader used to load the resource
* @param resource The resource to find
* @return The resource
* @throws IOException If the resource cannot be found or read
*/
public static Reader getResourceAsReader(ClassLoader loader, String resource) throws IOException {
Reader reader;
if (charset == null) {
reader = new InputStreamReader(getResourceAsStream(loader, resource));
} else {
reader = new InputStreamReader(getResourceAsStream(loader, resource), charset);
}
return reader;
}
/**
* Returns a resource on the classpath as a File object
*
* @param resource The resource to find
* @return The resource
* @throws IOException If the resource cannot be found or read
*/
public static File getResourceAsFile(String resource) throws IOException {
return new File(getResourceURL(resource).getFile());
}
/**
* Returns a resource on the classpath as a File object
*
* @param loader - the classloader used to load the resource
* @param resource - the resource to find
* @return The resource
* @throws IOException If the resource cannot be found or read
*/
public static File getResourceAsFile(ClassLoader loader, String resource) throws IOException {
return new File(getResourceURL(loader, resource).getFile());
}
/**
* Gets a URL as an input stream
*
* @param urlString - the URL to get
* @return An input stream with the data from the URL
* @throws IOException If the resource cannot be found or read
*/
public static InputStream getUrlAsStream(String urlString) throws IOException {
URL url = new URL(urlString);
URLConnection conn = url.openConnection();
return conn.getInputStream();
}
/**
* Gets a URL as a Reader
*
* @param urlString - the URL to get
* @return A Reader with the data from the URL
* @throws IOException If the resource cannot be found or read
*/
public static Reader getUrlAsReader(String urlString) throws IOException {
return new InputStreamReader(getUrlAsStream(urlString));
}
/**
* Gets a URL as a Properties object
*
* @param urlString - the URL to get
* @return A Properties object with the data from the URL
* @throws IOException If the resource cannot be found or read
*/
public static Properties getUrlAsProperties(String urlString) throws IOException {
Properties props = new Properties();
InputStream in = null;
String propfile = urlString;
in = getUrlAsStream(propfile);
props.load(in);
in.close();
return props;
}
/**
* Loads a class
*
@@ -284,32 +64,6 @@ public final class Resources extends Object {
return clazz;
}
/**
* Creates an instance of a class
*
* @param className - the class to create
* @return An instance of the class
* @throws ClassNotFoundException If the class cannot be found (duh!)
* @throws InstantiationException If the class cannot be instantiaed
* @throws IllegalAccessException If the class is not public, or other access problems arise
*/
public static Object instantiate(String className) throws ClassNotFoundException, InstantiationException,
IllegalAccessException {
return instantiate(classForName(className));
}
/**
* Creates an instance of a class
*
* @param clazz - the class to create
* @return An instance of the class
* @throws InstantiationException If the class cannot be instantiaed
* @throws IllegalAccessException If the class is not public, or other access problems arise
*/
public static Object instantiate(Class<?> clazz) throws InstantiationException, IllegalAccessException {
return clazz.newInstance();
}
private static ClassLoader getClassLoader() {
if (defaultClassLoader != null) {
return defaultClassLoader;
@@ -318,19 +72,4 @@ public final class Resources extends Object {
}
}
public static Charset getCharset() {
return charset;
}
/**
* Use this method to set the Charset to be used when calling the getResourceAsReader methods. This will allow
* iBATIS to function properly when the system default encoding doesn't deal well with unicode (IBATIS-340,
* IBATIS-349)
*
* @param charset
*/
public static void setCharset(Charset charset) {
Resources.charset = charset;
}
}
@@ -478,36 +478,40 @@ public final class JdbcUtils implements JdbcConstants {
}
public static Driver createDriver(ClassLoader classLoader, String driverClassName) throws SQLException {
Class<?> clazz = null;
if (classLoader != null) {
try {
return (Driver) classLoader.loadClass(driverClassName).newInstance();
} catch (IllegalAccessException e) {
throw new SQLException(e.getMessage(), e);
} catch (InstantiationException e) {
throw new SQLException(e.getMessage(), e);
clazz = classLoader.loadClass(driverClassName);
} catch (ClassNotFoundException e) {
// skip
}
}
if (clazz == null) {
try {
ClassLoader contextLoader = Thread.currentThread().getContextClassLoader();
if (contextLoader != null) {
clazz = contextLoader.loadClass(driverClassName);
}
} catch (ClassNotFoundException e) {
// skip
}
}
if (clazz == null) {
try {
clazz = Class.forName(driverClassName);
} catch (ClassNotFoundException e) {
throw new SQLException(e.getMessage(), e);
}
}
try {
return (Driver) Class.forName(driverClassName).newInstance();
return (Driver) clazz.newInstance();
} catch (IllegalAccessException e) {
throw new SQLException(e.getMessage(), e);
} catch (InstantiationException e) {
throw new SQLException(e.getMessage(), e);
} catch (ClassNotFoundException e) {
// skip
}
try {
return (Driver) Thread.currentThread().getContextClassLoader().loadClass(driverClassName).newInstance();
} catch (IllegalAccessException e) {
throw new SQLException(e.getMessage(), e);
} catch (InstantiationException e) {
throw new SQLException(e.getMessage(), e);
} catch (ClassNotFoundException e) {
throw new SQLException(e.getMessage(), e);
}
}