mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
refactor
This commit is contained in:
+9
-46
@@ -5,7 +5,6 @@ import java.util.List;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLExpr;
|
||||
import com.alibaba.druid.sql.ast.SQLOrderBy;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLExprTableSource;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLSelectQueryBlock;
|
||||
import com.alibaba.druid.sql.dialect.postgresql.ast.PGSQLObjectImpl;
|
||||
import com.alibaba.druid.sql.dialect.postgresql.ast.PGWithClause;
|
||||
@@ -25,14 +24,18 @@ public class PGSelectQueryBlock extends SQLSelectQueryBlock {
|
||||
private SQLOrderBy orderBy;
|
||||
private FetchClause fetch;
|
||||
private ForClause forClause;
|
||||
private IntoClause into;
|
||||
private IntoOption intoOption;
|
||||
|
||||
public IntoClause getInto() {
|
||||
return into;
|
||||
public static enum IntoOption {
|
||||
TEMPORARY, TEMP, UNLOGGED
|
||||
}
|
||||
|
||||
public void setInto(IntoClause into) {
|
||||
this.into = into;
|
||||
public IntoOption getIntoOption() {
|
||||
return intoOption;
|
||||
}
|
||||
|
||||
public void setIntoOption(IntoOption intoOption) {
|
||||
this.intoOption = intoOption;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -237,44 +240,4 @@ public class PGSelectQueryBlock extends SQLSelectQueryBlock {
|
||||
}
|
||||
}
|
||||
|
||||
public static class IntoClause extends PGSQLObjectImpl {
|
||||
|
||||
public static enum Option {
|
||||
TEMPORARY, TEMP, UNLOGGED
|
||||
}
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private SQLExprTableSource table;
|
||||
private Option option;
|
||||
|
||||
public Option getOption() {
|
||||
return option;
|
||||
}
|
||||
|
||||
public void setOption(Option option) {
|
||||
this.option = option;
|
||||
}
|
||||
|
||||
public SQLExprTableSource getTable() {
|
||||
return table;
|
||||
}
|
||||
|
||||
public void setTable(SQLExpr table) {
|
||||
this.table = new SQLExprTableSource(table);
|
||||
}
|
||||
|
||||
public void setTable(SQLExprTableSource table) {
|
||||
this.table = table;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept0(PGASTVisitor visitor) {
|
||||
if (visitor.visit(this)) {
|
||||
acceptChild(visitor, table);
|
||||
}
|
||||
visitor.endVisit(this);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,9 +3,10 @@ package com.alibaba.druid.sql.dialect.postgresql.parser;
|
||||
import com.alibaba.druid.sql.ast.SQLExpr;
|
||||
import com.alibaba.druid.sql.ast.SQLSetQuantifier;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLExprTableSource;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLSelectQuery;
|
||||
import com.alibaba.druid.sql.dialect.postgresql.ast.stmt.PGSelectQueryBlock;
|
||||
import com.alibaba.druid.sql.dialect.postgresql.ast.stmt.PGSelectQueryBlock.IntoClause;
|
||||
import com.alibaba.druid.sql.dialect.postgresql.ast.stmt.PGSelectQueryBlock.IntoOption;
|
||||
import com.alibaba.druid.sql.parser.Lexer;
|
||||
import com.alibaba.druid.sql.parser.ParserException;
|
||||
import com.alibaba.druid.sql.parser.SQLSelectParser;
|
||||
@@ -55,18 +56,17 @@ public class PGSelectParser extends SQLSelectParser {
|
||||
parseSelectList(queryBlock);
|
||||
|
||||
if (lexer.token() == Token.INTO) {
|
||||
IntoClause into = new IntoClause();
|
||||
lexer.nextToken();
|
||||
|
||||
if (lexer.token() == Token.TEMPORARY) {
|
||||
lexer.nextToken();
|
||||
into.setOption(IntoClause.Option.TEMPORARY);
|
||||
queryBlock.setIntoOption(IntoOption.TEMPORARY);
|
||||
} else if (lexer.token() == Token.TEMP) {
|
||||
lexer.nextToken();
|
||||
into.setOption(IntoClause.Option.TEMP);
|
||||
queryBlock.setIntoOption(IntoOption.TEMP);
|
||||
} else if (lexer.token() == Token.UNLOGGED) {
|
||||
lexer.nextToken();
|
||||
into.setOption(IntoClause.Option.UNLOGGED);
|
||||
queryBlock.setIntoOption(IntoOption.UNLOGGED);
|
||||
}
|
||||
|
||||
if (lexer.token() == Token.TABLE) {
|
||||
@@ -74,9 +74,8 @@ public class PGSelectParser extends SQLSelectParser {
|
||||
}
|
||||
|
||||
SQLExpr name = this.createExprParser().name();
|
||||
into.setTable(name);
|
||||
|
||||
queryBlock.setInto(into);
|
||||
queryBlock.setInto(new SQLExprTableSource(name));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -12,8 +12,12 @@ import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
|
||||
public interface PGASTVisitor extends SQLASTVisitor {
|
||||
|
||||
void endVisit(PGSelectQueryBlock.WindowClause x);
|
||||
void endVisit(PGSelectQueryBlock x);
|
||||
|
||||
boolean visit(PGSelectQueryBlock x);
|
||||
|
||||
void endVisit(PGSelectQueryBlock.WindowClause x);
|
||||
|
||||
boolean visit(PGSelectQueryBlock.WindowClause x);
|
||||
|
||||
void endVisit(PGSelectQueryBlock.FetchClause x);
|
||||
@@ -32,27 +36,23 @@ public interface PGASTVisitor extends SQLASTVisitor {
|
||||
|
||||
boolean visit(PGWithClause x);
|
||||
|
||||
void endVisit(PGSelectQueryBlock.IntoClause x);
|
||||
|
||||
boolean visit(PGSelectQueryBlock.IntoClause x);
|
||||
|
||||
void endVisit(PGTruncateStatement x);
|
||||
|
||||
boolean visit(PGTruncateStatement x);
|
||||
|
||||
|
||||
void endVisit(PGDeleteStatement x);
|
||||
|
||||
|
||||
boolean visit(PGDeleteStatement x);
|
||||
|
||||
|
||||
void endVisit(PGInsertStatement x);
|
||||
|
||||
|
||||
boolean visit(PGInsertStatement x);
|
||||
|
||||
|
||||
void endVisit(PGSelectStatement x);
|
||||
|
||||
|
||||
boolean visit(PGSelectStatement x);
|
||||
|
||||
|
||||
void endVisit(PGUpdateStatement x);
|
||||
|
||||
|
||||
boolean visit(PGUpdateStatement x);
|
||||
}
|
||||
|
||||
+24
-25
@@ -4,9 +4,9 @@ import com.alibaba.druid.sql.dialect.postgresql.ast.PGWithClause;
|
||||
import com.alibaba.druid.sql.dialect.postgresql.ast.PGWithQuery;
|
||||
import com.alibaba.druid.sql.dialect.postgresql.ast.stmt.PGDeleteStatement;
|
||||
import com.alibaba.druid.sql.dialect.postgresql.ast.stmt.PGInsertStatement;
|
||||
import com.alibaba.druid.sql.dialect.postgresql.ast.stmt.PGSelectQueryBlock;
|
||||
import com.alibaba.druid.sql.dialect.postgresql.ast.stmt.PGSelectQueryBlock.FetchClause;
|
||||
import com.alibaba.druid.sql.dialect.postgresql.ast.stmt.PGSelectQueryBlock.ForClause;
|
||||
import com.alibaba.druid.sql.dialect.postgresql.ast.stmt.PGSelectQueryBlock.IntoClause;
|
||||
import com.alibaba.druid.sql.dialect.postgresql.ast.stmt.PGSelectQueryBlock.WindowClause;
|
||||
import com.alibaba.druid.sql.dialect.postgresql.ast.stmt.PGSelectStatement;
|
||||
import com.alibaba.druid.sql.dialect.postgresql.ast.stmt.PGTruncateStatement;
|
||||
@@ -70,17 +70,6 @@ public class PGASTVisitorAdapter extends SQLASTVisitorAdapter implements PGASTVi
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(IntoClause x) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(IntoClause x) {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(PGTruncateStatement x) {
|
||||
|
||||
@@ -91,46 +80,56 @@ public class PGASTVisitorAdapter extends SQLASTVisitorAdapter implements PGASTVi
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void endVisit(PGDeleteStatement x) {
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean visit(PGDeleteStatement x) {
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void endVisit(PGInsertStatement x) {
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean visit(PGInsertStatement x) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void endVisit(PGSelectStatement x) {
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean visit(PGSelectStatement x) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void endVisit(PGUpdateStatement x) {
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean visit(PGUpdateStatement x) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(PGSelectQueryBlock x) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(PGSelectQueryBlock x) {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+10
-25
@@ -1,7 +1,6 @@
|
||||
package com.alibaba.druid.sql.dialect.postgresql.visitor;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLSetQuantifier;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLSelectQueryBlock;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLSelectStatement;
|
||||
import com.alibaba.druid.sql.dialect.postgresql.ast.PGWithClause;
|
||||
import com.alibaba.druid.sql.dialect.postgresql.ast.PGWithQuery;
|
||||
@@ -10,7 +9,6 @@ import com.alibaba.druid.sql.dialect.postgresql.ast.stmt.PGInsertStatement;
|
||||
import com.alibaba.druid.sql.dialect.postgresql.ast.stmt.PGSelectQueryBlock;
|
||||
import com.alibaba.druid.sql.dialect.postgresql.ast.stmt.PGSelectQueryBlock.FetchClause;
|
||||
import com.alibaba.druid.sql.dialect.postgresql.ast.stmt.PGSelectQueryBlock.ForClause;
|
||||
import com.alibaba.druid.sql.dialect.postgresql.ast.stmt.PGSelectQueryBlock.IntoClause;
|
||||
import com.alibaba.druid.sql.dialect.postgresql.ast.stmt.PGSelectQueryBlock.WindowClause;
|
||||
import com.alibaba.druid.sql.dialect.postgresql.ast.stmt.PGSelectStatement;
|
||||
import com.alibaba.druid.sql.dialect.postgresql.ast.stmt.PGTruncateStatement;
|
||||
@@ -135,14 +133,6 @@ public class PGOutputVisitor extends SQLASTOutputVisitor implements PGASTVisitor
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean visit(SQLSelectQueryBlock x) {
|
||||
if (x instanceof PGSelectQueryBlock) {
|
||||
return visit((PGSelectQueryBlock) x);
|
||||
}
|
||||
|
||||
return super.visit(x);
|
||||
}
|
||||
|
||||
public boolean visit(PGSelectQueryBlock x) {
|
||||
if (x.getWith() != null) {
|
||||
x.getWith().accept(this);
|
||||
@@ -166,6 +156,11 @@ public class PGOutputVisitor extends SQLASTOutputVisitor implements PGASTVisitor
|
||||
|
||||
if (x.getInto() != null) {
|
||||
println();
|
||||
if (x.getIntoOption() != null) {
|
||||
print(x.getIntoOption().name());
|
||||
print(" ");
|
||||
}
|
||||
|
||||
x.getInto().accept(this);
|
||||
}
|
||||
|
||||
@@ -223,21 +218,6 @@ public class PGOutputVisitor extends SQLASTOutputVisitor implements PGASTVisitor
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(IntoClause x) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(IntoClause x) {
|
||||
print("INTO ");
|
||||
if (x.getOption() != null) {
|
||||
print(x.getOption().name());
|
||||
print(" ");
|
||||
}
|
||||
x.getTable().accept(this);
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(PGTruncateStatement x) {
|
||||
@@ -435,4 +415,9 @@ public class PGOutputVisitor extends SQLASTOutputVisitor implements PGASTVisitor
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(PGSelectQueryBlock x) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
+14
-16
@@ -4,15 +4,16 @@ import java.util.Map;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLName;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLSelectQueryBlock;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLSelectStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLTruncateStatement;
|
||||
import com.alibaba.druid.sql.dialect.postgresql.ast.PGWithClause;
|
||||
import com.alibaba.druid.sql.dialect.postgresql.ast.PGWithQuery;
|
||||
import com.alibaba.druid.sql.dialect.postgresql.ast.stmt.PGDeleteStatement;
|
||||
import com.alibaba.druid.sql.dialect.postgresql.ast.stmt.PGInsertStatement;
|
||||
import com.alibaba.druid.sql.dialect.postgresql.ast.stmt.PGSelectQueryBlock;
|
||||
import com.alibaba.druid.sql.dialect.postgresql.ast.stmt.PGSelectQueryBlock.FetchClause;
|
||||
import com.alibaba.druid.sql.dialect.postgresql.ast.stmt.PGSelectQueryBlock.ForClause;
|
||||
import com.alibaba.druid.sql.dialect.postgresql.ast.stmt.PGSelectQueryBlock.IntoClause;
|
||||
import com.alibaba.druid.sql.dialect.postgresql.ast.stmt.PGSelectQueryBlock.WindowClause;
|
||||
import com.alibaba.druid.sql.dialect.postgresql.ast.stmt.PGSelectStatement;
|
||||
import com.alibaba.druid.sql.dialect.postgresql.ast.stmt.PGTruncateStatement;
|
||||
@@ -87,20 +88,6 @@ public class PGSchemaStatVisitor extends SchemaStatVisitor implements PGASTVisit
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(IntoClause x) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(IntoClause x) {
|
||||
String ident = x.getTable().toString();
|
||||
|
||||
TableStat stat = getTableStat(ident);
|
||||
stat.incrementInsertCount();
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(PGTruncateStatement x) {
|
||||
|
||||
@@ -196,7 +183,7 @@ public class PGSchemaStatVisitor extends SchemaStatVisitor implements PGASTVisit
|
||||
public void endVisit(PGSelectStatement x) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean visit(PGSelectStatement x) {
|
||||
if (x.getWith() != null) {
|
||||
@@ -237,4 +224,15 @@ public class PGSchemaStatVisitor extends SchemaStatVisitor implements PGASTVisit
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(PGSelectQueryBlock x) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(PGSelectQueryBlock x) {
|
||||
this.visit((SQLSelectQueryBlock) x);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user