Skip to content

Commit

Permalink
Merge pull request alibaba#372 from wenshao/master
Browse files Browse the repository at this point in the history
add testcase & remove unused code
  • Loading branch information
wenshao committed Jun 19, 2013
2 parents 75c0556 + 72c9665 commit 9620050
Show file tree
Hide file tree
Showing 152 changed files with 4,914 additions and 1,776 deletions.
4 changes: 3 additions & 1 deletion src/main/java/com/alibaba/druid/mock/MockClob.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -26,6 +27,7 @@
public class MockClob implements Clob {

private byte[] bytes;
private ByteArrayOutputStream out = new ByteArrayOutputStream();

public MockClob(){
this(new byte[0]);
Expand Down Expand Up @@ -81,7 +83,7 @@ public int setString(long pos, String str, int offset, int len) throws SQLExcept

@Override
public OutputStream setAsciiStream(long pos) throws SQLException {
return null;
return out;
}

@Override
Expand Down
100 changes: 50 additions & 50 deletions src/main/java/com/alibaba/druid/pool/DruidDataSource.java
Original file line number Diff line number Diff line change
Expand Up @@ -318,10 +318,10 @@ public void resetStat() {
transactionHistogram.reset();
cachedPreparedStatementDeleteCount.set(0);
recycleErrorCount.set(0);

resetCount.incrementAndGet();
}

public long getResetCount() {
return this.resetCount.get();
}
Expand Down Expand Up @@ -1445,19 +1445,19 @@ public DruidDataSourceStatValue getStatValueAndReset() {

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;
Expand All @@ -1473,56 +1473,56 @@ public DruidDataSourceStatValue getStatValueAndReset() {
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;
}
Expand Down
23 changes: 0 additions & 23 deletions src/main/java/com/alibaba/druid/pool/DruidDataSourceStatValue.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@

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 {

Expand Down Expand Up @@ -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;
Expand Down
36 changes: 23 additions & 13 deletions src/main/java/com/alibaba/druid/sql/ast/SQLDataTypeImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,28 @@ public List<SQLExpr> getArguments() {
return this.arguments;
}

public void output(StringBuffer buf) {
buf.append(this.name);
if (this.arguments.size() > 0) {
buf.append("(");
int i = 0;
for (int size = this.arguments.size(); i < size; ++i) {
if (i != 0) {
buf.append(", ");
}
((SQLExpr) this.arguments.get(i)).output(buf);
}
buf.append(")");
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((arguments == null) ? 0 : arguments.hashCode());
result = prime * result + ((name == null) ? 0 : name.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;
SQLDataTypeImpl other = (SQLDataTypeImpl) obj;
if (arguments == null) {
if (other.arguments != null) return false;
} else if (!arguments.equals(other.arguments)) return false;
if (name == null) {
if (other.name != null) return false;
} else if (!name.equals(other.name)) return false;
return true;
}

}
30 changes: 19 additions & 11 deletions src/main/java/com/alibaba/druid/sql/ast/SQLOrderBy.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,24 @@ protected void accept0(SQLASTVisitor visitor) {
visitor.endVisit(this);
}

public void output(StringBuffer buf) {
buf.append("ORDER ");
buf.append("BY ");

int i = 0;
for (int size = this.items.size(); i < size; ++i) {
if (i != 0) {
buf.append(", ");
}
this.items.get(i).output(buf);
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((items == null) ? 0 : items.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;
SQLOrderBy other = (SQLOrderBy) obj;
if (items == null) {
if (other.items != null) return false;
} else if (!items.equals(other.items)) return false;
return true;
}

}
12 changes: 0 additions & 12 deletions src/main/java/com/alibaba/druid/sql/ast/expr/SQLBetweenExpr.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,6 @@ public SQLBetweenExpr(SQLExpr testExpr, boolean not, SQLExpr beginExpr, SQLExpr
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);
Expand Down
14 changes: 3 additions & 11 deletions src/main/java/com/alibaba/druid/sql/ast/expr/SQLBinaryOpExpr.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
public class SQLBinaryOpExpr extends SQLExprImpl implements Serializable {

private static final long serialVersionUID = 1L;
private SQLExpr left;
private SQLExpr right;
private SQLBinaryOperator operator;
private SQLExpr left;
private SQLExpr right;
private SQLBinaryOperator operator;

public SQLBinaryOpExpr(){

Expand Down Expand Up @@ -76,14 +76,6 @@ public void setOperator(SQLBinaryOperator operator) {
this.operator = operator;
}

public void output(StringBuffer buf) {
this.left.output(buf);
buf.append(" ");
buf.append(this.operator.name);
buf.append(" ");
this.right.output(buf);
}

protected void accept0(SQLASTVisitor visitor) {
if (visitor.visit(this)) {
acceptChild(visitor, this.left);
Expand Down
Loading

0 comments on commit 9620050

Please sign in to comment.