SQLASTOutputVisitor support exportTables.

This commit is contained in:
wenshao
2016-12-10 22:42:20 +08:00
parent 3c1acd06b8
commit fae7e4dcf0
2 changed files with 94 additions and 0 deletions
@@ -47,6 +47,9 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Paramet
protected boolean groupItemSingleLine = false;
protected List<Object> parameters;
protected Set<String> tables;
protected boolean exportTables = false;
protected String dbType;
@@ -108,6 +111,10 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Paramet
return parameters;
}
public Set<String> getTables() {
return this.tables;
}
public void setParameters(List<Object> parameters) {
this.parameters = parameters;
}
@@ -152,6 +159,14 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Paramet
this.parameterizedMergeInList = parameterizedMergeInList;
}
public boolean isExportTables() {
return exportTables;
}
public void setExportTables(boolean exportTables) {
this.exportTables = exportTables;
}
public void print(char value) {
if (this.appender == null) {
return;
@@ -1066,9 +1081,21 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Paramet
return false;
}
protected void addTable(String table) {
if (tables == null) {
tables = new HashSet<String>();
}
this.tables.add(table);
}
protected void printTableSourceExpr(SQLExpr expr) {
if (exportTables) {
addTable(expr.toString());
}
if (tableMapping != null && expr instanceof SQLName) {
String tableName = expr.toString();
String destTableName = tableMapping.get(tableName);
if (destTableName != null) {
tableName = destTableName;