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
@@ -48,7 +48,6 @@ public class SQLPartition extends OracleSegmentAttributesImpl implements OracleS
private SQLObject lobStorage;
public SQLName getName() {
return name;
}
@@ -202,4 +201,53 @@ public class SQLPartition extends OracleSegmentAttributesImpl implements OracleS
public void setSegmentCreationDeferred(boolean segmentCreationDeferred) {
this.segmentCreationDeferred = segmentCreationDeferred;
}
public SQLPartition clone() {
SQLPartition x = new SQLPartition();
if (name != null) {
x.setName(name.clone());
}
if (subPartitionsCount != null) {
x.setSubPartitionsCount(subPartitionsCount.clone());
}
for (SQLSubPartition p : subPartitions) {
SQLSubPartition p2 = p.clone();
p2.setParent(x);
x.subPartitions.add(p2);
}
if (values != null) {
x.setValues(values.clone());
}
if (dataDirectory != null) {
x.setDataDirectory(dataDirectory.clone());
}
if (indexDirectory != null) {
x.setDataDirectory(indexDirectory.clone());
}
if (maxRows != null) {
x.setDataDirectory(maxRows.clone());
}
if (minRows != null) {
x.setDataDirectory(minRows.clone());
}
if (engine != null) {
x.setDataDirectory(engine.clone());
}
if (comment != null) {
x.setDataDirectory(comment.clone());
}
x.segmentCreationImmediate = segmentCreationImmediate;
x.segmentCreationDeferred = segmentCreationDeferred;
if (lobStorage != null) {
x.setLobStorage(lobStorage.clone());
}
return x;
}
}
@@ -74,4 +74,26 @@ public abstract class SQLPartitionBy extends SQLObjectImpl {
public List<SQLName> getStoreIn() {
return storeIn;
}
public void cloneTo(SQLPartitionBy x) {
if (subPartitionBy != null) {
x.setSubPartitionBy(subPartitionBy.clone());
}
if (partitionsCount != null) {
x.setPartitionsCount(partitionsCount.clone());
}
x.linear = linear;
for (SQLPartition p : partitions) {
SQLPartition p2 = p.clone();
p2.setParent(x);
x.partitions.add(p2);
}
for (SQLName name : storeIn) {
SQLName name2 = name.clone();
name2.setParent(x);
x.storeIn.add(name2);
}
}
public abstract SQLPartitionBy clone();
}
@@ -54,4 +54,15 @@ public class SQLPartitionByHash extends SQLPartitionBy {
visitor.endVisit(this);
}
public SQLPartitionByHash clone() {
SQLPartitionByHash x = new SQLPartitionByHash();
if (expr != null) {
x.setExpr(expr.clone());
}
x.key = key;
return x;
}
}
@@ -59,4 +59,20 @@ public class SQLPartitionByList extends SQLPartitionBy {
}
this.columns.add(column);
}
public SQLPartitionByList clone() {
SQLPartitionByList x = new SQLPartitionByList();
if (expr != null) {
x.setExpr(expr.clone());
}
for (SQLName column : columns) {
SQLName c2 = column.clone();
c2.setParent(x);
x.columns.add(c2);
}
return x;
}
}
@@ -79,4 +79,23 @@ public class SQLPartitionByRange extends SQLPartitionBy {
visitor.endVisit(this);
}
public SQLPartitionByRange clone() {
SQLPartitionByRange x = new SQLPartitionByRange();
if (expr != null) {
x.setExpr(expr.clone());
}
if (interval != null) {
x.setInterval(interval.clone());
}
for (SQLName column : columns) {
SQLName c2 = column.clone();
c2.setParent(x);
x.columns.add(c2);
}
return x;
}
}
@@ -58,4 +58,16 @@ public class SQLPartitionValue extends SQLObjectImpl {
}
visitor.endVisit(this);
}
public SQLPartitionValue clone() {
SQLPartitionValue x = new SQLPartitionValue(operator);
for (SQLExpr item : items) {
SQLExpr item2 = item.clone();
item2.setParent(x);
x.items.add(item2);
}
return x;
}
}
@@ -68,4 +68,21 @@ public class SQLSubPartition extends SQLObjectImpl {
visitor.endVisit(this);
}
public SQLSubPartition clone() {
SQLSubPartition x = new SQLSubPartition();
if (name != null) {
x.setName(name.clone());
}
if (values != null) {
x.setValues(values.clone());
}
if (tableSpace != null) {
x.setTableSpace(tableSpace.clone());
}
return x;
}
}
@@ -57,4 +57,23 @@ public abstract class SQLSubPartitionBy extends SQLObjectImpl {
return subPartitionTemplate;
}
public void cloneTo(SQLSubPartitionBy x) {
if (subPartitionsCount != null) {
x.setSubPartitionsCount(subPartitionsCount.clone());
}
x.linear = linear;
for (SQLAssignItem option : options) {
SQLAssignItem option2 = option.clone();
option2.setParent(x);
x.options.add(option2);
}
for (SQLSubPartition p : subPartitionTemplate) {
SQLSubPartition p2 = p.clone();
p2.setParent(x);
x.subPartitionTemplate.add(p2);
}
}
public abstract SQLSubPartitionBy clone();
}
@@ -52,4 +52,13 @@ public class SQLSubPartitionByHash extends SQLSubPartitionBy {
this.key = key;
}
public SQLSubPartitionByHash clone() {
SQLSubPartitionByHash x = new SQLSubPartitionByHash();
if (expr != null) {
x.setExpr(expr.clone());
}
x.key = key;
return x;
}
}
@@ -41,4 +41,11 @@ public class SQLSubPartitionByList extends SQLSubPartitionBy {
this.column = column;
}
public SQLSubPartitionByList clone() {
SQLSubPartitionByList x = new SQLSubPartitionByList();
if (column != null) {
x.setColumn(column.clone());
}
return x;
}
}
@@ -31,4 +31,16 @@ public class SQLSubPartitionByRange extends SQLSubPartitionBy {
protected void accept0(SQLASTVisitor visitor) {
}
public SQLSubPartitionByRange clone() {
SQLSubPartitionByRange x = new SQLSubPartitionByRange();
for (SQLName column : columns) {
SQLName c2 = column.clone();
c2.setParent(x);
x.columns.add(c2);
}
return x;
}
}
@@ -33,6 +33,17 @@ public class SQLAssignItem extends SQLObjectImpl implements SQLReplaceable {
setValue(value);
}
public SQLAssignItem clone() {
SQLAssignItem x = new SQLAssignItem();
if (target != null) {
x.setTarget(target.clone());
}
if (value != null) {
x.setValue(value.clone());
}
return x;
}
public SQLExpr getTarget() {
return target;
}
@@ -57,4 +57,10 @@ public class SQLCheck extends SQLConstraintImpl implements SQLTableElement {
expr = expr.clone();
}
}
public SQLCheck clone() {
SQLCheck x = new SQLCheck();
cloneTo(x);
return x;
}
}
@@ -737,4 +737,29 @@ public class SQLCreateTableStatement extends SQLStatementImpl implements SQLDDLS
return -1;
}
public void cloneTo(SQLCreateTableStatement x) {
x.ifNotExiists = ifNotExiists;
x.type = type;
if (tableSource != null) {
x.setTableSource(tableSource.clone());
}
for (SQLTableElement e : tableElementList) {
SQLTableElement e2 = e.clone();
e2.setParent(x);
x.tableElementList.add(e2);
}
if (inherits != null) {
x.setInherits(inherits.clone());
}
if (select != null) {
x.setSelect(select.clone());
}
}
public SQLCreateTableStatement clone() {
SQLCreateTableStatement x = new SQLCreateTableStatement();
cloneTo(x);
return x;
}
}
@@ -27,4 +27,10 @@ public class SQLPrimaryKeyImpl extends SQLUnique implements SQLPrimaryKey {
}
visitor.endVisit(this);
}
public SQLPrimaryKeyImpl clone() {
SQLPrimaryKeyImpl x = new SQLPrimaryKeyImpl();
cloneTo(x);
return x;
}
}
@@ -18,5 +18,5 @@ package com.alibaba.druid.sql.ast.statement;
import com.alibaba.druid.sql.ast.SQLObject;
public interface SQLTableElement extends SQLObject {
SQLTableElement clone();
}
@@ -72,6 +72,12 @@ public class SQLUnique extends SQLConstraintImpl implements SQLUniqueConstraint,
}
}
public SQLUnique clone() {
SQLUnique x = new SQLUnique();
cloneTo(x);
return x;
}
public void simplify() {
super.simplify();