improved sql parser.

This commit is contained in:
wenshao
2017-08-01 19:05:31 +08:00
parent c2adc8bfd4
commit 544da04ee4
32 changed files with 489 additions and 4 deletions
@@ -25,7 +25,6 @@ import com.alibaba.druid.util.JdbcConstants;
public class MySqlKey extends SQLUnique implements SQLUniqueConstraint, SQLTableConstraint {
private String indexType;
private boolean hasConstaint;
@@ -66,4 +65,15 @@ public class MySqlKey extends SQLUnique implements SQLUniqueConstraint, SQLTable
this.hasConstaint = hasConstaint;
}
public void cloneTo(MySqlKey x) {
super.cloneTo(x);
x.indexType = indexType;
x.hasConstaint = hasConstaint;
}
public MySqlKey clone() {
MySqlKey x = new MySqlKey();
cloneTo(x);
return x;
}
}
@@ -32,4 +32,10 @@ public class MySqlPrimaryKey extends MySqlKey implements SQLPrimaryKey {
}
visitor.endVisit(this);
}
public MySqlPrimaryKey clone() {
MySqlPrimaryKey x = new MySqlPrimaryKey();
cloneTo(x);
return x;
}
}
@@ -31,4 +31,10 @@ public class MySqlUnique extends MySqlKey {
}
visitor.endVisit(this);
}
public MySqlUnique clone() {
MySqlUnique x = new MySqlUnique();
cloneTo(x);
return x;
}
}
@@ -342,4 +342,38 @@ public class MySqlCreateTableStatement extends SQLCreateTableStatement implement
public void output(StringBuffer buf) {
this.accept(new MySqlOutputVisitor(buf));
}
public void cloneTo(MySqlCreateTableStatement x) {
super.cloneTo(x);
for (Map.Entry<String, SQLObject> entry : tableOptions.entrySet()) {
SQLObject obj = entry.getValue().clone();
obj.setParent(x);
x.tableOptions.put(entry.getKey(), obj);
}
if (partitioning != null) {
x.setPartitioning(partitioning.clone());
}
for (SQLCommentHint hint : hints) {
SQLCommentHint h2 = hint.clone();
h2.setParent(x);
x.hints.add(h2);
}
for (SQLCommentHint hint : optionHints) {
SQLCommentHint h2 = hint.clone();
h2.setParent(x);
x.optionHints.add(h2);
}
if (like != null) {
x.setLike(like.clone());
}
if (tableGroup != null) {
x.setTableGroup(tableGroup.clone());
}
}
public MySqlCreateTableStatement clone() {
MySqlCreateTableStatement x = new MySqlCreateTableStatement();
cloneTo(x);
return x;
}
}
@@ -59,4 +59,18 @@ public class MySqlPartitionByKey extends SQLPartitionBy implements MySqlObject {
this.columns.add(column);
}
public void cloneTo(MySqlPartitionByKey x) {
super.cloneTo(x);
for (SQLName column : columns) {
SQLName c2 = column.clone();
c2.setParent(x);
x.columns.add(c2);
}
}
public MySqlPartitionByKey clone() {
MySqlPartitionByKey x = new MySqlPartitionByKey();
cloneTo(x);
return x;
}
}
@@ -57,4 +57,18 @@ public class MySqlSubPartitionByKey extends SQLSubPartitionBy implements MySqlOb
this.columns.add(column);
}
public void cloneTo(MySqlSubPartitionByKey x) {
super.cloneTo(x);
for (SQLName column : columns) {
SQLName c2 = column.clone();
c2.setParent(x);
x.columns.add(c2);
}
}
public MySqlSubPartitionByKey clone() {
MySqlSubPartitionByKey x = new MySqlSubPartitionByKey();
cloneTo(x);
return x;
}
}
@@ -19,6 +19,7 @@ import java.util.ArrayList;
import java.util.List;
import com.alibaba.druid.sql.ast.SQLExpr;
import com.alibaba.druid.sql.ast.SQLName;
import com.alibaba.druid.sql.ast.SQLSubPartitionBy;
import com.alibaba.druid.sql.ast.statement.SQLColumnDefinition;
import com.alibaba.druid.sql.dialect.mysql.ast.MySqlObject;
@@ -72,4 +73,21 @@ public class MySqlSubPartitionByList extends SQLSubPartitionBy implements MySqlO
this.columns.add(column);
}
public void cloneTo(MySqlSubPartitionByList x) {
super.cloneTo(x);
if (expr != null) {
x.setExpr(expr.clone());
}
for (SQLColumnDefinition column : columns) {
SQLColumnDefinition c2 = column.clone();
c2.setParent(x);
x.columns.add(c2);
}
}
public MySqlSubPartitionByList clone() {
MySqlSubPartitionByList x = new MySqlSubPartitionByList();
cloneTo(x);
return x;
}
}
@@ -20,6 +20,7 @@ import java.util.List;
import com.alibaba.druid.sql.ast.SQLExpr;
import com.alibaba.druid.sql.ast.SQLName;
import com.alibaba.druid.sql.ast.statement.SQLColumnDefinition;
import com.alibaba.druid.sql.ast.statement.SQLSelectOrderByItem;
import com.alibaba.druid.sql.ast.statement.SQLTableElement;
import com.alibaba.druid.sql.dialect.mysql.ast.MySqlObjectImpl;
@@ -69,4 +70,18 @@ public class MySqlTableIndex extends MySqlObjectImpl implements SQLTableElement
}
visitor.endVisit(this);
}
public MySqlTableIndex clone() {
MySqlTableIndex x = new MySqlTableIndex();
if (name != null) {
x.setName(name.clone());
}
x.indexType = indexType;
for (SQLSelectOrderByItem column : columns) {
SQLSelectOrderByItem c2 = column.clone();
c2.setParent(x);
x.columns.add(c2);
}
return x;
}
}