mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
improved sql parser.
This commit is contained in:
@@ -17,5 +17,5 @@ package com.alibaba.druid.sql.ast;
|
||||
|
||||
|
||||
public interface SQLHint extends SQLObject {
|
||||
|
||||
SQLHint clone();
|
||||
}
|
||||
|
||||
@@ -117,4 +117,29 @@ public class SQLParameter extends SQLObjectImpl {
|
||||
}
|
||||
this.cursorName = cursorName;
|
||||
}
|
||||
|
||||
public SQLParameter clone() {
|
||||
SQLParameter x = new SQLParameter();
|
||||
if (name != null) {
|
||||
x.setName(name.clone());
|
||||
}
|
||||
if (dataType != null) {
|
||||
x.setDataType(dataType.clone());
|
||||
}
|
||||
if (defaultValue != null) {
|
||||
x.setDefaultValue(defaultValue.clone());
|
||||
}
|
||||
x.paramType = paramType;
|
||||
x.noCopy = noCopy;
|
||||
x.constant = constant;
|
||||
if (cursorName != null) {
|
||||
x.setCursorName(cursorName.clone());
|
||||
}
|
||||
for (SQLParameter p : cursorParameters) {
|
||||
SQLParameter p2 = p.clone();
|
||||
p2.setParent(x);
|
||||
x.cursorParameters.add(p2);
|
||||
}
|
||||
return x;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,4 +21,6 @@ public interface SQLStatement extends SQLObject {
|
||||
boolean isAfterSemi();
|
||||
|
||||
void setAfterSemi(boolean afterSemi);
|
||||
|
||||
SQLStatement clone();
|
||||
}
|
||||
|
||||
@@ -56,4 +56,8 @@ public abstract class SQLStatementImpl extends SQLObjectImpl implements SQLState
|
||||
public void setAfterSemi(boolean afterSemi) {
|
||||
this.afterSemi = afterSemi;
|
||||
}
|
||||
|
||||
public SQLStatement clone() {
|
||||
throw new UnsupportedOperationException(this.getClass().getName());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,6 +59,10 @@ public class SQLBinaryExpr extends SQLExprImpl implements SQLLiteralExpr {
|
||||
return result;
|
||||
}
|
||||
|
||||
public SQLBinaryExpr clone() {
|
||||
return new SQLBinaryExpr(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) {
|
||||
|
||||
@@ -83,4 +83,8 @@ public class SQLBooleanExpr extends SQLExprImpl implements SQLExpr, SQLLiteralEx
|
||||
public SQLDataType computeDataType() {
|
||||
return DEFAULT_DATA_TYPE;
|
||||
}
|
||||
|
||||
public SQLBooleanExpr clone() {
|
||||
return new SQLBooleanExpr(value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,6 +31,10 @@ public class SQLDateExpr extends SQLExprImpl implements SQLLiteralExpr {
|
||||
|
||||
}
|
||||
|
||||
public SQLDateExpr(String literal) {
|
||||
this.literal = literal;
|
||||
}
|
||||
|
||||
public String getLiteral() {
|
||||
return literal;
|
||||
}
|
||||
@@ -75,4 +79,7 @@ public class SQLDateExpr extends SQLExprImpl implements SQLLiteralExpr {
|
||||
return true;
|
||||
}
|
||||
|
||||
public SQLDateExpr clone() {
|
||||
return new SQLDateExpr(literal);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,4 +39,8 @@ public class SQLDefaultExpr extends SQLExprImpl implements SQLLiteralExpr {
|
||||
public String toString() {
|
||||
return "DEFAULT";
|
||||
}
|
||||
|
||||
public SQLDefaultExpr clone() {
|
||||
return new SQLDefaultExpr();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,4 +80,8 @@ public class SQLHexExpr extends SQLExprImpl implements SQLLiteralExpr {
|
||||
public byte[] toBytes() {
|
||||
return HexBin.decode(this.hex);
|
||||
}
|
||||
|
||||
public SQLHexExpr clone () {
|
||||
return new SQLHexExpr(hex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,6 +44,20 @@ public class SQLInListExpr extends SQLExprImpl implements Serializable {
|
||||
this.not = not;
|
||||
}
|
||||
|
||||
public SQLInListExpr clone() {
|
||||
SQLInListExpr x = new SQLInListExpr();
|
||||
x.not = not;
|
||||
if (expr != null) {
|
||||
x.setExpr(expr.clone());
|
||||
}
|
||||
for (SQLExpr e : targetList) {
|
||||
SQLExpr e2 = e.clone();
|
||||
e2.setParent(x);
|
||||
x.targetList.add(e2);
|
||||
}
|
||||
return x;
|
||||
}
|
||||
|
||||
public boolean isNot() {
|
||||
return this.not;
|
||||
}
|
||||
|
||||
@@ -35,6 +35,18 @@ public class SQLInSubQueryExpr extends SQLExprImpl implements Serializable {
|
||||
|
||||
}
|
||||
|
||||
public SQLInSubQueryExpr clone() {
|
||||
SQLInSubQueryExpr x = new SQLInSubQueryExpr();
|
||||
x.not = not;
|
||||
if (expr != null) {
|
||||
x.setExpr(expr.clone());
|
||||
}
|
||||
if (subQuery != null) {
|
||||
x.setSubQuery(subQuery.clone());
|
||||
}
|
||||
return x;
|
||||
}
|
||||
|
||||
public boolean isNot() {
|
||||
return not;
|
||||
}
|
||||
|
||||
@@ -75,4 +75,14 @@ public class SQLListExpr extends SQLExprImpl {
|
||||
return true;
|
||||
}
|
||||
|
||||
public SQLListExpr clone() {
|
||||
SQLListExpr x = new SQLListExpr();
|
||||
for (SQLExpr item : items) {
|
||||
SQLExpr item2 = item.clone();
|
||||
item2.setParent(x);
|
||||
x.items.add(item2);
|
||||
}
|
||||
return x;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,5 +18,5 @@ package com.alibaba.druid.sql.ast.expr;
|
||||
import com.alibaba.druid.sql.ast.SQLExpr;
|
||||
|
||||
public interface SQLLiteralExpr extends SQLExpr {
|
||||
|
||||
SQLLiteralExpr clone();
|
||||
}
|
||||
|
||||
@@ -26,4 +26,6 @@ public abstract class SQLNumericLiteralExpr extends SQLExprImpl implements SQLLi
|
||||
public abstract Number getNumber();
|
||||
|
||||
public abstract void setNumber(Number number);
|
||||
|
||||
public abstract SQLNumericLiteralExpr clone();
|
||||
}
|
||||
|
||||
@@ -67,4 +67,6 @@ public abstract class SQLTextLiteralExpr extends SQLExprImpl implements SQLLiter
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public abstract SQLTextLiteralExpr clone();
|
||||
}
|
||||
|
||||
@@ -32,6 +32,8 @@ public class SQLBlockStatement extends SQLStatementImpl {
|
||||
|
||||
private List<SQLStatement> statementList = new ArrayList<SQLStatement>();
|
||||
|
||||
public SQLStatement exception;
|
||||
|
||||
public List<SQLStatement> getStatementList() {
|
||||
return statementList;
|
||||
}
|
||||
@@ -48,8 +50,6 @@ public class SQLBlockStatement extends SQLStatementImpl {
|
||||
this.labelName = labelName;
|
||||
}
|
||||
|
||||
public SQLStatement exception;
|
||||
|
||||
@Override
|
||||
public void accept0(SQLASTVisitor visitor) {
|
||||
if (visitor.visit(this)) {
|
||||
@@ -86,4 +86,28 @@ public class SQLBlockStatement extends SQLStatementImpl {
|
||||
public void setEndLabel(String endLabel) {
|
||||
this.endLabel = endLabel;
|
||||
}
|
||||
|
||||
public SQLBlockStatement clone() {
|
||||
SQLBlockStatement x = new SQLBlockStatement();
|
||||
x.labelName = labelName;
|
||||
x.endLabel = endLabel;
|
||||
|
||||
for (SQLParameter p : parameters) {
|
||||
SQLParameter p2 = p.clone();
|
||||
p2.setParent(x);
|
||||
x.parameters.add(p2);
|
||||
}
|
||||
|
||||
for (SQLStatement stmt : statementList) {
|
||||
SQLStatement stmt2 = stmt.clone();
|
||||
stmt2.setParent(x);
|
||||
x.statementList.add(stmt2);
|
||||
}
|
||||
|
||||
if (exception != null) {
|
||||
x.setException(exception.clone());
|
||||
}
|
||||
|
||||
return x;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,6 +35,24 @@ public class SQLCommitStatement extends SQLStatementImpl {
|
||||
private SQLExpr transactionName;
|
||||
private SQLExpr delayedDurability;
|
||||
|
||||
public SQLCommitStatement clone() {
|
||||
SQLCommitStatement x = new SQLCommitStatement();
|
||||
x.write = write;
|
||||
x.wait = wait;
|
||||
x.immediate = immediate;
|
||||
x.work = work;
|
||||
x.chain = chain;
|
||||
x.release = release;
|
||||
|
||||
if(transactionName != null) {
|
||||
x.setTransactionName(transactionName.clone());
|
||||
}
|
||||
if (delayedDurability != null) {
|
||||
x.setDelayedDurability(delayedDurability.clone());
|
||||
}
|
||||
return x;
|
||||
}
|
||||
|
||||
public void accept0(SQLASTVisitor visitor) {
|
||||
if (visitor.visit(this)) {
|
||||
acceptChild(visitor, transactionName);
|
||||
|
||||
@@ -25,7 +25,7 @@ import java.util.List;
|
||||
/**
|
||||
* Created by wenshao on 23/05/2017.
|
||||
*/
|
||||
public class SQLCreateFunctionStatement extends SQLStatementImpl {
|
||||
public class SQLCreateFunctionStatement extends SQLStatementImpl implements SQLDDLStatement {
|
||||
private SQLName definer;
|
||||
|
||||
private boolean create = true;
|
||||
@@ -47,6 +47,38 @@ public class SQLCreateFunctionStatement extends SQLStatementImpl {
|
||||
|
||||
private boolean deterministic = false;
|
||||
|
||||
public SQLCreateFunctionStatement clone() {
|
||||
SQLCreateFunctionStatement x = new SQLCreateFunctionStatement();
|
||||
|
||||
if (definer != null) {
|
||||
x.setDefiner(definer.clone());
|
||||
}
|
||||
x.create = create;
|
||||
x.orReplace = orReplace;
|
||||
if (name != null) {
|
||||
x.setName(name.clone());
|
||||
}
|
||||
if (block != null) {
|
||||
x.setBlock(block.clone());
|
||||
}
|
||||
for (SQLParameter p : parameters) {
|
||||
SQLParameter p2 = p.clone();
|
||||
p2.setParent(x);
|
||||
x.parameters.add(p2);
|
||||
}
|
||||
x.javaCallSpec = javaCallSpec;
|
||||
if (authid != null) {
|
||||
x.setAuthid(authid.clone());
|
||||
}
|
||||
if (returnDataType != null) {
|
||||
x.setReturnDataType(returnDataType.clone());
|
||||
}
|
||||
x.comment = comment;
|
||||
x.deterministic = deterministic;
|
||||
|
||||
return x;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept0(SQLASTVisitor visitor) {
|
||||
if (visitor.visit(this)) {
|
||||
|
||||
@@ -135,4 +135,23 @@ public class SQLCreateIndexStatement extends SQLStatementImpl implements SQLDDLS
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public SQLCreateIndexStatement clone() {
|
||||
SQLCreateIndexStatement x = new SQLCreateIndexStatement();
|
||||
if (name != null) {
|
||||
x.setName(name.clone());
|
||||
}
|
||||
if (table != null) {
|
||||
x.setTable(table.clone());
|
||||
}
|
||||
for (SQLSelectOrderByItem item : items) {
|
||||
SQLSelectOrderByItem item2 = item.clone();
|
||||
item2.setParent(x);
|
||||
x.items.add(item2);
|
||||
}
|
||||
x.type = type;
|
||||
x.using = using;
|
||||
return x;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
/**
|
||||
* Created by wenshao on 16/9/14.
|
||||
*/
|
||||
public class SQLCreateSequenceStatement extends SQLStatementImpl {
|
||||
public class SQLCreateSequenceStatement extends SQLStatementImpl implements SQLDDLStatement {
|
||||
private SQLName name;
|
||||
|
||||
private SQLExpr startWith;
|
||||
|
||||
@@ -280,4 +280,40 @@ public class SQLCreateViewStatement extends SQLStatementImpl implements SQLDDLSt
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public SQLCreateViewStatement clone() {
|
||||
SQLCreateViewStatement x = new SQLCreateViewStatement();
|
||||
|
||||
x.orReplace = orReplace;
|
||||
x.force = force;
|
||||
if (subQuery != null) {
|
||||
x.setSubQuery(subQuery.clone());
|
||||
}
|
||||
x.ifNotExists = ifNotExists;
|
||||
|
||||
x.algorithm = algorithm;
|
||||
if (definer != null) {
|
||||
x.setDefiner(definer.clone());
|
||||
}
|
||||
x.sqlSecurity = sqlSecurity;
|
||||
if (tableSource != null) {
|
||||
x.setTableSource(tableSource.clone());
|
||||
}
|
||||
for (SQLTableElement column : columns) {
|
||||
SQLTableElement column2 = column.clone();
|
||||
column2.setParent(x);
|
||||
x.columns.add(column2);
|
||||
}
|
||||
x.withCheckOption = withCheckOption;
|
||||
x.withCascaded = withCascaded;
|
||||
x.withLocal = withLocal;
|
||||
x.withReadOnly = withReadOnly;
|
||||
|
||||
if (comment != null) {
|
||||
x.setComment(comment.clone());
|
||||
}
|
||||
|
||||
return x;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,4 +60,18 @@ public class SQLErrorLoggingClause extends SQLObjectImpl {
|
||||
this.limit = limit;
|
||||
}
|
||||
|
||||
public SQLErrorLoggingClause clone() {
|
||||
SQLErrorLoggingClause x = new SQLErrorLoggingClause();
|
||||
if (into != null) {
|
||||
x.setInto(into.clone());
|
||||
}
|
||||
if (simpleExpression != null) {
|
||||
x.setSimpleExpression(simpleExpression.clone());
|
||||
}
|
||||
if (limit != null) {
|
||||
x.setLimit(limit.clone());
|
||||
}
|
||||
return x;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -52,4 +52,11 @@ public class SQLExprHint extends SQLObjectImpl implements SQLHint {
|
||||
visitor.endVisit(this);
|
||||
}
|
||||
|
||||
public SQLExprHint clone() {
|
||||
SQLExprHint x = new SQLExprHint();
|
||||
if (expr != null) {
|
||||
x.setExpr(expr.clone());
|
||||
}
|
||||
return x;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -223,4 +223,20 @@ public class SQLExprTableSource extends SQLTableSourceImpl {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public SQLTableSource findTableSourceWithColumn(String columnName) {
|
||||
if (schemaObject == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
SQLStatement stmt = schemaObject.getStatement();
|
||||
if (stmt instanceof SQLCreateTableStatement) {
|
||||
SQLCreateTableStatement createTableStmt = (SQLCreateTableStatement) stmt;
|
||||
if (createTableStmt.findColumn(columnName) != null) {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,6 +31,26 @@ public class SQLIfStatement extends SQLStatementImpl {
|
||||
private List<ElseIf> elseIfList = new ArrayList<ElseIf>();
|
||||
private Else elseItem;
|
||||
|
||||
public SQLIfStatement clone() {
|
||||
SQLIfStatement x = new SQLIfStatement();
|
||||
|
||||
for (SQLStatement stmt : statements) {
|
||||
SQLStatement stmt2 = stmt.clone();
|
||||
stmt2.setParent(x);
|
||||
x.statements.add(stmt2);
|
||||
}
|
||||
for (ElseIf o : elseIfList) {
|
||||
ElseIf o2 = o.clone();
|
||||
o2.setParent(x);
|
||||
x.elseIfList.add(o2);
|
||||
}
|
||||
if (elseItem != null) {
|
||||
x.setElseItem(elseItem.clone());
|
||||
}
|
||||
|
||||
return x;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept0(SQLASTVisitor visitor) {
|
||||
if (visitor.visit(this)) {
|
||||
@@ -111,6 +131,21 @@ public class SQLIfStatement extends SQLStatementImpl {
|
||||
}
|
||||
this.condition = condition;
|
||||
}
|
||||
|
||||
public ElseIf clone() {
|
||||
ElseIf x = new ElseIf();
|
||||
|
||||
if (condition != null) {
|
||||
x.setCondition(condition.clone());
|
||||
}
|
||||
for (SQLStatement stmt : statements) {
|
||||
SQLStatement stmt2 = stmt.clone();
|
||||
stmt2.setParent(x);
|
||||
x.statements.add(stmt2);
|
||||
}
|
||||
|
||||
return x;
|
||||
}
|
||||
}
|
||||
|
||||
public static class Else extends SQLObjectImpl {
|
||||
@@ -133,5 +168,14 @@ public class SQLIfStatement extends SQLStatementImpl {
|
||||
this.statements = statements;
|
||||
}
|
||||
|
||||
public Else clone() {
|
||||
Else x = new Else();
|
||||
for (SQLStatement stmt : statements) {
|
||||
SQLStatement stmt2 = stmt.clone();
|
||||
stmt2.setParent(x);
|
||||
x.statements.add(stmt2);
|
||||
}
|
||||
return x;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,6 +36,27 @@ public abstract class SQLInsertInto extends SQLObjectImpl {
|
||||
|
||||
}
|
||||
|
||||
public void cloneTo(SQLInsertInto x) {
|
||||
if (tableSource != null) {
|
||||
x.setTableSource(tableSource.clone());
|
||||
}
|
||||
for (SQLExpr column : columns) {
|
||||
SQLExpr column2 = column.clone();
|
||||
column2.setParent(x);
|
||||
x.columns.add(column2);
|
||||
}
|
||||
if (query != null) {
|
||||
x.setQuery(query.clone());
|
||||
}
|
||||
for (ValuesClause v : valuesList) {
|
||||
ValuesClause v2 = v.clone();
|
||||
v2.setParent(x);
|
||||
x.valuesList.add(v2);
|
||||
}
|
||||
}
|
||||
|
||||
public abstract SQLInsertInto clone();
|
||||
|
||||
public String getAlias() {
|
||||
return tableSource.getAlias();
|
||||
}
|
||||
|
||||
@@ -34,6 +34,19 @@ public class SQLInsertStatement extends SQLInsertInto implements SQLStatement {
|
||||
|
||||
}
|
||||
|
||||
public void cloneTo(SQLInsertStatement x) {
|
||||
super.cloneTo(x);
|
||||
x.dbType = dbType;
|
||||
x.upsert = upsert;
|
||||
x.afterSemi = afterSemi;
|
||||
}
|
||||
|
||||
public SQLInsertStatement clone() {
|
||||
SQLInsertStatement x = new SQLInsertStatement();
|
||||
cloneTo(x);
|
||||
return x;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void accept0(SQLASTVisitor visitor) {
|
||||
if (visitor.visit(this)) {
|
||||
@@ -62,6 +75,14 @@ public class SQLInsertStatement extends SQLInsertInto implements SQLStatement {
|
||||
this(new ArrayList<SQLExpr>());
|
||||
}
|
||||
|
||||
public ValuesClause clone() {
|
||||
ValuesClause x = new ValuesClause(new ArrayList<SQLExpr>(this.values.size()));
|
||||
for (SQLExpr v : values) {
|
||||
x.addValue(v);
|
||||
}
|
||||
return x;
|
||||
}
|
||||
|
||||
public ValuesClause(List<SQLExpr> values){
|
||||
this.values = values;
|
||||
for (int i = 0; i < values.size(); ++i) {
|
||||
|
||||
@@ -285,6 +285,10 @@ public class SQLJoinTableSource extends SQLTableSourceImpl implements SQLReplace
|
||||
if (right instanceof SQLJoinTableSource) {
|
||||
SQLJoinTableSource rightJoin = (SQLJoinTableSource) right;
|
||||
|
||||
if (rightJoin.joinType != JoinType.COMMA && rightJoin.joinType != JoinType.INNER_JOIN) {
|
||||
return;
|
||||
}
|
||||
|
||||
SQLTableSource a = left;
|
||||
SQLTableSource b = rightJoin.getLeft();
|
||||
SQLTableSource c = rightJoin.getRight();
|
||||
@@ -384,4 +388,20 @@ public class SQLJoinTableSource extends SQLTableSourceImpl implements SQLReplace
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SQLTableSource findTableSourceWithColumn(String columnName) {
|
||||
if (left != null) {
|
||||
SQLTableSource tableSource = left.findTableSourceWithColumn(columnName);
|
||||
if (tableSource != null) {
|
||||
return tableSource;
|
||||
}
|
||||
}
|
||||
|
||||
if (right != null) {
|
||||
return right.findTableSourceWithColumn(columnName);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -49,4 +49,12 @@ public class SQLReturnStatement extends SQLStatementImpl {
|
||||
}
|
||||
visitor.endVisit(this);
|
||||
}
|
||||
|
||||
public SQLReturnStatement clone() {
|
||||
SQLReturnStatement x = new SQLReturnStatement();
|
||||
if (expr != null) {
|
||||
x.setExpr(expr.clone());
|
||||
}
|
||||
return x;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,6 +83,17 @@ public class SQLSelectGroupByClause extends SQLObjectImpl {
|
||||
}
|
||||
|
||||
public SQLSelectGroupByClause clone() {
|
||||
throw new UnsupportedOperationException();
|
||||
SQLSelectGroupByClause x = new SQLSelectGroupByClause();
|
||||
for (SQLExpr item : items) {
|
||||
SQLExpr item2 = item.clone();
|
||||
item2.setParent(x);
|
||||
x.items.add(item2);
|
||||
}
|
||||
if (having != null) {
|
||||
x.setHaving(having.clone());
|
||||
}
|
||||
x.withRollUp = withRollUp;
|
||||
x.withCube = withCube;
|
||||
return x;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,10 +62,10 @@ public class SQLSelectItem extends SQLObjectImpl implements SQLReplaceable {
|
||||
}
|
||||
|
||||
public void setExpr(SQLExpr expr) {
|
||||
this.expr = expr;
|
||||
if (expr != null) {
|
||||
expr.setParent(this);
|
||||
}
|
||||
this.expr = expr;
|
||||
}
|
||||
|
||||
public String computeAlias() {
|
||||
@@ -151,7 +151,7 @@ public class SQLSelectItem extends SQLObjectImpl implements SQLReplaceable {
|
||||
SQLSelectItem x = new SQLSelectItem();
|
||||
x.alias = alias;
|
||||
if (expr != null) {
|
||||
x.expr = expr.clone();
|
||||
x.setExpr(expr.clone());
|
||||
}
|
||||
x.connectByRoot = connectByRoot;
|
||||
return x;
|
||||
|
||||
@@ -438,6 +438,13 @@ public class SQLSelectQueryBlock extends SQLObjectImpl implements SQLSelectQuery
|
||||
return findTableSource(from, alias);
|
||||
}
|
||||
|
||||
public SQLTableSource findTableSourceWithColumn(String column) {
|
||||
if (from == null) {
|
||||
return null;
|
||||
}
|
||||
return from.findTableSourceWithColumn(column);
|
||||
}
|
||||
|
||||
private static SQLTableSource findTableSource(SQLTableSource from, String alias) {
|
||||
if (from == null || alias == null) {
|
||||
return null;
|
||||
@@ -489,6 +496,14 @@ public class SQLSelectQueryBlock extends SQLObjectImpl implements SQLSelectQuery
|
||||
return null;
|
||||
}
|
||||
|
||||
public SQLColumnDefinition findColumn(String columnName) {
|
||||
if (from == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return from.findColumn(columnName);
|
||||
}
|
||||
|
||||
public void addCondition(SQLExpr expr) {
|
||||
if (expr == null) {
|
||||
return;
|
||||
|
||||
@@ -73,4 +73,19 @@ public class SQLSelectStatement extends SQLStatementImpl {
|
||||
public void setHeadHints(List<SQLCommentHint> headHints) {
|
||||
this.headHints = headHints;
|
||||
}
|
||||
|
||||
public SQLSelectStatement clone() {
|
||||
SQLSelectStatement x = new SQLSelectStatement();
|
||||
if (select != null) {
|
||||
x.setSelect(select.clone());
|
||||
}
|
||||
if (headHints != null) {
|
||||
for (SQLCommentHint h : headHints) {
|
||||
SQLCommentHint h2 = h.clone();
|
||||
h2.setParent(x);
|
||||
x.headHints.add(h2);
|
||||
}
|
||||
}
|
||||
return x;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -91,4 +91,21 @@ public class SQLSetStatement extends SQLStatementImpl {
|
||||
item.output(buf);
|
||||
}
|
||||
}
|
||||
|
||||
public SQLSetStatement clone() {
|
||||
SQLSetStatement x = new SQLSetStatement();
|
||||
for (SQLAssignItem item : items) {
|
||||
SQLAssignItem item2 = item.clone();
|
||||
item2.setParent(x);
|
||||
x.items.add(item2);
|
||||
}
|
||||
if (hints != null) {
|
||||
for (SQLCommentHint hint : hints) {
|
||||
SQLCommentHint h2 = hint.clone();
|
||||
h2.setParent(x);
|
||||
x.hints.add(h2);
|
||||
}
|
||||
}
|
||||
return x;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,4 +38,5 @@ public interface SQLTableSource extends SQLObject {
|
||||
void setFlashback(SQLExpr flashback);
|
||||
|
||||
SQLColumnDefinition findColumn(String columnName);
|
||||
SQLTableSource findTableSourceWithColumn(String columnName);
|
||||
}
|
||||
|
||||
@@ -98,4 +98,8 @@ public abstract class SQLTableSourceImpl extends SQLObjectImpl implements SQLTab
|
||||
public SQLColumnDefinition findColumn(String columnName) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public SQLTableSource findTableSourceWithColumn(String columnName) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,4 +68,19 @@ public class SQLWhileStatement extends SQLStatementImpl {
|
||||
public void setCondition(SQLExpr condition) {
|
||||
this.condition = condition;
|
||||
}
|
||||
|
||||
public SQLWhileStatement clone() {
|
||||
SQLWhileStatement x = new SQLWhileStatement();
|
||||
|
||||
if (condition != null) {
|
||||
x.setCondition(condition.clone());
|
||||
}
|
||||
for (SQLStatement stmt : statements) {
|
||||
SQLStatement stmt2 = stmt.clone();
|
||||
stmt2.setParent(x);
|
||||
x.statements.add(stmt2);
|
||||
}
|
||||
x.labelName = labelName;
|
||||
return x;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user