improved sql parser.

This commit is contained in:
wenshao
2017-08-03 10:41:23 +08:00
parent 9df6894d83
commit b0c38aef68
70 changed files with 1091 additions and 109 deletions
@@ -27,4 +27,9 @@ public class MySqlForceIndexHint extends MySqlIndexHintImpl {
visitor.endVisit(this);
}
public MySqlForceIndexHint clone() {
MySqlForceIndexHint x = new MySqlForceIndexHint();
cloneTo(x);
return x;
}
}
@@ -27,4 +27,9 @@ public class MySqlIgnoreIndexHint extends MySqlIndexHintImpl {
visitor.endVisit(this);
}
public MySqlIgnoreIndexHint clone() {
MySqlIgnoreIndexHint x = new MySqlIgnoreIndexHint();
cloneTo(x);
return x;
}
}
@@ -46,4 +46,14 @@ public abstract class MySqlIndexHintImpl extends MySqlObjectImpl implements MySq
this.indexList = indexList;
}
public abstract MySqlIndexHintImpl clone();
public void cloneTo(MySqlIndexHintImpl x) {
x.option = option;
for (SQLName name : indexList) {
SQLName name2 = name.clone();
name2.setParent(x);
x.indexList.add(name2);
}
}
}
@@ -27,4 +27,9 @@ public class MySqlUseIndexHint extends MySqlIndexHintImpl {
visitor.endVisit(this);
}
public MySqlUseIndexHint clone() {
MySqlUseIndexHint x = new MySqlUseIndexHint();
cloneTo(x);
return x;
}
}
@@ -34,6 +34,21 @@ public class MySqlInsertStatement extends SQLInsertStatement {
private final List<SQLExpr> duplicateKeyUpdate = new ArrayList<SQLExpr>();
public void cloneTo(MySqlInsertStatement x) {
super.cloneTo(x);
x.lowPriority = lowPriority;
x.delayed = delayed;
x.highPriority = highPriority;
x.ignore = ignore;
x.rollbackOnFail = rollbackOnFail;
for (SQLExpr e : duplicateKeyUpdate) {
SQLExpr e2 = e.clone();
e2.setParent(x);
x.duplicateKeyUpdate.add(e2);
}
}
public List<SQLExpr> getDuplicateKeyUpdate() {
return duplicateKeyUpdate;
}
@@ -102,4 +117,10 @@ public class MySqlInsertStatement extends SQLInsertStatement {
visitor.endVisit(this);
}
public SQLInsertStatement clone() {
MySqlInsertStatement x = new MySqlInsertStatement();
cloneTo(x);
return x;
}
}
@@ -69,4 +69,32 @@ public class NameResolveVisitor extends OracleASTVisitorAdapter {
}
return true;
}
public boolean visit(SQLPropertyExpr x) {
String ownerName = x.getOwnernName();
if (ownerName == null) {
return super.visit(x);
}
for (SQLObject parent = x.getParent(); parent != null; parent = parent.getParent()) {
if (parent instanceof SQLSelectQueryBlock) {
SQLSelectQueryBlock queryBlock = (SQLSelectQueryBlock) parent;
SQLTableSource tableSource = queryBlock.findTableSource(ownerName);
if (tableSource == null) {
continue;
}
String alias = tableSource.getAlias();
if (tableSource != null
&& ownerName.equalsIgnoreCase(alias)
&& !ownerName.equals(alias)) {
x.setOwner(alias);
}
break;
}
}
return super.visit(x);
}
}
@@ -35,7 +35,7 @@ public abstract class OracleSQLObjectImpl extends SQLObjectImpl implements Oracl
public abstract void accept0(OracleASTVisitor visitor);
public OracleSQLObject clone() {
throw new UnsupportedOperationException();
throw new UnsupportedOperationException(this.getClass().getName());
}
public SQLDataType computeDataType() {
@@ -58,4 +58,21 @@ public class OracleReturningClause extends OracleSQLObjectImpl {
visitor.endVisit(this);
}
public OracleReturningClause clone() {
OracleReturningClause x = new OracleReturningClause();
for (SQLExpr item : items) {
SQLExpr item2 = item.clone();
item2.setParent(x);
x.items.add(item2);
}
for (SQLExpr v : values) {
SQLExpr v2 = v.clone();
v2.setParent(x);
x.values.add(v2);
}
return x;
}
}
@@ -34,6 +34,43 @@ public class OracleStorageClause extends OracleSQLObjectImpl {
private FlashCacheType flashCache;
private FlashCacheType cellFlashCache;
public OracleStorageClause clone() {
OracleStorageClause x = new OracleStorageClause();
if (initial != null) {
x.setInitial(initial.clone());
}
if (next != null) {
x.setNext(next.clone());
}
if (minExtents != null) {
x.setMinExtents(minExtents.clone());
}
if (maxExtents != null) {
x.setMinExtents(maxExtents.clone());
}
if (maxSize != null) {
x.setMaxSize(maxSize.clone());
}
if (pctIncrease != null) {
x.setPctIncrease(pctIncrease.clone());
}
if (freeLists != null) {
x.setFreeLists(freeLists.clone());
}
if (freeListGroups != null) {
x.setFreeListGroups(freeListGroups.clone());
}
if (bufferPool != null) {
x.setBufferPool(bufferPool.clone());
}
if (objno != null) {
x.setObjno(objno.clone());
}
x.flashCache = flashCache;
x.cellFlashCache = cellFlashCache;
return x;
}
@Override
public void accept0(OracleASTVisitor visitor) {
if (visitor.visit(this)) {
@@ -95,4 +95,7 @@ public class OracleBinaryDoubleExpr extends SQLNumericLiteralExpr implements Ora
this.setValue(number.doubleValue());
}
public OracleBinaryDoubleExpr clone() {
return new OracleBinaryDoubleExpr(value);
}
}
@@ -32,6 +32,10 @@ public class OracleBinaryFloatExpr extends SQLNumericLiteralExpr implements Orac
this.value = value;
}
public OracleBinaryFloatExpr clone() {
return new OracleBinaryFloatExpr(value);
}
@Override
public Number getNumber() {
return value;
@@ -34,6 +34,19 @@ public class OracleIntervalExpr extends SQLExprImpl implements SQLLiteralExpr, O
}
public OracleIntervalExpr clone() {
OracleIntervalExpr x = new OracleIntervalExpr();
if (value != null) {
x.setValue(value.clone());
}
x.type = type;
x.precision = precision;
x.factionalSecondsPrecision = factionalSecondsPrecision;
x.toType = toType;
x.toFactionalSecondsPrecision = toFactionalSecondsPrecision;
return x;
}
public SQLExpr getValue() {
return this.value;
}
@@ -84,4 +84,21 @@ public class OracleCheck extends SQLCheck implements OracleConstraint, OracleSQL
this.using = using;
}
public void cloneTo(OracleCheck x) {
super.cloneTo(x);
if (using != null) {
x.setUsing(using.clone());
}
if (exceptionsInto != null) {
x.setExceptionsInto(exceptionsInto.clone());
}
x.initially = initially;
x.deferrable = deferrable;
}
public OracleCheck clone() {
OracleCheck x = new OracleCheck();
cloneTo(x);
return x;
}
}
@@ -48,4 +48,6 @@ public interface OracleConstraint extends OracleSQLObject, SQLConstraint, SQLTab
public static enum Initially {
DEFERRED, IMMEDIATE
}
OracleConstraint clone();
}
@@ -72,6 +72,18 @@ public class OracleExceptionStatement extends OracleStatementImpl implements Ora
visitor.endVisit(this);
}
public Item clone() {
Item x = new Item();
if (when != null) {
x.setWhen(when.clone());
}
for (SQLStatement stmt : statements) {
SQLStatement stmt2 = stmt.clone();
stmt2.setParent(x);
x.statements.add(stmt2);
}
return x;
}
}
@Override
@@ -81,4 +93,14 @@ public class OracleExceptionStatement extends OracleStatementImpl implements Ora
}
visitor.endVisit(this);
}
public OracleExceptionStatement clone() {
OracleExceptionStatement x = new OracleExceptionStatement();
for (Item item : items) {
Item item2 = item.clone();
item2.setParent(x);
x.items.add(item2);
}
return x;
}
}
@@ -86,4 +86,24 @@ public class OracleForStatement extends OracleStatementImpl {
}
this.endLabel = endLabel;
}
public OracleForStatement clone() {
OracleForStatement x = new OracleForStatement();
if (index != null) {
x.setIndex(index.clone());
}
if (range != null) {
x.setRange(range.clone());
}
for (SQLStatement stmt : statements) {
SQLStatement stmt2 = stmt.clone();
stmt2.setParent(x);
x.statements.add(stmt2);
}
x.all = all;
if (endLabel != null) {
x.setEndLabel(endLabel.clone());
}
return x;
}
}
@@ -86,4 +86,21 @@ public class OracleForeignKey extends SQLForeignKeyImpl implements OracleConstra
this.using = using;
}
public void cloneTo(OracleForeignKey x) {
super.cloneTo(x);
if (using != null) {
x.setUsing(using.clone());
}
if (exceptionsInto != null) {
x.setExceptionsInto(exceptionsInto.clone());
}
x.initially = initially;
x.deferrable = deferrable;
}
public OracleForeignKey clone() {
OracleForeignKey x = new OracleForeignKey();
cloneTo(x);
return x;
}
}
@@ -28,9 +28,24 @@ import com.alibaba.druid.sql.visitor.SQLASTVisitor;
public class OracleInsertStatement extends SQLInsertStatement implements OracleStatement {
private OracleReturningClause returning;
private OracleReturningClause returning;
private SQLErrorLoggingClause errorLogging;
private List<SQLHint> hints = new ArrayList<SQLHint>();
private List<SQLHint> hints = new ArrayList<SQLHint>();
public void cloneTo(OracleInsertStatement x) {
super.cloneTo(x);
if (returning != null) {
x.setReturning(returning.clone());
}
if (errorLogging != null) {
x.setErrorLogging(errorLogging.clone());
}
for (SQLHint hint : hints) {
SQLHint h2 = hint.clone();
h2.setParent(x);
x.hints.add(h2);
}
}
public List<SQLHint> getHints() {
return hints;
@@ -77,4 +92,10 @@ public class OracleInsertStatement extends SQLInsertStatement implements OracleS
public void output(StringBuffer buf) {
new OracleOutputVisitor(buf).visit(this);
}
public OracleInsertStatement clone() {
OracleInsertStatement x = new OracleInsertStatement();
cloneTo(x);
return x;
}
}
@@ -198,5 +198,21 @@ public class OracleMultiInsertStatement extends OracleStatementImpl {
visitor.endVisit(this);
}
public void cloneTo(InsertIntoClause x) {
super.cloneTo(x);
if (returning != null) {
x.setReturning(returning.clone());
}
if (errorLogging != null) {
x.setErrorLogging(errorLogging.clone());
}
}
public InsertIntoClause clone() {
InsertIntoClause x = new InsertIntoClause();
cloneTo(x);
return x;
}
}
}
@@ -47,6 +47,14 @@ public abstract class OracleSelectRestriction extends OracleSQLObjectImpl {
visitor.endVisit(this);
}
public CheckOption clone() {
CheckOption x = new CheckOption();
if (constraint != null) {
x.setConstraint(constraint.clone());
}
return x;
}
}
public static class ReadOnly extends OracleSelectRestriction {
@@ -60,5 +68,12 @@ public abstract class OracleSelectRestriction extends OracleSQLObjectImpl {
visitor.endVisit(this);
}
public ReadOnly clone() {
ReadOnly x = new ReadOnly();
return x;
}
}
}
@@ -83,4 +83,22 @@ public class OracleUnique extends SQLUnique implements OracleConstraint, OracleS
this.initially = initially;
}
public void cloneTo(OracleUnique x) {
super.cloneTo(x);
if (using != null) {
x.setUsing(using.clone());
}
if (exceptionsInto != null) {
x.setExceptionsInto(exceptionsInto.clone());
}
x.initially = initially;
x.deferrable = deferrable;
}
public OracleUnique clone() {
OracleUnique x = new OracleUnique();
cloneTo(x);
return x;
}
}
@@ -48,4 +48,15 @@ public class PGWithClause extends PGSQLObjectImpl {
}
visitor.endVisit(this);
}
public PGWithClause clone() {
PGWithClause x = new PGWithClause();
x.recursive = recursive;
for (PGWithQuery w : withQuery) {
PGWithQuery w2 = w.clone();
w2.setParent(x);
x.withQuery.add(w2);
}
return x;
}
}
@@ -64,4 +64,22 @@ public class PGWithQuery extends PGSQLObjectImpl {
}
visitor.endVisit(this);
}
public PGWithQuery clone() {
PGWithQuery x = new PGWithQuery();
if (name != null) {
x.setName(name.clone());
}
for (SQLExpr c : columns) {
SQLExpr c2 = c.clone();
c2.setParent(x);
x.columns.add(c);
}
if (query != null) {
x.setQuery(query.clone());
}
return x;
}
}
@@ -65,4 +65,12 @@ public class PGIntervalExpr extends SQLExprImpl implements SQLLiteralExpr,PGExpr
protected void accept0(SQLASTVisitor visitor) {
this.accept0((PGASTVisitor) visitor);
}
public PGIntervalExpr clone() {
PGIntervalExpr x = new PGIntervalExpr();
if (value != null) {
x.setValue(value.clone());
}
return x;
}
}
@@ -31,6 +31,22 @@ public class PGInsertStatement extends SQLInsertStatement implements PGSQLStatem
private SQLExpr returning;
private boolean defaultValues = false;
public void cloneTo(PGInsertStatement x) {
super.cloneTo(x);
if (with != null) {
x.setWith(with.clone());
}
for (ValuesClause v : valuesList) {
ValuesClause v2 = v.clone();
v2.setParent(x);
x.valuesList.add(v2);
}
if (returning != null) {
x.setReturning(returning.clone());
}
x.defaultValues = defaultValues;
}
public SQLExpr getReturning() {
return returning;
}
@@ -96,4 +112,10 @@ public class PGInsertStatement extends SQLInsertStatement implements PGSQLStatem
visitor.endVisit(this);
}
public PGInsertStatement clone() {
PGInsertStatement x = new PGInsertStatement();
cloneTo(x);
return x;
}
}
@@ -58,4 +58,21 @@ public class SQLServerOutput extends SQLServerObjectImpl {
return selectList;
}
public SQLServerOutput clone() {
SQLServerOutput x = new SQLServerOutput();
if (into != null) {
x.setInto(into.clone());
}
for (SQLExpr c : columns) {
SQLExpr c2 = c.clone();
c2.setParent(x);
x.columns.add(c2);
}
for (SQLSelectItem item : selectList) {
SQLSelectItem item2 = item.clone();
item2.setParent(x);
x.selectList.add(item2);
}
return x;
}
}
@@ -65,4 +65,13 @@ public class SQLServerTop extends SQLServerObjectImpl {
visitor.endVisit(this);
}
public SQLServerTop clone() {
SQLServerTop x = new SQLServerTop();
if (expr != null) {
x.setExpr(expr.clone());
}
x.percent = percent;
x.withTies = withTies;
return x;
}
}
@@ -33,6 +33,17 @@ public class SQLServerInsertStatement extends SQLInsertStatement implements SQLS
private SQLServerOutput output;
public void cloneTo(SQLServerInsertStatement x) {
super.cloneTo(x);
x.defaultValues = defaultValues;
if (top != null) {
x.setTop(top.clone());
}
if (output != null) {
x.setOutput(output.clone());
}
}
@Override
protected void accept0(SQLASTVisitor visitor) {
this.accept0((SQLServerASTVisitor) visitor);
@@ -76,4 +87,9 @@ public class SQLServerInsertStatement extends SQLInsertStatement implements SQLS
this.top = top;
}
public SQLServerInsertStatement clone() {
SQLServerInsertStatement x = new SQLServerInsertStatement();
cloneTo(x);
return x;
}
}