mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
improved sql parser.
This commit is contained in:
@@ -2134,6 +2134,30 @@ public class OracleOutputVisitor extends SQLASTOutputVisitor implements OracleAS
|
||||
x.getInitial().accept(this);
|
||||
}
|
||||
|
||||
if (x.getNext() != null) {
|
||||
println();
|
||||
print0(ucase ? "NEXT " : "next ");
|
||||
x.getNext().accept(this);
|
||||
}
|
||||
|
||||
if (x.getMinExtents() != null) {
|
||||
println();
|
||||
print0(ucase ? "MINEXTENTS " : "minextents ");
|
||||
x.getMinExtents().accept(this);
|
||||
}
|
||||
|
||||
if (x.getMaxExtents() != null) {
|
||||
println();
|
||||
print0(ucase ? "MAXEXTENTS " : "maxextents ");
|
||||
x.getMaxExtents().accept(this);
|
||||
}
|
||||
|
||||
if (x.getPctIncrease() != null) {
|
||||
println();
|
||||
print0(ucase ? "PCTINCREASE " : "pctincrease ");
|
||||
x.getPctIncrease().accept(this);
|
||||
}
|
||||
|
||||
if (x.getMaxSize() != null) {
|
||||
println();
|
||||
print0(ucase ? "MAXSIZE " : "maxsize ");
|
||||
|
||||
@@ -30,7 +30,6 @@ import com.alibaba.druid.sql.dialect.oracle.visitor.OracleASTVisitorAdapter;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
import java.util.concurrent.ConcurrentSkipListMap;
|
||||
|
||||
/**
|
||||
@@ -128,10 +127,21 @@ public class SchemaRepository {
|
||||
public SchemaObject findTable(SQLTableSource tableSource, String alias) {
|
||||
if (tableSource instanceof SQLExprTableSource) {
|
||||
if (alias.equalsIgnoreCase(tableSource.computeAlias())) {
|
||||
SQLExpr expr = ((SQLExprTableSource) tableSource).getExpr();
|
||||
SQLExprTableSource exprTableSource = (SQLExprTableSource) tableSource;
|
||||
|
||||
SchemaObject tableObject = exprTableSource.getSchemaObject();
|
||||
if (tableObject != null) {
|
||||
return tableObject;
|
||||
}
|
||||
|
||||
SQLExpr expr = exprTableSource.getExpr();
|
||||
if (expr instanceof SQLIdentifierExpr) {
|
||||
String tableName = ((SQLIdentifierExpr) expr).getName();
|
||||
SchemaObject tableObject = findTable(tableName);
|
||||
|
||||
tableObject = findTable(tableName);
|
||||
if (tableObject != null) {
|
||||
exprTableSource.setSchemaObject(tableObject);
|
||||
}
|
||||
return tableObject;
|
||||
}
|
||||
}
|
||||
@@ -220,20 +230,31 @@ public class SchemaRepository {
|
||||
|
||||
public Map<String, SchemaObject> getTables(SQLTableSource x) {
|
||||
Map<String, SchemaObject> tables = new LinkedHashMap<String, SchemaObject>();
|
||||
computeTable(x, tables);
|
||||
computeTables(x, tables);
|
||||
return tables;
|
||||
}
|
||||
|
||||
private void computeTable(SQLTableSource x, Map<String, SchemaObject> tables) {
|
||||
private void computeTables(SQLTableSource x, Map<String, SchemaObject> tables) {
|
||||
if (x == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (x instanceof SQLExprTableSource) {
|
||||
SQLExpr expr = ((SQLExprTableSource) x).getExpr();
|
||||
SQLExprTableSource exprTableSource = (SQLExprTableSource) x;
|
||||
|
||||
SQLExpr expr = exprTableSource.getExpr();
|
||||
if (expr instanceof SQLIdentifierExpr) {
|
||||
String tableName = ((SQLIdentifierExpr) expr).getName();
|
||||
SchemaObject table = findTable(tableName);
|
||||
|
||||
SchemaObject table = exprTableSource.getSchemaObject();
|
||||
if (table == null) {
|
||||
table = findTable(tableName);
|
||||
|
||||
if (table != null) {
|
||||
exprTableSource.setSchemaObject(table);
|
||||
}
|
||||
}
|
||||
|
||||
if (table != null) {
|
||||
tables.put(tableName, table);
|
||||
|
||||
@@ -249,8 +270,8 @@ public class SchemaRepository {
|
||||
|
||||
if (x instanceof SQLJoinTableSource) {
|
||||
SQLJoinTableSource join = (SQLJoinTableSource) x;
|
||||
computeTable(join.getLeft(), tables);
|
||||
computeTable(join.getRight(), tables);
|
||||
computeTables(join.getLeft(), tables);
|
||||
computeTables(join.getRight(), tables);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -184,6 +184,8 @@ public class TableStat {
|
||||
|
||||
private String name;
|
||||
|
||||
private int hash;
|
||||
|
||||
public Name(String name){
|
||||
this.name = name;
|
||||
}
|
||||
@@ -193,7 +195,11 @@ public class TableStat {
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return StringUtils.lowerHashCode(name);
|
||||
int h = hash;
|
||||
if (h == 0 && name != null && name.length() > 0) {
|
||||
hash = h = StringUtils.lowerHashCode(name);
|
||||
}
|
||||
return h;
|
||||
}
|
||||
|
||||
public boolean equals(Object o) {
|
||||
|
||||
Reference in New Issue
Block a user