mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
sql paser refactor SQLColumnDefinition
This commit is contained in:
-100
@@ -1,100 +0,0 @@
|
||||
/*
|
||||
* Copyright 1999-2101 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 com.alibaba.druid.sql.ast.statement.SQLColumnDefinition;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.visitor.SQLServerASTVisitor;
|
||||
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
|
||||
public class SQLServerColumnDefinition extends SQLColumnDefinition implements SQLServerObject {
|
||||
|
||||
private Identity identity;
|
||||
|
||||
public SQLServerColumnDefinition(){
|
||||
|
||||
}
|
||||
|
||||
public Identity getIdentity() {
|
||||
return identity;
|
||||
}
|
||||
|
||||
public void setIdentity(Identity identity) {
|
||||
if (identity != null) {
|
||||
identity.setParent(this);
|
||||
}
|
||||
this.identity = identity;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void accept0(SQLASTVisitor visitor) {
|
||||
this.accept0((SQLServerASTVisitor) visitor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept0(SQLServerASTVisitor visitor) {
|
||||
if (visitor.visit(this)) {
|
||||
this.acceptChild(visitor, name);
|
||||
this.acceptChild(visitor, dataType);
|
||||
this.acceptChild(visitor, defaultExpr);
|
||||
this.acceptChild(visitor, constraints);
|
||||
this.acceptChild(visitor, identity);
|
||||
}
|
||||
visitor.endVisit(this);
|
||||
}
|
||||
|
||||
public static class Identity extends SQLServerObjectImpl {
|
||||
|
||||
private Integer seed;
|
||||
private Integer increment;
|
||||
|
||||
private boolean notForReplication;
|
||||
|
||||
public Identity(){
|
||||
|
||||
}
|
||||
|
||||
public Integer getSeed() {
|
||||
return seed;
|
||||
}
|
||||
|
||||
public void setSeed(Integer seed) {
|
||||
this.seed = seed;
|
||||
}
|
||||
|
||||
public Integer getIncrement() {
|
||||
return increment;
|
||||
}
|
||||
|
||||
public void setIncrement(Integer increment) {
|
||||
this.increment = increment;
|
||||
}
|
||||
|
||||
public boolean isNotForReplication() {
|
||||
return notForReplication;
|
||||
}
|
||||
|
||||
public void setNotForReplication(boolean notForReplication) {
|
||||
this.notForReplication = notForReplication;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept0(SQLServerASTVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
visitor.endVisit(this);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
+3
-5
@@ -26,7 +26,6 @@ import com.alibaba.druid.sql.ast.expr.SQLPropertyExpr;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLColumnDefinition;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLExprTableSource;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLSelectItem;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerColumnDefinition;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerOutput;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerTop;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.expr.SQLServerObjectReferenceExpr;
|
||||
@@ -192,7 +191,7 @@ public class SQLServerExprParser extends SQLExprParser {
|
||||
}
|
||||
|
||||
public SQLColumnDefinition createColumnDefinition() {
|
||||
SQLColumnDefinition column = new SQLServerColumnDefinition();
|
||||
SQLColumnDefinition column = new SQLColumnDefinition();
|
||||
return column;
|
||||
}
|
||||
|
||||
@@ -206,7 +205,7 @@ public class SQLServerExprParser extends SQLExprParser {
|
||||
SQLIntegerExpr increment = (SQLIntegerExpr) this.primary();
|
||||
accept(Token.RPAREN);
|
||||
|
||||
SQLServerColumnDefinition.Identity identity = new SQLServerColumnDefinition.Identity();
|
||||
SQLColumnDefinition.Identity identity = new SQLColumnDefinition.Identity();
|
||||
identity.setSeed((Integer) seed.getNumber());
|
||||
identity.setIncrement((Integer) increment.getNumber());
|
||||
|
||||
@@ -223,8 +222,7 @@ public class SQLServerExprParser extends SQLExprParser {
|
||||
}
|
||||
}
|
||||
|
||||
SQLServerColumnDefinition sqlSreverColumn = (SQLServerColumnDefinition) column;
|
||||
sqlSreverColumn.setIdentity(identity);
|
||||
column.setIdentity(identity);
|
||||
}
|
||||
|
||||
return super.parseColumnRest(column);
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
*/
|
||||
package com.alibaba.druid.sql.dialect.sqlserver.visitor;
|
||||
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerColumnDefinition;
|
||||
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;
|
||||
@@ -55,14 +54,6 @@ public interface SQLServerASTVisitor extends SQLASTVisitor {
|
||||
|
||||
void endVisit(SQLServerUpdateStatement x);
|
||||
|
||||
boolean visit(SQLServerColumnDefinition x);
|
||||
|
||||
void endVisit(SQLServerColumnDefinition x);
|
||||
|
||||
boolean visit(SQLServerColumnDefinition.Identity x);
|
||||
|
||||
void endVisit(SQLServerColumnDefinition.Identity x);
|
||||
|
||||
boolean visit(SQLServerExecStatement x);
|
||||
|
||||
void endVisit(SQLServerExecStatement x);
|
||||
|
||||
-21
@@ -15,7 +15,6 @@
|
||||
*/
|
||||
package com.alibaba.druid.sql.dialect.sqlserver.visitor;
|
||||
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerColumnDefinition;
|
||||
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;
|
||||
@@ -85,26 +84,6 @@ public class SQLServerASTVisitorAdapter extends SQLASTVisitorAdapter implements
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLServerColumnDefinition.Identity x) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(SQLServerColumnDefinition.Identity x) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLServerColumnDefinition x) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(SQLServerColumnDefinition x) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLServerExecStatement x) {
|
||||
return true;
|
||||
|
||||
+1
-30
@@ -24,8 +24,6 @@ import com.alibaba.druid.sql.ast.statement.SQLColumnConstraint;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLColumnDefinition;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLExprTableSource;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLGrantStatement;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerColumnDefinition;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerColumnDefinition.Identity;
|
||||
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;
|
||||
@@ -275,22 +273,7 @@ public class SQLServerOutputVisitor extends SQLASTOutputVisitor implements SQLSe
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(Identity x) {
|
||||
print0(ucase ? "IDENTITY (" : "identity (");
|
||||
print(x.getSeed());
|
||||
print0(", ");
|
||||
print(x.getIncrement());
|
||||
print(')');
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(Identity x) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLServerColumnDefinition x) {
|
||||
public boolean visit(SQLColumnDefinition x) {
|
||||
x.getName().accept(this);
|
||||
|
||||
if (x.getDataType() != null) {
|
||||
@@ -321,18 +304,6 @@ public class SQLServerOutputVisitor extends SQLASTOutputVisitor implements SQLSe
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(SQLServerColumnDefinition x) {
|
||||
|
||||
}
|
||||
|
||||
public boolean visit(SQLColumnDefinition x) {
|
||||
if (x instanceof SQLServerColumnDefinition) {
|
||||
return visit((SQLServerColumnDefinition) x);
|
||||
}
|
||||
return super.visit(x);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLServerExecStatement x) {
|
||||
print0(ucase ? "EXEC " : "exec ");
|
||||
|
||||
-23
@@ -19,11 +19,8 @@ import java.util.Map;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLDeclareItem;
|
||||
import com.alibaba.druid.sql.ast.SQLExpr;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLColumnDefinition;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLInsertStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLSelectQueryBlock;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerColumnDefinition;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerColumnDefinition.Identity;
|
||||
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;
|
||||
@@ -116,26 +113,6 @@ public class SQLServerSchemaStatVisitor extends SchemaStatVisitor implements SQL
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(Identity x) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(Identity x) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLServerColumnDefinition x) {
|
||||
return visit((SQLColumnDefinition) x);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(SQLServerColumnDefinition x) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLServerExecStatement x) {
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user