mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
refactor sql parser.
This commit is contained in:
@@ -1,133 +0,0 @@
|
||||
/*
|
||||
* Copyright 1999-2017 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.druid.sql.dialect.sqlserver.ast;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLExpr;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLSelect;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.visitor.SQLServerASTVisitor;
|
||||
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
|
||||
public class SQLServerSelect extends SQLSelect implements SQLServerObject {
|
||||
|
||||
private boolean forBrowse;
|
||||
private List<String> forXmlOptions = new ArrayList<String>(4);
|
||||
private SQLExpr xmlPath;
|
||||
|
||||
private SQLExpr rowCount;
|
||||
private SQLExpr offset;
|
||||
|
||||
public boolean isForBrowse() {
|
||||
return forBrowse;
|
||||
}
|
||||
|
||||
public void setForBrowse(boolean forBrowse) {
|
||||
this.forBrowse = forBrowse;
|
||||
}
|
||||
|
||||
public List<String> getForXmlOptions() {
|
||||
return forXmlOptions;
|
||||
}
|
||||
|
||||
public void setForXmlOptions(List<String> forXmlOptions) {
|
||||
this.forXmlOptions = forXmlOptions;
|
||||
}
|
||||
|
||||
public SQLExpr getRowCount() {
|
||||
return rowCount;
|
||||
}
|
||||
|
||||
public void setRowCount(SQLExpr rowCount) {
|
||||
if (rowCount != null) {
|
||||
rowCount.setParent(this);
|
||||
}
|
||||
|
||||
this.rowCount = rowCount;
|
||||
}
|
||||
|
||||
public SQLExpr getOffset() {
|
||||
return offset;
|
||||
}
|
||||
|
||||
public void setOffset(SQLExpr offset) {
|
||||
if (offset != null) {
|
||||
offset.setParent(this);
|
||||
}
|
||||
this.offset = offset;
|
||||
}
|
||||
|
||||
public SQLExpr getXmlPath() {
|
||||
return xmlPath;
|
||||
}
|
||||
|
||||
public void setXmlPath(SQLExpr xmlPath) {
|
||||
if (xmlPath != null) {
|
||||
xmlPath.setParent(this);
|
||||
}
|
||||
this.xmlPath = xmlPath;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void accept0(SQLASTVisitor visitor) {
|
||||
this.accept0((SQLServerASTVisitor) visitor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept0(SQLServerASTVisitor visitor) {
|
||||
if (visitor.visit(this)) {
|
||||
acceptChild(visitor, this.query);
|
||||
acceptChild(visitor, this.orderBy);
|
||||
acceptChild(visitor, this.hints);
|
||||
acceptChild(visitor, this.offset);
|
||||
acceptChild(visitor, this.rowCount);
|
||||
}
|
||||
|
||||
visitor.endVisit(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = super.hashCode();
|
||||
result = prime * result + (forBrowse ? 1231 : 1237);
|
||||
result = prime * result + ((forXmlOptions == null) ? 0 : forXmlOptions.hashCode());
|
||||
result = prime * result + ((offset == null) ? 0 : offset.hashCode());
|
||||
result = prime * result + ((rowCount == null) ? 0 : rowCount.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) return true;
|
||||
if (!super.equals(obj)) return false;
|
||||
if (getClass() != obj.getClass()) return false;
|
||||
SQLServerSelect other = (SQLServerSelect) obj;
|
||||
if (forBrowse != other.forBrowse) return false;
|
||||
if (forXmlOptions == null) {
|
||||
if (other.forXmlOptions != null) return false;
|
||||
} else if (!forXmlOptions.equals(other.forXmlOptions)) return false;
|
||||
if (offset == null) {
|
||||
if (other.offset != null) return false;
|
||||
} else if (!offset.equals(other.offset)) return false;
|
||||
if (rowCount == null) {
|
||||
if (other.rowCount != null) return false;
|
||||
} else if (!rowCount.equals(other.rowCount)) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
+1
-2
@@ -22,7 +22,6 @@ import com.alibaba.druid.sql.ast.statement.SQLExprTableSource;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLSelect;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLSelectQuery;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLTableSource;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerSelect;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerSelectQueryBlock;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerTop;
|
||||
import com.alibaba.druid.sql.parser.ParserException;
|
||||
@@ -41,7 +40,7 @@ public class SQLServerSelectParser extends SQLSelectParser {
|
||||
}
|
||||
|
||||
public SQLSelect select() {
|
||||
SQLServerSelect select = new SQLServerSelect();
|
||||
SQLSelect select = new SQLSelect();
|
||||
|
||||
withSubquery(select);
|
||||
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
package com.alibaba.druid.sql.dialect.sqlserver.visitor;
|
||||
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerOutput;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerSelect;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerSelectQueryBlock;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerTop;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.expr.SQLServerObjectReferenceExpr;
|
||||
@@ -68,10 +67,6 @@ public interface SQLServerASTVisitor extends SQLASTVisitor {
|
||||
|
||||
void endVisit(SQLServerOutput x);
|
||||
|
||||
boolean visit(SQLServerSelect x);
|
||||
|
||||
void endVisit(SQLServerSelect x);
|
||||
|
||||
boolean visit(SQLServerRollbackStatement x);
|
||||
|
||||
void endVisit(SQLServerRollbackStatement x);
|
||||
|
||||
-11
@@ -16,7 +16,6 @@
|
||||
package com.alibaba.druid.sql.dialect.sqlserver.visitor;
|
||||
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerOutput;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerSelect;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerSelectQueryBlock;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerTop;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.expr.SQLServerObjectReferenceExpr;
|
||||
@@ -122,16 +121,6 @@ public class SQLServerASTVisitorAdapter extends SQLASTVisitorAdapter implements
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLServerSelect x) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(SQLServerSelect x) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLServerRollbackStatement x) {
|
||||
return true;
|
||||
|
||||
+1
-8
@@ -20,7 +20,6 @@ import com.alibaba.druid.sql.ast.SQLSetQuantifier;
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.*;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerOutput;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerSelect;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerSelectQueryBlock;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerTop;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.expr.SQLServerObjectReferenceExpr;
|
||||
@@ -417,13 +416,7 @@ public class SQLServerOutputVisitor extends SQLASTOutputVisitor implements SQLSe
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(SQLServerSelect x) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLServerSelect x) {
|
||||
public boolean visit(SQLSelect x) {
|
||||
super.visit(x);
|
||||
if (x.isForBrowse()) {
|
||||
println();
|
||||
|
||||
-11
@@ -20,7 +20,6 @@ import java.util.Map;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLInsertStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLSelectQueryBlock;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerOutput;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerSelect;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerSelectQueryBlock;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerTop;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.expr.SQLServerObjectReferenceExpr;
|
||||
@@ -149,16 +148,6 @@ public class SQLServerSchemaStatVisitor extends SchemaStatVisitor implements SQL
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLServerSelect x) {
|
||||
return super.visit(x);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(SQLServerSelect x) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLServerRollbackStatement x) {
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user