mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
refactor
This commit is contained in:
@@ -10,6 +10,7 @@ import com.alibaba.druid.filter.wall.spi.WallVisitorUtils;
|
||||
public class WallConfig {
|
||||
|
||||
private boolean selelctAllow = true;
|
||||
private boolean selectIntoAllow = true;
|
||||
private boolean selectWhereAlwayTrueCheck = true;
|
||||
private boolean selectHavingAlwayTrueCheck = true;
|
||||
|
||||
@@ -34,10 +35,6 @@ public class WallConfig {
|
||||
|
||||
private String dir;
|
||||
|
||||
private boolean loadDefault = true;
|
||||
|
||||
private boolean loadExtend = true;
|
||||
|
||||
private boolean inited;
|
||||
|
||||
public WallConfig(){
|
||||
@@ -62,54 +59,19 @@ public class WallConfig {
|
||||
}
|
||||
|
||||
public void init() {
|
||||
if (loadDefault) {
|
||||
loadDefault(dir);
|
||||
}
|
||||
|
||||
if (loadExtend) {
|
||||
loadExtend(dir);
|
||||
}
|
||||
|
||||
inited = true;
|
||||
loadConfig(dir);
|
||||
}
|
||||
|
||||
public boolean isLoadDefault() {
|
||||
return loadDefault;
|
||||
}
|
||||
|
||||
public void setLoadDefault(boolean loadDefault) {
|
||||
this.loadDefault = loadDefault;
|
||||
}
|
||||
|
||||
public boolean isLoadExtend() {
|
||||
return loadExtend;
|
||||
}
|
||||
|
||||
public void setLoadExtend(boolean loadExtend) {
|
||||
this.loadExtend = loadExtend;
|
||||
}
|
||||
|
||||
public void loadDefault(String dir) {
|
||||
if (dir.endsWith("/")) {
|
||||
dir = dir.substring(0, dir.length() - 1);
|
||||
}
|
||||
loadResource(getPermitNames(), dir + "/permit-name-default.txt");
|
||||
loadResource(getPermitSchemas(), dir + "/permit-schema-default.txt");
|
||||
loadResource(getPermitFunctions(), dir + "/permit-function-default.txt");
|
||||
loadResource(getPermitTables(), dir + "/permit-table-default.txt");
|
||||
loadResource(getPermitObjects(), dir + "/permit-object-default.txt");
|
||||
}
|
||||
|
||||
public void loadExtend(String dir) {
|
||||
public void loadConfig(String dir) {
|
||||
if (dir.endsWith("/")) {
|
||||
dir = dir.substring(0, dir.length() - 1);
|
||||
}
|
||||
|
||||
loadResource(getPermitNames(), dir + "permit-name.txt");
|
||||
loadResource(getPermitSchemas(), dir + "permit-schema.txt");
|
||||
loadResource(getPermitFunctions(), dir + "permit-function.txt");
|
||||
loadResource(getPermitTables(), dir + "permit-table.txt");
|
||||
loadResource(getPermitObjects(), dir + "permit-object.txt");
|
||||
loadResource(getPermitNames(), dir + "/permit-name.txt");
|
||||
loadResource(getPermitSchemas(), dir + "/permit-schema.txt");
|
||||
loadResource(getPermitFunctions(), dir + "/permit-function.txt");
|
||||
loadResource(getPermitTables(), dir + "/permit-table.txt");
|
||||
loadResource(getPermitObjects(), dir + "/permit-object.txt");
|
||||
}
|
||||
|
||||
public boolean isSelelctAllow() {
|
||||
@@ -120,6 +82,14 @@ public class WallConfig {
|
||||
this.selelctAllow = selelctAllow;
|
||||
}
|
||||
|
||||
public boolean isSelectIntoAllow() {
|
||||
return selectIntoAllow;
|
||||
}
|
||||
|
||||
public void setSelectIntoAllow(boolean selectIntoAllow) {
|
||||
this.selectIntoAllow = selectIntoAllow;
|
||||
}
|
||||
|
||||
public boolean isSelectWhereAlwayTrueCheck() {
|
||||
return selectWhereAlwayTrueCheck;
|
||||
}
|
||||
|
||||
@@ -61,14 +61,14 @@ public class MySqlWallVisitor extends MySqlASTVisitorAdapter implements WallVisi
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLSelectQueryBlock x) {
|
||||
WallVisitorUtils.checkSelelctCondition(this, x.getWhere());
|
||||
WallVisitorUtils.checkSelelct(this, x);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(MySqlSelectQueryBlock x) {
|
||||
WallVisitorUtils.checkSelelctCondition(this, x.getWhere());
|
||||
WallVisitorUtils.checkSelelct(this, x);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -99,14 +99,14 @@ public class OracleWallVisitor extends OracleASTVIsitorAdapter implements WallVi
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLSelectQueryBlock x) {
|
||||
WallVisitorUtils.checkSelelctCondition(this, x.getWhere());
|
||||
WallVisitorUtils.checkSelelct(this, x);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(OracleSelectQueryBlock x) {
|
||||
WallVisitorUtils.checkSelelctCondition(this, x.getWhere());
|
||||
WallVisitorUtils.checkSelelct(this, x);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -12,7 +12,6 @@ import com.alibaba.druid.filter.wall.IllegalSQLObjectViolation;
|
||||
import com.alibaba.druid.filter.wall.WallVisitor;
|
||||
import com.alibaba.druid.logging.Log;
|
||||
import com.alibaba.druid.logging.LogFactory;
|
||||
import com.alibaba.druid.sql.SQLUtils;
|
||||
import com.alibaba.druid.sql.ast.SQLExpr;
|
||||
import com.alibaba.druid.sql.ast.SQLName;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLAggregateExpr;
|
||||
@@ -55,18 +54,20 @@ public class WallVisitorUtils {
|
||||
}
|
||||
}
|
||||
|
||||
public static void checkSelelctCondition(WallVisitor visitor, SQLExpr x) {
|
||||
if (x == null) {
|
||||
public static void checkSelelct(WallVisitor visitor, SQLSelectQueryBlock x) {
|
||||
if (!visitor.getConfig().isSelectIntoAllow() && x.getInto() != null) {
|
||||
visitor.getViolations().add(new IllegalSQLObjectViolation(visitor.toSQL(x)));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!visitor.getConfig().isSelectWhereAlwayTrueCheck()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!visitor.getConfig().isSelectHavingAlwayTrueCheck()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (Boolean.TRUE == getValue(x)) {
|
||||
if (x instanceof SQLBinaryOpExpr) {
|
||||
SQLBinaryOpExpr binaryOpExpr = (SQLBinaryOpExpr) x;
|
||||
SQLExpr where = x.getWhere();
|
||||
if (where != null && Boolean.TRUE == getValue(where)) {
|
||||
if (where instanceof SQLBinaryOpExpr) {
|
||||
SQLBinaryOpExpr binaryOpExpr = (SQLBinaryOpExpr) where;
|
||||
if (binaryOpExpr.getOperator() == SQLBinaryOperator.Equality
|
||||
|| binaryOpExpr.getOperator() == SQLBinaryOperator.NotEqual) {
|
||||
if (binaryOpExpr.getLeft() instanceof SQLIntegerExpr
|
||||
@@ -76,7 +77,7 @@ public class WallVisitorUtils {
|
||||
}
|
||||
}
|
||||
|
||||
visitor.getViolations().add(new IllegalSQLObjectViolation(SQLUtils.toSQLString(x)));
|
||||
visitor.getViolations().add(new IllegalSQLObjectViolation(visitor.toSQL(x)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,7 +91,7 @@ public class WallVisitorUtils {
|
||||
}
|
||||
|
||||
if (Boolean.TRUE == getValue(x)) {
|
||||
visitor.getViolations().add(new IllegalSQLObjectViolation(SQLUtils.toSQLString(x)));
|
||||
visitor.getViolations().add(new IllegalSQLObjectViolation(visitor.toSQL(x)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -114,7 +115,7 @@ public class WallVisitorUtils {
|
||||
visitor.getViolations().add(new IllegalSQLObjectViolation(visitor.toSQL(x)));
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (!visitor.getConfig().isUpdateWhereAlayTrueCheck()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -29,7 +29,8 @@ public class SQLSelectQueryBlock extends SQLSelectQuery {
|
||||
protected int distionOption;
|
||||
protected final List<SQLSelectItem> selectList = new ArrayList<SQLSelectItem>();
|
||||
|
||||
protected SQLTableSource from; ;
|
||||
protected SQLTableSource from;
|
||||
protected SQLExprTableSource into;
|
||||
protected SQLExpr where;
|
||||
protected SQLSelectGroupByClause groupBy;
|
||||
|
||||
@@ -37,6 +38,18 @@ public class SQLSelectQueryBlock extends SQLSelectQuery {
|
||||
|
||||
}
|
||||
|
||||
public SQLExprTableSource getInto() {
|
||||
return into;
|
||||
}
|
||||
|
||||
public void setInto(SQLExpr into) {
|
||||
this.into = new SQLExprTableSource(into);
|
||||
}
|
||||
|
||||
public void setInto(SQLExprTableSource into) {
|
||||
this.into = into;
|
||||
}
|
||||
|
||||
public SQLSelectGroupByClause getGroupBy() {
|
||||
return this.groupBy;
|
||||
}
|
||||
|
||||
+13
-28
@@ -22,7 +22,6 @@ import com.alibaba.druid.sql.ast.SQLExpr;
|
||||
import com.alibaba.druid.sql.ast.SQLName;
|
||||
import com.alibaba.druid.sql.ast.SQLObjectImpl;
|
||||
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.mysql.visitor.MySqlASTVisitor;
|
||||
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
@@ -30,43 +29,29 @@ import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
@SuppressWarnings("serial")
|
||||
public class MySqlSelectQueryBlock extends SQLSelectQueryBlock {
|
||||
|
||||
private boolean hignPriority;
|
||||
private boolean straightJoin;
|
||||
private boolean hignPriority;
|
||||
private boolean straightJoin;
|
||||
|
||||
private boolean smallResult;
|
||||
private boolean bigResult;
|
||||
private boolean bufferResult;
|
||||
private Boolean cache;
|
||||
private boolean calcFoundRows;
|
||||
private boolean smallResult;
|
||||
private boolean bigResult;
|
||||
private boolean bufferResult;
|
||||
private Boolean cache;
|
||||
private boolean calcFoundRows;
|
||||
|
||||
private SQLOrderBy orderBy;
|
||||
private SQLOrderBy orderBy;
|
||||
|
||||
private Limit limit;
|
||||
private Limit limit;
|
||||
|
||||
private SQLName procedureName;
|
||||
private List<SQLExpr> procedureArgumentList = new ArrayList<SQLExpr>();
|
||||
private SQLName procedureName;
|
||||
private List<SQLExpr> procedureArgumentList = new ArrayList<SQLExpr>();
|
||||
|
||||
private SQLExprTableSource into;
|
||||
|
||||
private boolean forUpdate = false;
|
||||
private boolean lockInShareMode = false;
|
||||
private boolean forUpdate = false;
|
||||
private boolean lockInShareMode = false;
|
||||
|
||||
public MySqlSelectQueryBlock(){
|
||||
|
||||
}
|
||||
|
||||
public SQLExprTableSource getInto() {
|
||||
return into;
|
||||
}
|
||||
|
||||
public void setInto(SQLExpr into) {
|
||||
this.into = new SQLExprTableSource(into);
|
||||
}
|
||||
|
||||
public void setInto(SQLExprTableSource into) {
|
||||
this.into = into;
|
||||
}
|
||||
|
||||
public boolean isForUpdate() {
|
||||
return forUpdate;
|
||||
}
|
||||
|
||||
@@ -111,53 +111,58 @@ public class MySqlSelectParser extends SQLSelectParser {
|
||||
|
||||
if (lexer.token() == (Token.INTO)) {
|
||||
lexer.nextToken();
|
||||
acceptIdentifier("OUTFILE");
|
||||
|
||||
MySqlOutFileExpr outFile = new MySqlOutFileExpr();
|
||||
outFile.setFile(expr());
|
||||
|
||||
queryBlock.setInto(outFile);
|
||||
|
||||
if (identifierEquals("FIELDS") || identifierEquals("COLUMNS")) {
|
||||
if (identifierEquals("OUTFILE")) {
|
||||
lexer.nextToken();
|
||||
|
||||
if (identifierEquals("TERMINATED")) {
|
||||
lexer.nextToken();
|
||||
accept(Token.BY);
|
||||
}
|
||||
outFile.setColumnsTerminatedBy((SQLLiteralExpr) expr());
|
||||
MySqlOutFileExpr outFile = new MySqlOutFileExpr();
|
||||
outFile.setFile(expr());
|
||||
|
||||
if (identifierEquals("OPTIONALLY")) {
|
||||
queryBlock.setInto(outFile);
|
||||
|
||||
if (identifierEquals("FIELDS") || identifierEquals("COLUMNS")) {
|
||||
lexer.nextToken();
|
||||
outFile.setColumnsEnclosedOptionally(true);
|
||||
|
||||
if (identifierEquals("TERMINATED")) {
|
||||
lexer.nextToken();
|
||||
accept(Token.BY);
|
||||
}
|
||||
outFile.setColumnsTerminatedBy((SQLLiteralExpr) expr());
|
||||
|
||||
if (identifierEquals("OPTIONALLY")) {
|
||||
lexer.nextToken();
|
||||
outFile.setColumnsEnclosedOptionally(true);
|
||||
}
|
||||
|
||||
if (identifierEquals("ENCLOSED")) {
|
||||
lexer.nextToken();
|
||||
accept(Token.BY);
|
||||
outFile.setColumnsEnclosedBy((SQLLiteralExpr) expr());
|
||||
}
|
||||
|
||||
if (identifierEquals("ESCAPED")) {
|
||||
lexer.nextToken();
|
||||
accept(Token.BY);
|
||||
outFile.setColumnsEscaped((SQLLiteralExpr) expr());
|
||||
}
|
||||
}
|
||||
|
||||
if (identifierEquals("ENCLOSED")) {
|
||||
if (identifierEquals("LINES")) {
|
||||
lexer.nextToken();
|
||||
accept(Token.BY);
|
||||
outFile.setColumnsEnclosedBy((SQLLiteralExpr) expr());
|
||||
}
|
||||
|
||||
if (identifierEquals("ESCAPED")) {
|
||||
lexer.nextToken();
|
||||
accept(Token.BY);
|
||||
outFile.setColumnsEscaped((SQLLiteralExpr) expr());
|
||||
}
|
||||
}
|
||||
|
||||
if (identifierEquals("LINES")) {
|
||||
lexer.nextToken();
|
||||
|
||||
if (identifierEquals("STARTING")) {
|
||||
lexer.nextToken();
|
||||
accept(Token.BY);
|
||||
outFile.setLinesStartingBy((SQLLiteralExpr) expr());
|
||||
} else {
|
||||
identifierEquals("TERMINATED");
|
||||
lexer.nextToken();
|
||||
accept(Token.BY);
|
||||
outFile.setLinesTerminatedBy((SQLLiteralExpr) expr());
|
||||
if (identifierEquals("STARTING")) {
|
||||
lexer.nextToken();
|
||||
accept(Token.BY);
|
||||
outFile.setLinesStartingBy((SQLLiteralExpr) expr());
|
||||
} else {
|
||||
identifierEquals("TERMINATED");
|
||||
lexer.nextToken();
|
||||
accept(Token.BY);
|
||||
outFile.setLinesTerminatedBy((SQLLiteralExpr) expr());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
queryBlock.setInto(this.createExprParser().name());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -198,7 +203,8 @@ public class MySqlSelectParser extends SQLSelectParser {
|
||||
|
||||
if (lexer.token() == Token.INTO) {
|
||||
lexer.nextToken();
|
||||
throw new ParserException("TODO");
|
||||
SQLExpr expr = this.createExprParser().name();
|
||||
queryBlock.setInto(expr);
|
||||
}
|
||||
|
||||
if (lexer.token() == Token.FOR) {
|
||||
|
||||
-15
@@ -18,9 +18,7 @@ package com.alibaba.druid.sql.dialect.oracle.ast.stmt;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLExpr;
|
||||
import com.alibaba.druid.sql.ast.SQLSetQuantifier;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLExprTableSource;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLSelectItem;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLSelectQueryBlock;
|
||||
import com.alibaba.druid.sql.dialect.oracle.ast.OracleHint;
|
||||
@@ -36,24 +34,11 @@ public class OracleSelectQueryBlock extends SQLSelectQueryBlock {
|
||||
|
||||
private OracleSelectHierachicalQueryClause hierachicalQueryClause;
|
||||
private ModelClause modelClause;
|
||||
private SQLExprTableSource into;
|
||||
|
||||
public OracleSelectQueryBlock(){
|
||||
|
||||
}
|
||||
|
||||
public SQLExprTableSource getInto() {
|
||||
return into;
|
||||
}
|
||||
|
||||
public void setInto(SQLExpr into) {
|
||||
this.into = new SQLExprTableSource(into);
|
||||
}
|
||||
|
||||
public void setInto(SQLExprTableSource into) {
|
||||
this.into = into;
|
||||
}
|
||||
|
||||
public ModelClause getModelClause() {
|
||||
return modelClause;
|
||||
}
|
||||
|
||||
+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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -496,6 +496,12 @@ public class SchemaStatVisitor extends SQLASTVisitorAdapter {
|
||||
x.putAttribute(ATTR_TABLE, table);
|
||||
}
|
||||
}
|
||||
|
||||
// String ident = x.getTable().toString();
|
||||
//
|
||||
// TableStat stat = getTableStat(ident);
|
||||
// stat.incrementInsertCount();
|
||||
// return false;
|
||||
|
||||
if (x.getWhere() != null) {
|
||||
x.getWhere().setParent(x);
|
||||
|
||||
Reference in New Issue
Block a user