mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
refactor
This commit is contained in:
@@ -26,7 +26,7 @@ import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
public class SQLCreateTableStatement extends SQLStatementImpl {
|
||||
|
||||
protected Type type;
|
||||
protected SQLName name;
|
||||
protected SQLExprTableSource tableSource;
|
||||
|
||||
protected List<SQLTableElement> tableElementList = new ArrayList<SQLTableElement>();
|
||||
|
||||
@@ -35,11 +35,23 @@ public class SQLCreateTableStatement extends SQLStatementImpl {
|
||||
}
|
||||
|
||||
public SQLName getName() {
|
||||
return name;
|
||||
if (tableSource == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (SQLName) tableSource.getExpr();
|
||||
}
|
||||
|
||||
public void setName(SQLName name) {
|
||||
this.name = name;
|
||||
this.setTableSource(new SQLExprTableSource(name));
|
||||
}
|
||||
|
||||
public SQLExprTableSource getTableSource() {
|
||||
return tableSource;
|
||||
}
|
||||
|
||||
public void setTableSource(SQLExprTableSource tableSource) {
|
||||
this.tableSource = tableSource;
|
||||
}
|
||||
|
||||
public Type getType() {
|
||||
@@ -67,7 +79,7 @@ public class SQLCreateTableStatement extends SQLStatementImpl {
|
||||
buf.append("LOCAL TEMPORARY ");
|
||||
}
|
||||
|
||||
this.name.output(buf);
|
||||
this.tableSource.output(buf);
|
||||
buf.append(" ");
|
||||
|
||||
buf.append("(");
|
||||
@@ -83,7 +95,7 @@ public class SQLCreateTableStatement extends SQLStatementImpl {
|
||||
@Override
|
||||
protected void accept0(SQLASTVisitor visitor) {
|
||||
if (visitor.visit(this)) {
|
||||
this.acceptChild(visitor, name);
|
||||
this.acceptChild(visitor, tableSource);
|
||||
this.acceptChild(visitor, tableElementList);
|
||||
}
|
||||
visitor.endVisit(this);
|
||||
|
||||
@@ -9,21 +9,25 @@ import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
|
||||
public class SQLTruncateStatement extends SQLStatementImpl {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
protected List<SQLName> tableNames = new ArrayList<SQLName>(2);
|
||||
private static final long serialVersionUID = 1L;
|
||||
protected List<SQLExprTableSource> tableSources = new ArrayList<SQLExprTableSource>(2);
|
||||
|
||||
public List<SQLName> getTableNames() {
|
||||
return tableNames;
|
||||
public List<SQLExprTableSource> getTableSources() {
|
||||
return tableSources;
|
||||
}
|
||||
|
||||
public void setTableNames(List<SQLName> tableNames) {
|
||||
this.tableNames = tableNames;
|
||||
public void setTableSources(List<SQLExprTableSource> tableSources) {
|
||||
this.tableSources = tableSources;
|
||||
}
|
||||
|
||||
public void addTableSource(SQLName name) {
|
||||
this.tableSources.add(new SQLExprTableSource(name));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void accept0(SQLASTVisitor visitor) {
|
||||
if (visitor.visit(this)) {
|
||||
acceptChild(visitor, tableNames);
|
||||
acceptChild(visitor, tableSources);
|
||||
}
|
||||
visitor.endVisit(this);
|
||||
}
|
||||
|
||||
+1
-1
@@ -29,7 +29,7 @@ public class HiveCreateTableStatement extends SQLCreateTableStatement implements
|
||||
@Override
|
||||
public void accept0(HiveASTVisitor visitor) {
|
||||
if (visitor.visit(this)) {
|
||||
this.acceptChild(visitor, name);
|
||||
this.acceptChild(visitor, tableSource);
|
||||
this.acceptChild(visitor, tableElementList);
|
||||
this.acceptChild(visitor, partitionedBy);
|
||||
}
|
||||
|
||||
+1
-1
@@ -69,7 +69,7 @@ public class MySqlCreateTableStatement extends SQLCreateTableStatement {
|
||||
buf.append("IF NOT EXISTS ");
|
||||
}
|
||||
|
||||
this.name.output(buf);
|
||||
this.tableSource.output(buf);
|
||||
buf.append(" ");
|
||||
buf.append("(");
|
||||
for (int i = 0, size = tableElementList.size(); i < size; ++i) {
|
||||
|
||||
+1
-1
@@ -184,7 +184,7 @@ public class OracleCreateTableStatement extends SQLCreateTableStatement implemen
|
||||
|
||||
public void accept0(OracleASTVisitor visitor) {
|
||||
if (visitor.visit(this)) {
|
||||
this.acceptChild(visitor, name);
|
||||
this.acceptChild(visitor, tableSource);
|
||||
this.acceptChild(visitor, tableElementList);
|
||||
this.acceptChild(visitor, tablespace);
|
||||
this.acceptChild(visitor, select);
|
||||
|
||||
+1
-1
@@ -17,7 +17,7 @@ public class OracleTruncateStatement extends SQLTruncateStatement implements Ora
|
||||
|
||||
public void accept0(OracleASTVisitor visitor) {
|
||||
if (visitor.visit(this)) {
|
||||
acceptChild(visitor, tableNames);
|
||||
acceptChild(visitor, tableSources);
|
||||
}
|
||||
visitor.endVisit(this);
|
||||
}
|
||||
|
||||
+1
-1
@@ -580,7 +580,7 @@ public class OracleStatementParser extends SQLStatementParser {
|
||||
OracleTruncateStatement stmt = new OracleTruncateStatement();
|
||||
|
||||
SQLName name = this.exprParser.name();
|
||||
stmt.getTableNames().add(name);
|
||||
stmt.addTableSource(name);
|
||||
|
||||
if (identifierEquals("PURGE")) {
|
||||
lexer.nextToken();
|
||||
|
||||
@@ -2839,7 +2839,7 @@ public class OracleOutputVisitor extends SQLASTOutputVisitor implements OracleAS
|
||||
@Override
|
||||
public boolean visit(OracleTruncateStatement x) {
|
||||
print("TRUNCATE TABLE ");
|
||||
printAndAccept(x.getTableNames(), ", ");
|
||||
printAndAccept(x.getTableSources(), ", ");
|
||||
|
||||
if (x.isPurgeSnapshotLog()) {
|
||||
print(" PURGE SNAPSHOT LOG");
|
||||
|
||||
+1
-1
@@ -37,7 +37,7 @@ public class PGTruncateStatement extends SQLTruncateStatement implements PGSQLSt
|
||||
|
||||
public void accept0(PGASTVisitor visitor) {
|
||||
if (visitor.visit(this)) {
|
||||
acceptChild(visitor, tableNames);
|
||||
acceptChild(visitor, tableSources);
|
||||
}
|
||||
visitor.endVisit(this);
|
||||
}
|
||||
|
||||
+1
-1
@@ -205,7 +205,7 @@ public class PGSQLStatementParser extends SQLStatementParser {
|
||||
|
||||
for (;;) {
|
||||
SQLName name = this.exprParser.name();
|
||||
stmt.getTableNames().add(name);
|
||||
stmt.addTableSource(name);
|
||||
|
||||
if (lexer.token() == Token.COMMA) {
|
||||
lexer.nextToken();
|
||||
|
||||
@@ -251,7 +251,7 @@ public class PGOutputVisitor extends SQLASTOutputVisitor implements PGASTVisitor
|
||||
print("ONLY ");
|
||||
}
|
||||
|
||||
printlnAndAccept(x.getTableNames(), ", ");
|
||||
printlnAndAccept(x.getTableSources(), ", ");
|
||||
|
||||
if (x.getRestartIdentity() != null) {
|
||||
if (x.getRestartIdentity().booleanValue()) {
|
||||
|
||||
@@ -176,7 +176,7 @@ public class SQLStatementParser extends SQLParser {
|
||||
|
||||
for (;;) {
|
||||
SQLName name = this.exprParser.name();
|
||||
stmt.getTableNames().add(name);
|
||||
stmt.addTableSource(name);
|
||||
|
||||
if (lexer.token() == Token.COMMA) {
|
||||
lexer.nextToken();
|
||||
|
||||
@@ -967,7 +967,7 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter {
|
||||
@Override
|
||||
public boolean visit(SQLTruncateStatement x) {
|
||||
print("TRUNCATE TABLE ");
|
||||
printAndAccept(x.getTableNames(), ", ");
|
||||
printAndAccept(x.getTableSources(), ", ");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -377,7 +377,9 @@ public class SchemaStatVisitor extends SQLASTVisitorAdapter {
|
||||
|
||||
String originalTable = getCurrentTable();
|
||||
|
||||
for (SQLName name : x.getTableNames()) {
|
||||
for (SQLExprTableSource tableSource : x.getTableSources()) {
|
||||
SQLName name = (SQLName) tableSource.getExpr();
|
||||
|
||||
String ident = name.toString();
|
||||
setCurrentTable(ident);
|
||||
x.putAttribute("_old_local_", originalTable);
|
||||
|
||||
Reference in New Issue
Block a user