bug fixed for concurrent & sql schema stat

This commit is contained in:
wenshao
2012-07-26 16:59:22 +08:00
parent 440029671c
commit 0370afc794
6 changed files with 31 additions and 13 deletions
@@ -39,7 +39,7 @@ public final class ConnectionHolder {
private final List<ConnectionEventListener> connectionEventListeners = new CopyOnWriteArrayList<ConnectionEventListener>();
private final List<StatementEventListener> statementEventListeners = new CopyOnWriteArrayList<StatementEventListener>();
private final long connecttimeMillis;
private long lastActiveTimeMillis;
private transient long lastActiveTimeMillis;
private long useCount = 0;
private PreparedStatementPool statementPool;
@@ -67,14 +67,15 @@ public final class ConnectionHolder {
this.lastActiveTimeMillis = connecttimeMillis;
this.underlyingAutoCommit = conn.getAutoCommit();
this.underlyingHoldability = conn.getHoldability();
this.underlyingHoldability = conn.getHoldability();
this.underlyingReadOnly = conn.isReadOnly();
try {
this.underlyingTransactionIsolation = conn.getTransactionIsolation();
} catch (SQLException e) {
if ("com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException".equals(e.getClass().getName()));
if ("com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException".equals(e.getClass().getName()))
;
}
this.defaultHoldability = underlyingHoldability;
this.defaultTransactionIsolation = underlyingTransactionIsolation;
this.defaultAutoCommit = underlyingAutoCommit;
@@ -318,7 +318,6 @@ public class OracleSchemaStatVisitor extends SchemaStatVisitor implements Oracle
}
public void endVisit(OracleUpdateStatement x) {
clearAliasMap();
}
public boolean visit(OracleDeleteStatement x) {
@@ -326,7 +325,6 @@ public class OracleSchemaStatVisitor extends SchemaStatVisitor implements Oracle
}
public void endVisit(OracleDeleteStatement x) {
clearAliasMap();
}
public boolean visit(OracleSelectQueryBlock x) {
@@ -1035,7 +1033,6 @@ public class OracleSchemaStatVisitor extends SchemaStatVisitor implements Oracle
@Override
public void endVisit(OracleMergeStatement x) {
clearAliasMap();
}
@Override
@@ -723,7 +723,6 @@ public class SchemaStatVisitor extends SQLASTVisitorAdapter {
}
public void endVisit(SQLSelectStatement x) {
clearAliasMap();
}
public boolean visit(SQLSubqueryTableSource x) {
@@ -897,11 +896,10 @@ public class SchemaStatVisitor extends SQLASTVisitorAdapter {
}
public void endVisit(SQLDeleteStatement x) {
clearAliasMap();
}
public void endVisit(SQLUpdateStatement x) {
clearAliasMap();
}
public boolean visit(SQLCreateTableStatement x) {
@@ -337,7 +337,26 @@ public class TableStat {
}
public String toString() {
return this.column.toString() + " " + this.operator;
StringBuffer buf = new StringBuffer();
buf.append(this.column.toString());
buf.append(' ');
buf.append(this.operator);
if (values.size() == 1) {
buf.append(' ');
buf.append(String.valueOf(this.values.get(0)));
} else if (values.size() > 0) {
buf.append(" (");
for (int i = 0; i < values.size(); ++i) {
if (i != 0) {
buf.append(", ");
}
buf.append(String.valueOf(values.get(i)));
}
buf.append(")");
}
return buf.toString();
}
}
@@ -39,7 +39,7 @@ public class TestActiveTrace extends TestCase {
conn.close();
// Assert.assertEquals(1, dataSource.getPoolingCount());
dataSource.shrink();
Assert.assertEquals(0, dataSource.getPoolingCount());
Assert.assertEquals("createCount : " + dataSource.getCreateCount(), 0, dataSource.getPoolingCount());
Assert.assertEquals(0, dataSource.getActiveConnections().size());
}
}
@@ -13,7 +13,7 @@ import com.alibaba.druid.stat.TableStat.Column;
public class MySqlSchemaStatVisitorTest_Subquery extends TestCase {
public void test_0() throws Exception {
String sql = "SELECT id2, name2 FROM (select id, name from users limit 10) a";
String sql = "SELECT id2, name2 FROM (select id, name from users u where id = 22 limit 10) a";
MySqlStatementParser parser = new MySqlStatementParser(sql);
List<SQLStatement> statementList = parser.parseStatementList();
@@ -27,9 +27,12 @@ public class MySqlSchemaStatVisitorTest_Subquery extends TestCase {
System.out.println(sql);
System.out.println("Tables : " + visitor.getTables());
System.out.println("fields : " + visitor.getColumns());
System.out.println("alias : " + visitor.getAliasMap());
System.out.println("conditions : " + visitor.getConditions());
Assert.assertEquals(1, visitor.getTables().size());
Assert.assertEquals(true, visitor.containsTable("users"));
Assert.assertEquals(22, visitor.getConditions().get(0).getValues().get(0));
Assert.assertEquals(2, visitor.getColumns().size());
Assert.assertEquals(true, visitor.getColumns().contains(new Column("users", "id")));