improved sql parser.

This commit is contained in:
wenshao
2017-06-05 20:27:08 +08:00
parent bea1d70af2
commit d9a0cae840
14 changed files with 431 additions and 9 deletions
@@ -183,7 +183,6 @@ public class SQLSelect extends SQLObjectImpl {
public boolean isSimple() {
return withSubQuery == null
&& orderBy == null
&& (hints == null || hints.size() == 0)
&& restriction == null
&& (!forBrowse)
@@ -272,6 +272,9 @@ public class SQLSelectQueryBlock extends SQLObjectImpl implements SQLSelectQuery
acceptChild(visitor, this.startWith);
acceptChild(visitor, this.connectBy);
acceptChild(visitor, this.groupBy);
acceptChild(visitor, this.orderBy);
acceptChild(visitor, this.waitTime);
acceptChild(visitor, this.limit);
}
visitor.endVisit(this);
}
@@ -386,4 +389,30 @@ public class SQLSelectQueryBlock extends SQLObjectImpl implements SQLSelectQuery
public void setBracket(boolean bracket) {
this.bracket = bracket;
}
public SQLTableSource findTableSource(String alias) {
return findTableSource(from, alias);
}
private static SQLTableSource findTableSource(SQLTableSource from, String alias) {
if (from == null || alias == null) {
return null;
}
if (alias.equalsIgnoreCase(from.computeAlias())) {
return from;
}
if (from instanceof SQLJoinTableSource) {
SQLJoinTableSource join = (SQLJoinTableSource) from;
SQLTableSource result = findTableSource(join.getLeft(), alias);
if (result != null) {
return result;
}
return findTableSource(join.getRight(), alias);
}
return null;
}
}