mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
refactor
This commit is contained in:
@@ -90,137 +90,138 @@ public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTV
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean visit(MySqlSelectQueryBlock select) {
|
||||
if (select.getOrderBy() != null) {
|
||||
select.getOrderBy().setParent(select);
|
||||
public boolean visit(MySqlSelectQueryBlock x) {
|
||||
if (x.getOrderBy() != null) {
|
||||
x.getOrderBy().setParent(x);
|
||||
}
|
||||
|
||||
print("SELECT ");
|
||||
|
||||
if (SQLSetQuantifier.ALL == select.getDistionOption()) print("ALL ");
|
||||
else if (SQLSetQuantifier.DISTINCT == select.getDistionOption()) print("DISTINCT ");
|
||||
else if (SQLSetQuantifier.DISTINCTROW == select.getDistionOption()) {
|
||||
if (SQLSetQuantifier.ALL == x.getDistionOption()) print("ALL ");
|
||||
else if (SQLSetQuantifier.DISTINCT == x.getDistionOption()) print("DISTINCT ");
|
||||
else if (SQLSetQuantifier.DISTINCTROW == x.getDistionOption()) {
|
||||
print("DISTINCTROW ");
|
||||
}
|
||||
|
||||
if (select.isHignPriority()) {
|
||||
if (x.isHignPriority()) {
|
||||
print("HIGH_PRIORITY ");
|
||||
}
|
||||
|
||||
if (select.isSmallResult()) {
|
||||
if (x.isSmallResult()) {
|
||||
print("SQL_SMALL_RESULT ");
|
||||
}
|
||||
|
||||
if (select.isBigResult()) {
|
||||
if (x.isBigResult()) {
|
||||
print("SQL_BIG_RESULT ");
|
||||
}
|
||||
|
||||
if (select.isBufferResult()) {
|
||||
if (x.isBufferResult()) {
|
||||
print("SQL_BUFFER_RESULT ");
|
||||
}
|
||||
|
||||
if (select.getCache() != null) {
|
||||
if (select.getCache().booleanValue()) {
|
||||
if (x.getCache() != null) {
|
||||
if (x.getCache().booleanValue()) {
|
||||
print("SQL_CACHE ");
|
||||
} else {
|
||||
print("SQL_NO_CACHE ");
|
||||
}
|
||||
}
|
||||
|
||||
if (select.isCalcFoundRows()) {
|
||||
if (x.isCalcFoundRows()) {
|
||||
print("SQL_CALC_FOUND_ROWS ");
|
||||
}
|
||||
|
||||
printSelectList(select.getSelectList());
|
||||
printSelectList(x.getSelectList());
|
||||
|
||||
if (select.getOutFile() != null) {
|
||||
if (x.getOutFile() != null) {
|
||||
println();
|
||||
print("INTO OUTFILE ");
|
||||
select.getOutFile().accept(this);
|
||||
if (select.getOutFileCharset() != null) {
|
||||
x.getOutFile().accept(this);
|
||||
if (x.getOutFileCharset() != null) {
|
||||
print(" CHARACTER SET ");
|
||||
print(select.getOutFileCharset());
|
||||
print(x.getOutFileCharset());
|
||||
}
|
||||
|
||||
if (select.getOutFileColumnsTerminatedBy() != null || select.getOutFileColumnsEnclosedBy() != null
|
||||
|| select.getOutFileColumnsEscaped() != null) {
|
||||
if (x.getOutFileColumnsTerminatedBy() != null || x.getOutFileColumnsEnclosedBy() != null
|
||||
|| x.getOutFileColumnsEscaped() != null) {
|
||||
print(" COLUMNS");
|
||||
if (select.getOutFileColumnsTerminatedBy() != null) {
|
||||
if (x.getOutFileColumnsTerminatedBy() != null) {
|
||||
print(" TERMINATED BY ");
|
||||
select.getOutFileColumnsTerminatedBy().accept(this);
|
||||
x.getOutFileColumnsTerminatedBy().accept(this);
|
||||
}
|
||||
|
||||
if (select.getOutFileColumnsEnclosedBy() != null) {
|
||||
if (select.isOutFileColumnsEnclosedOptionally()) {
|
||||
if (x.getOutFileColumnsEnclosedBy() != null) {
|
||||
if (x.isOutFileColumnsEnclosedOptionally()) {
|
||||
print(" OPTIONALLY");
|
||||
}
|
||||
print(" ENCLOSED BY ");
|
||||
select.getOutFileColumnsEnclosedBy().accept(this);
|
||||
x.getOutFileColumnsEnclosedBy().accept(this);
|
||||
}
|
||||
|
||||
if (select.getOutFileColumnsEscaped() != null) {
|
||||
if (x.getOutFileColumnsEscaped() != null) {
|
||||
print(" ESCAPED BY ");
|
||||
select.getOutFileColumnsEscaped().accept(this);
|
||||
x.getOutFileColumnsEscaped().accept(this);
|
||||
}
|
||||
}
|
||||
|
||||
if (select.getOutFileLinesStartingBy() != null || select.getOutFileLinesTerminatedBy() != null) {
|
||||
if (x.getOutFileLinesStartingBy() != null || x.getOutFileLinesTerminatedBy() != null) {
|
||||
print(" LINES");
|
||||
if (select.getOutFileLinesStartingBy() != null) {
|
||||
if (x.getOutFileLinesStartingBy() != null) {
|
||||
print(" STARTING BY ");
|
||||
select.getOutFileLinesStartingBy().accept(this);
|
||||
x.getOutFileLinesStartingBy().accept(this);
|
||||
}
|
||||
|
||||
if (select.getOutFileLinesTerminatedBy() != null) {
|
||||
if (x.getOutFileLinesTerminatedBy() != null) {
|
||||
print(" TERMINATED BY ");
|
||||
select.getOutFileLinesTerminatedBy().accept(this);
|
||||
x.getOutFileLinesTerminatedBy().accept(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (select.getFrom() != null) {
|
||||
if (x.getFrom() != null) {
|
||||
println();
|
||||
print("FROM ");
|
||||
select.getFrom().accept(this);
|
||||
x.getFrom().accept(this);
|
||||
}
|
||||
|
||||
if (select.getWhere() != null) {
|
||||
if (x.getWhere() != null) {
|
||||
println();
|
||||
print("WHERE ");
|
||||
select.getWhere().accept(this);
|
||||
x.getWhere().setParent(x);
|
||||
x.getWhere().accept(this);
|
||||
}
|
||||
|
||||
if (select.getGroupBy() != null) {
|
||||
if (x.getGroupBy() != null) {
|
||||
println();
|
||||
select.getGroupBy().accept(this);
|
||||
x.getGroupBy().accept(this);
|
||||
}
|
||||
|
||||
if (select.getOrderBy() != null) {
|
||||
if (x.getOrderBy() != null) {
|
||||
println();
|
||||
select.getOrderBy().accept(this);
|
||||
x.getOrderBy().accept(this);
|
||||
}
|
||||
|
||||
if (select.getLimit() != null) {
|
||||
if (x.getLimit() != null) {
|
||||
println();
|
||||
select.getLimit().accept(this);
|
||||
x.getLimit().accept(this);
|
||||
}
|
||||
|
||||
if (select.getProcedureName() != null) {
|
||||
if (x.getProcedureName() != null) {
|
||||
print(" PROCEDURE ");
|
||||
select.getProcedureName().accept(this);
|
||||
if (select.getProcedureArgumentList().size() > 0) {
|
||||
x.getProcedureName().accept(this);
|
||||
if (x.getProcedureArgumentList().size() > 0) {
|
||||
print("(");
|
||||
printAndAccept(select.getProcedureArgumentList(), ", ");
|
||||
printAndAccept(x.getProcedureArgumentList(), ", ");
|
||||
print(")");
|
||||
}
|
||||
}
|
||||
|
||||
if (select.isForUpdate()) {
|
||||
if (x.isForUpdate()) {
|
||||
println();
|
||||
print("FOR UPDATE");
|
||||
}
|
||||
|
||||
if (select.isLockInShareMode()) {
|
||||
if (x.isLockInShareMode()) {
|
||||
println();
|
||||
print("LOCK IN SHARE MODE");
|
||||
}
|
||||
@@ -675,6 +676,7 @@ public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTV
|
||||
if (x.getWhere() != null) {
|
||||
println();
|
||||
print("WHERE ");
|
||||
x.getWhere().setParent(x);
|
||||
x.getWhere().accept(this);
|
||||
}
|
||||
|
||||
@@ -1036,6 +1038,7 @@ public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTV
|
||||
|
||||
if (x.getWhere() != null) {
|
||||
print(" WHERE ");
|
||||
x.getWhere().setParent(x);
|
||||
x.getWhere().accept(this);
|
||||
}
|
||||
|
||||
@@ -1067,6 +1070,7 @@ public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTV
|
||||
|
||||
if (x.getWhere() != null) {
|
||||
print(" WHERE ");
|
||||
x.getWhere().setParent(x);
|
||||
x.getWhere().accept(this);
|
||||
}
|
||||
|
||||
@@ -1089,6 +1093,7 @@ public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTV
|
||||
|
||||
if (x.getWhere() != null) {
|
||||
print(" WHERE ");
|
||||
x.getWhere().setParent(x);
|
||||
x.getWhere().accept(this);
|
||||
}
|
||||
|
||||
@@ -1141,6 +1146,7 @@ public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTV
|
||||
|
||||
if (x.getWhere() != null) {
|
||||
print(" WHERE ");
|
||||
x.getWhere().setParent(x);
|
||||
x.getWhere().accept(this);
|
||||
}
|
||||
|
||||
|
||||
+61
-51
@@ -274,6 +274,7 @@ public class OracleOutputVisitor extends SQLASTOutputVisitor implements OracleAS
|
||||
if (x.getWhere() != null) {
|
||||
println();
|
||||
print("WHERE ");
|
||||
x.getWhere().setParent(x);
|
||||
x.getWhere().accept(this);
|
||||
}
|
||||
|
||||
@@ -438,30 +439,40 @@ public class OracleOutputVisitor extends SQLASTOutputVisitor implements OracleAS
|
||||
x.getLeft().accept(this);
|
||||
|
||||
if (x.getJoinType() == JoinType.COMMA) {
|
||||
print(",");
|
||||
print(", ");
|
||||
x.getRight().accept(this);
|
||||
} else {
|
||||
print(" ");
|
||||
print(JoinType.toString(x.getJoinType()));
|
||||
}
|
||||
|
||||
print(" ");
|
||||
x.getRight().accept(this);
|
||||
|
||||
if (x.getCondition() != null) {
|
||||
print(" ON ");
|
||||
x.getCondition().accept(this);
|
||||
print(" ");
|
||||
}
|
||||
|
||||
if (x.getUsing().size() > 0) {
|
||||
print(" USING (");
|
||||
printAndAccept(x.getUsing(), ", ");
|
||||
print(")");
|
||||
}
|
||||
|
||||
if (x.getFlashback() != null) {
|
||||
boolean isRoot = x.getParent() instanceof SQLSelectQueryBlock;
|
||||
if (isRoot) {
|
||||
incrementIndent();
|
||||
}
|
||||
|
||||
println();
|
||||
x.getFlashback().accept(this);
|
||||
print(JoinType.toString(x.getJoinType()));
|
||||
print(" ");
|
||||
|
||||
x.getRight().accept(this);
|
||||
|
||||
if (isRoot) {
|
||||
decrementIndent();
|
||||
}
|
||||
|
||||
if (x.getCondition() != null) {
|
||||
print(" ON ");
|
||||
x.getCondition().accept(this);
|
||||
print(" ");
|
||||
}
|
||||
|
||||
if (x.getUsing().size() > 0) {
|
||||
print(" USING (");
|
||||
printAndAccept(x.getUsing(), ", ");
|
||||
print(")");
|
||||
}
|
||||
|
||||
if (x.getFlashback() != null) {
|
||||
println();
|
||||
x.getFlashback().accept(this);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
@@ -529,58 +540,60 @@ public class OracleOutputVisitor extends SQLASTOutputVisitor implements OracleAS
|
||||
return super.visit(select);
|
||||
}
|
||||
|
||||
public boolean visit(OracleSelectQueryBlock select) {
|
||||
public boolean visit(OracleSelectQueryBlock x) {
|
||||
print("SELECT ");
|
||||
|
||||
if (SQLSetQuantifier.ALL == select.getDistionOption()) {
|
||||
if (SQLSetQuantifier.ALL == x.getDistionOption()) {
|
||||
print("ALL ");
|
||||
} else if (SQLSetQuantifier.DISTINCT == select.getDistionOption()) {
|
||||
} else if (SQLSetQuantifier.DISTINCT == x.getDistionOption()) {
|
||||
print("DISTINCT ");
|
||||
} else if (SQLSetQuantifier.UNIQUE == select.getDistionOption()) {
|
||||
} else if (SQLSetQuantifier.UNIQUE == x.getDistionOption()) {
|
||||
print("UNIQUE ");
|
||||
}
|
||||
|
||||
if (select.getHints().size() > 0) {
|
||||
if (x.getHints().size() > 0) {
|
||||
print("/*+");
|
||||
printAndAccept(select.getHints(), ", ");
|
||||
printAndAccept(x.getHints(), ", ");
|
||||
print("*/ ");
|
||||
}
|
||||
|
||||
printSelectList(select.getSelectList());
|
||||
printSelectList(x.getSelectList());
|
||||
|
||||
if (select.getInto() != null) {
|
||||
if (x.getInto() != null) {
|
||||
println();
|
||||
print("INTO ");
|
||||
select.getInto().accept(this);
|
||||
x.getInto().accept(this);
|
||||
}
|
||||
|
||||
println();
|
||||
print("FROM ");
|
||||
if (select.getFrom() == null) {
|
||||
if (x.getFrom() == null) {
|
||||
print("DUAL");
|
||||
} else {
|
||||
select.getFrom().accept(this);
|
||||
x.getFrom().setParent(x);
|
||||
x.getFrom().accept(this);
|
||||
}
|
||||
|
||||
if (select.getWhere() != null) {
|
||||
if (x.getWhere() != null) {
|
||||
println();
|
||||
print("WHERE ");
|
||||
select.getWhere().accept(this);
|
||||
x.getWhere().setParent(x);
|
||||
x.getWhere().accept(this);
|
||||
}
|
||||
|
||||
if (select.getHierachicalQueryClause() != null) {
|
||||
if (x.getHierachicalQueryClause() != null) {
|
||||
println();
|
||||
select.getHierachicalQueryClause().accept(this);
|
||||
x.getHierachicalQueryClause().accept(this);
|
||||
}
|
||||
|
||||
if (select.getGroupBy() != null) {
|
||||
if (x.getGroupBy() != null) {
|
||||
println();
|
||||
select.getGroupBy().accept(this);
|
||||
x.getGroupBy().accept(this);
|
||||
}
|
||||
|
||||
if (select.getModelClause() != null) {
|
||||
if (x.getModelClause() != null) {
|
||||
println();
|
||||
select.getModelClause().accept(this);
|
||||
x.getModelClause().accept(this);
|
||||
}
|
||||
|
||||
return false;
|
||||
@@ -603,18 +616,15 @@ public class OracleOutputVisitor extends SQLASTOutputVisitor implements OracleAS
|
||||
public boolean visit(OracleSelectSubqueryTableSource x) {
|
||||
print("(");
|
||||
incrementIndent();
|
||||
x.getSelect().accept(this);
|
||||
println();
|
||||
x.getSelect().accept(this);
|
||||
decrementIndent();
|
||||
println();
|
||||
print(")");
|
||||
|
||||
if (x.getPivot() != null) {
|
||||
incrementIndent();
|
||||
|
||||
println();
|
||||
x.getPivot().accept(this);
|
||||
|
||||
decrementIndent();
|
||||
}
|
||||
|
||||
if (x.getFlashback() != null) {
|
||||
@@ -655,17 +665,13 @@ public class OracleOutputVisitor extends SQLASTOutputVisitor implements OracleAS
|
||||
}
|
||||
|
||||
if (x.getSampleClause() != null) {
|
||||
println();
|
||||
print(" ");
|
||||
x.getSampleClause().accept(this);
|
||||
}
|
||||
|
||||
if (x.getPivot() != null) {
|
||||
incrementIndent();
|
||||
|
||||
println();
|
||||
x.getPivot().accept(this);
|
||||
|
||||
decrementIndent();
|
||||
}
|
||||
|
||||
if (x.getFlashback() != null) {
|
||||
@@ -812,6 +818,7 @@ public class OracleOutputVisitor extends SQLASTOutputVisitor implements OracleAS
|
||||
if (x.getWhere() != null) {
|
||||
println();
|
||||
print("WHERE ");
|
||||
x.getWhere().setParent(x);
|
||||
x.getWhere().accept(this);
|
||||
}
|
||||
|
||||
@@ -1496,6 +1503,7 @@ public class OracleOutputVisitor extends SQLASTOutputVisitor implements OracleAS
|
||||
incrementIndent();
|
||||
println();
|
||||
print("WHERE ");
|
||||
x.getWhere().setParent(x);
|
||||
x.getWhere().accept(this);
|
||||
decrementIndent();
|
||||
}
|
||||
@@ -1504,6 +1512,7 @@ public class OracleOutputVisitor extends SQLASTOutputVisitor implements OracleAS
|
||||
incrementIndent();
|
||||
println();
|
||||
print("DELETE WHERE ");
|
||||
x.getDeleteWhere().setParent(x);
|
||||
x.getDeleteWhere().accept(this);
|
||||
decrementIndent();
|
||||
}
|
||||
@@ -1530,6 +1539,7 @@ public class OracleOutputVisitor extends SQLASTOutputVisitor implements OracleAS
|
||||
incrementIndent();
|
||||
println();
|
||||
print("WHERE ");
|
||||
x.getWhere().setParent(x);
|
||||
x.getWhere().accept(this);
|
||||
decrementIndent();
|
||||
}
|
||||
|
||||
@@ -179,6 +179,7 @@ public class PGOutputVisitor extends SQLASTOutputVisitor implements PGASTVisitor
|
||||
if (x.getWhere() != null) {
|
||||
println();
|
||||
print("WHERE ");
|
||||
x.getWhere().setParent(x);
|
||||
x.getWhere().accept(this);
|
||||
}
|
||||
|
||||
@@ -305,6 +306,7 @@ public class PGOutputVisitor extends SQLASTOutputVisitor implements PGASTVisitor
|
||||
if (x.getWhere() != null) {
|
||||
println();
|
||||
print("WHERE ");
|
||||
x.getWhere().setParent(x);
|
||||
x.getWhere().accept(this);
|
||||
}
|
||||
|
||||
@@ -435,6 +437,7 @@ public class PGOutputVisitor extends SQLASTOutputVisitor implements PGASTVisitor
|
||||
if (x.getWhere() != null) {
|
||||
println();
|
||||
print("WHERE ");
|
||||
x.getWhere().setParent(x);
|
||||
x.getWhere().accept(this);
|
||||
}
|
||||
|
||||
|
||||
+14
-13
@@ -11,38 +11,39 @@ public class SQLServerOutputVisitor extends SQLASTOutputVisitor implements SQLSe
|
||||
super(appender);
|
||||
}
|
||||
|
||||
public boolean visit(SQLServerSelectQueryBlock select) {
|
||||
public boolean visit(SQLServerSelectQueryBlock x) {
|
||||
print("SELECT ");
|
||||
|
||||
if (SQLSetQuantifier.ALL == select.getDistionOption()) {
|
||||
if (SQLSetQuantifier.ALL == x.getDistionOption()) {
|
||||
print("ALL ");
|
||||
} else if (SQLSetQuantifier.DISTINCT == select.getDistionOption()) {
|
||||
} else if (SQLSetQuantifier.DISTINCT == x.getDistionOption()) {
|
||||
print("DISTINCT ");
|
||||
} else if (SQLSetQuantifier.UNIQUE == select.getDistionOption()) {
|
||||
} else if (SQLSetQuantifier.UNIQUE == x.getDistionOption()) {
|
||||
print("UNIQUE ");
|
||||
}
|
||||
|
||||
if (select.getTop() != null) {
|
||||
select.getTop().accept(this);
|
||||
if (x.getTop() != null) {
|
||||
x.getTop().accept(this);
|
||||
}
|
||||
|
||||
printSelectList(select.getSelectList());
|
||||
printSelectList(x.getSelectList());
|
||||
|
||||
if (select.getFrom() != null) {
|
||||
if (x.getFrom() != null) {
|
||||
println();
|
||||
print("FROM ");
|
||||
select.getFrom().accept(this);
|
||||
x.getFrom().accept(this);
|
||||
}
|
||||
|
||||
if (select.getWhere() != null) {
|
||||
if (x.getWhere() != null) {
|
||||
println();
|
||||
print("WHERE ");
|
||||
select.getWhere().accept(this);
|
||||
x.getWhere().setParent(x);
|
||||
x.getWhere().accept(this);
|
||||
}
|
||||
|
||||
if (select.getGroupBy() != null) {
|
||||
if (x.getGroupBy() != null) {
|
||||
print(" ");
|
||||
select.getGroupBy().accept(this);
|
||||
x.getGroupBy().accept(this);
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user