mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
修正Druid线程非Daemon问题
git-svn-id: http://code.alibabatech.com/svn/druid/trunk@275 b9813039-fb51-4c41-a8b9-e21c2acb5095
This commit is contained in:
@@ -149,7 +149,9 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
|
||||
}
|
||||
|
||||
createConnectionThread = new CreateConnectionThread("Druid-ConnectionPool-Create");
|
||||
createConnectionThread.setDaemon(true);
|
||||
destoryConnectionThread = new DestroyConnectionThread("Druid-ConnectionPool-Destory");
|
||||
destoryConnectionThread.setDaemon(true);
|
||||
|
||||
createConnectionThread.start();
|
||||
destoryConnectionThread.start();
|
||||
|
||||
@@ -1,31 +0,0 @@
|
||||
/*
|
||||
* Copyright 1999-2011 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.sql.dialect.mysql.ast;
|
||||
|
||||
import com.alibaba.druid.sql.ast.statement.SQLSelect;
|
||||
|
||||
public class MySqlSQLSelect extends SQLSelect {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public MySqlSQLSelect(){
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+36
-6
@@ -8,7 +8,10 @@ import java.util.Set;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLName;
|
||||
import com.alibaba.druid.sql.ast.SQLObject;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLAggregateExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLAllColumnExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLMethodInvokeExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLPropertyExpr;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLExprTableSource;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLInsertStatement;
|
||||
@@ -26,7 +29,7 @@ import com.alibaba.druid.stat.TableStat.Mode;
|
||||
|
||||
public class MySqlSchemaStatVisitor extends MySqlASTVisitorAdapter {
|
||||
|
||||
private HashMap<TableStat.Name, TableStat> tableStats = new HashMap<TableStat.Name, TableStat>();
|
||||
private HashMap<TableStat.Name, TableStat> tableStats = new HashMap<TableStat.Name, TableStat>();
|
||||
private Set<Column> fields = new HashSet<Column>();
|
||||
|
||||
private final static ThreadLocal<Map<String, String>> aliasLocal = new ThreadLocal<Map<String, String>>();
|
||||
@@ -83,10 +86,28 @@ public class MySqlSchemaStatVisitor extends MySqlASTVisitorAdapter {
|
||||
}
|
||||
|
||||
public boolean visit(SQLSelect x) {
|
||||
return true;
|
||||
accept(x.getQuery());
|
||||
|
||||
String originalTable = currentTableLocal.get();
|
||||
|
||||
currentTableLocal.set((String) x.getQuery().getAttribute("table"));
|
||||
x.putAttribute("_old_local_", originalTable);
|
||||
|
||||
accept(x.getOrderBy());
|
||||
|
||||
currentTableLocal.set(originalTable);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void endVisit(SQLSelect x) {
|
||||
public boolean visit(SQLAggregateExpr x) {
|
||||
accept(x.getArguments());
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean visit(SQLMethodInvokeExpr x) {
|
||||
accept(x.getParameters());
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean visit(SQLUpdateStatement x) {
|
||||
@@ -280,6 +301,7 @@ public class MySqlSchemaStatVisitor extends MySqlASTVisitorAdapter {
|
||||
|
||||
public void endVisit(SQLSelectQueryBlock x) {
|
||||
String originalTable = (String) x.getAttribute("_old_local_");
|
||||
x.putAttribute("table", currentTableLocal.get());
|
||||
currentTableLocal.set(originalTable);
|
||||
|
||||
Mode originalMode = (Mode) x.getAttribute("_original_use_mode");
|
||||
@@ -298,7 +320,7 @@ public class MySqlSchemaStatVisitor extends MySqlASTVisitorAdapter {
|
||||
Map<String, String> aliasMap = aliasLocal.get();
|
||||
if (aliasMap != null) {
|
||||
String table = aliasMap.get(owner);
|
||||
|
||||
|
||||
// table == null时是SubQuery
|
||||
if (table != null) {
|
||||
fields.add(new Column(table, x.getName()));
|
||||
@@ -318,10 +340,19 @@ public class MySqlSchemaStatVisitor extends MySqlASTVisitorAdapter {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean visit(SQLAllColumnExpr x) {
|
||||
String currentTable = currentTableLocal.get();
|
||||
|
||||
if (currentTable != null) {
|
||||
fields.add(new Column(currentTable, "*"));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public Map<TableStat.Name, TableStat> getTables() {
|
||||
return tableStats;
|
||||
}
|
||||
|
||||
|
||||
public boolean containsTable(String tableName) {
|
||||
return tableStats.containsKey(new TableStat.Name(tableName));
|
||||
}
|
||||
@@ -330,5 +361,4 @@ public class MySqlSchemaStatVisitor extends MySqlASTVisitorAdapter {
|
||||
return fields;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
+49
-7
@@ -6,8 +6,12 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLName;
|
||||
import com.alibaba.druid.sql.ast.SQLObject;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLAggregateExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLAllColumnExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLMethodInvokeExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLPropertyExpr;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLDeleteStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLExprTableSource;
|
||||
@@ -18,6 +22,7 @@ import com.alibaba.druid.sql.ast.statement.SQLSelectQueryBlock;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLSelectStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLSubqueryTableSource;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLUpdateStatement;
|
||||
import com.alibaba.druid.sql.dialect.oracle.ast.expr.OracleAggregateExpr;
|
||||
import com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleDeleteStatement;
|
||||
import com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleSelectQueryBlock;
|
||||
import com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleSelectTableReference;
|
||||
@@ -29,7 +34,7 @@ import com.alibaba.druid.stat.TableStat.Name;
|
||||
|
||||
public class OracleSchemaStatVisitor extends OracleASTVIsitorAdapter {
|
||||
|
||||
private HashMap<TableStat.Name, TableStat> tableStats = new HashMap<TableStat.Name, TableStat>();
|
||||
private HashMap<TableStat.Name, TableStat> tableStats = new HashMap<TableStat.Name, TableStat>();
|
||||
private Set<Column> fields = new HashSet<Column>();
|
||||
|
||||
private final static ThreadLocal<Map<String, String>> aliasLocal = new ThreadLocal<Map<String, String>>();
|
||||
@@ -47,8 +52,8 @@ public class OracleSchemaStatVisitor extends OracleASTVIsitorAdapter {
|
||||
}
|
||||
|
||||
public boolean visit(SQLExprTableSource x) {
|
||||
if (x.getExpr() instanceof SQLIdentifierExpr) {
|
||||
String ident = ((SQLIdentifierExpr) x.getExpr()).getName();
|
||||
if (x.getExpr() instanceof SQLName) {
|
||||
String ident = ((SQLName) x.getExpr()).toString();
|
||||
TableStat stat = tableStats.get(ident);
|
||||
if (stat == null) {
|
||||
stat = new TableStat();
|
||||
@@ -86,8 +91,8 @@ public class OracleSchemaStatVisitor extends OracleASTVIsitorAdapter {
|
||||
}
|
||||
|
||||
public boolean visit(OracleSelectTableReference x) {
|
||||
if (x.getExpr() instanceof SQLIdentifierExpr) {
|
||||
String ident = ((SQLIdentifierExpr) x.getExpr()).getName();
|
||||
if (x.getExpr() instanceof SQLName) {
|
||||
String ident = ((SQLName) x.getExpr()).toString();
|
||||
TableStat stat = tableStats.get(ident);
|
||||
if (stat == null) {
|
||||
stat = new TableStat();
|
||||
@@ -123,9 +128,36 @@ public class OracleSchemaStatVisitor extends OracleASTVIsitorAdapter {
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean visit(SQLAggregateExpr x) {
|
||||
accept(x.getArguments());
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean visit(OracleAggregateExpr x) {
|
||||
accept(x.getArguments());
|
||||
accept(x.getOver());
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean visit(SQLMethodInvokeExpr x) {
|
||||
accept(x.getParameters());
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean visit(SQLSelect x) {
|
||||
return true;
|
||||
accept(x.getQuery());
|
||||
|
||||
String originalTable = currentTableLocal.get();
|
||||
|
||||
currentTableLocal.set((String) x.getQuery().getAttribute("table"));
|
||||
x.putAttribute("_old_local_", originalTable);
|
||||
|
||||
accept(x.getOrderBy());
|
||||
|
||||
currentTableLocal.set(originalTable);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void endVisit(SQLSelect x) {
|
||||
@@ -312,6 +344,7 @@ public class OracleSchemaStatVisitor extends OracleASTVIsitorAdapter {
|
||||
|
||||
public void endVisit(SQLSelectQueryBlock x) {
|
||||
String originalTable = (String) x.getAttribute("_old_local_");
|
||||
x.putAttribute("table", currentTableLocal.get());
|
||||
currentTableLocal.set(originalTable);
|
||||
|
||||
Mode originalMode = (Mode) x.getAttribute("_original_use_mode");
|
||||
@@ -366,10 +399,19 @@ public class OracleSchemaStatVisitor extends OracleASTVIsitorAdapter {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean visit(SQLAllColumnExpr x) {
|
||||
String currentTable = currentTableLocal.get();
|
||||
|
||||
if (currentTable != null) {
|
||||
fields.add(new Column(currentTable, "*"));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public Map<Name, TableStat> getTables() {
|
||||
return tableStats;
|
||||
}
|
||||
|
||||
|
||||
public boolean containsTable(String tableName) {
|
||||
return tableStats.containsKey(new TableStat.Name(tableName));
|
||||
}
|
||||
|
||||
@@ -225,10 +225,10 @@ public class SQLASTVisitorAdapter implements SQLASTVisitor {
|
||||
return true;
|
||||
}
|
||||
|
||||
public void endVisit(SQLAggregateExpr astNode) {
|
||||
public void endVisit(SQLAggregateExpr x) {
|
||||
}
|
||||
|
||||
public boolean visit(SQLAggregateExpr astNode) {
|
||||
public boolean visit(SQLAggregateExpr x) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
package com.alibaba.druid.sql.oracle.bvt.visitor;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.Reader;
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser;
|
||||
import com.alibaba.druid.sql.dialect.mysql.visitor.MySqlOutputVisitor;
|
||||
import com.alibaba.druid.sql.dialect.mysql.visitor.MySqlParameterizedOutputVisitor;
|
||||
import com.alibaba.druid.sql.dialect.oracle.ast.visitor.OracleSchemaStatVisitor;
|
||||
import com.alibaba.druid.sql.dialect.oracle.parser.OracleStatementParser;
|
||||
import com.alibaba.druid.util.JdbcUtils;
|
||||
|
||||
public class OracleResourceTest extends TestCase {
|
||||
|
||||
public void test_0() throws Exception {
|
||||
// 13
|
||||
exec_test("bvt/parser/oracle-28.txt");
|
||||
// for (int i = 0; i <= 53; ++i) {
|
||||
// exec_test("bvt/parser/oracle-" + i + ".txt");
|
||||
// }
|
||||
}
|
||||
|
||||
public void exec_test(String resource) throws Exception {
|
||||
System.out.println(resource);
|
||||
InputStream is = null;
|
||||
|
||||
is = Thread.currentThread().getContextClassLoader().getResourceAsStream(resource);
|
||||
Reader reader = new InputStreamReader(is, "UTF-8");
|
||||
String input = JdbcUtils.read(reader);
|
||||
JdbcUtils.close(reader);
|
||||
String[] items = input.split("---------------------------");
|
||||
String sql = items[0].trim();
|
||||
String expect = items[1].trim();
|
||||
|
||||
OracleStatementParser parser = new OracleStatementParser(sql);
|
||||
List<SQLStatement> statementList = parser.parseStatementList();
|
||||
SQLStatement statemen = statementList.get(0);
|
||||
|
||||
Assert.assertEquals(1, statementList.size());
|
||||
|
||||
OracleSchemaStatVisitor visitor = new OracleSchemaStatVisitor();
|
||||
statemen.accept(visitor);
|
||||
|
||||
System.out.println(sql);
|
||||
System.out.println("Tables : " + visitor.getTables());
|
||||
System.out.println("fields : " + visitor.getFields());
|
||||
|
||||
System.out.println();
|
||||
System.out.println();
|
||||
}
|
||||
|
||||
void mergValidate(String sql, String expect) {
|
||||
|
||||
MySqlStatementParser parser = new MySqlStatementParser(sql);
|
||||
List<SQLStatement> statementList = parser.parseStatementList();
|
||||
SQLStatement statemen = statementList.get(0);
|
||||
|
||||
Assert.assertEquals(1, statementList.size());
|
||||
|
||||
StringBuilder out = new StringBuilder();
|
||||
MySqlParameterizedOutputVisitor visitor = new MySqlParameterizedOutputVisitor(out);
|
||||
statemen.accept(visitor);
|
||||
|
||||
System.out.println(out.toString());
|
||||
|
||||
Assert.assertEquals(expect, out.toString());
|
||||
}
|
||||
|
||||
private String output(List<SQLStatement> stmtList) {
|
||||
StringBuilder out = new StringBuilder();
|
||||
MySqlOutputVisitor visitor = new MySqlOutputVisitor(out);
|
||||
|
||||
for (SQLStatement stmt : stmtList) {
|
||||
stmt.accept(visitor);
|
||||
}
|
||||
|
||||
return out.toString();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user