mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
add testcase
This commit is contained in:
@@ -44,18 +44,6 @@ public class SQLBetweenExpr extends SQLExprImpl implements Serializable {
|
||||
this.not = not;
|
||||
}
|
||||
|
||||
public void output(StringBuffer buf) {
|
||||
this.testExpr.output(buf);
|
||||
if (this.not) {
|
||||
buf.append(" NOT BETWEEN ");
|
||||
} else {
|
||||
buf.append(" BETWEEN ");
|
||||
}
|
||||
this.beginExpr.output(buf);
|
||||
buf.append(" AND ");
|
||||
this.endExpr.output(buf);
|
||||
}
|
||||
|
||||
protected void accept0(SQLASTVisitor visitor) {
|
||||
if (visitor.visit(this)) {
|
||||
acceptChild(visitor, this.testExpr);
|
||||
|
||||
@@ -35,29 +35,6 @@ public class SQLCaseExpr extends SQLExprImpl implements Serializable {
|
||||
|
||||
}
|
||||
|
||||
public void output(StringBuffer buf) {
|
||||
buf.append("CASE ");
|
||||
if (this.valueExpr != null) {
|
||||
this.valueExpr.output(buf);
|
||||
buf.append(" ");
|
||||
}
|
||||
|
||||
int i = 0;
|
||||
for (int size = this.items.size(); i < size; ++i) {
|
||||
if (i != 0) {
|
||||
buf.append(" ");
|
||||
}
|
||||
((Item) this.items.get(i)).output(buf);
|
||||
}
|
||||
|
||||
if (this.elseExpr != null) {
|
||||
buf.append(" ELSE ");
|
||||
this.elseExpr.output(buf);
|
||||
}
|
||||
|
||||
buf.append(" END");
|
||||
}
|
||||
|
||||
public SQLExpr getValueExpr() {
|
||||
return this.valueExpr;
|
||||
}
|
||||
@@ -138,13 +115,6 @@ public class SQLCaseExpr extends SQLExprImpl implements Serializable {
|
||||
this.valueExpr = valueExpr;
|
||||
}
|
||||
|
||||
public void output(StringBuffer buf) {
|
||||
buf.append("WHEN ");
|
||||
this.conditionExpr.output(buf);
|
||||
buf.append(" THEN ");
|
||||
this.valueExpr.output(buf);
|
||||
}
|
||||
|
||||
protected void accept0(SQLASTVisitor visitor) {
|
||||
if (visitor.visit(this)) {
|
||||
acceptChild(visitor, this.conditionExpr);
|
||||
@@ -152,6 +122,31 @@ public class SQLCaseExpr extends SQLExprImpl implements Serializable {
|
||||
}
|
||||
visitor.endVisit(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((conditionExpr == null) ? 0 : conditionExpr.hashCode());
|
||||
result = prime * result + ((valueExpr == null) ? 0 : valueExpr.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) return true;
|
||||
if (obj == null) return false;
|
||||
if (getClass() != obj.getClass()) return false;
|
||||
Item other = (Item) obj;
|
||||
if (conditionExpr == null) {
|
||||
if (other.conditionExpr != null) return false;
|
||||
} else if (!conditionExpr.equals(other.conditionExpr)) return false;
|
||||
if (valueExpr == null) {
|
||||
if (other.valueExpr != null) return false;
|
||||
} else if (!valueExpr.equals(other.valueExpr)) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -32,13 +32,11 @@ public class SQLExistsExpr extends SQLExprImpl implements Serializable {
|
||||
}
|
||||
|
||||
public SQLExistsExpr(SQLSelect subQuery){
|
||||
|
||||
this.subQuery = subQuery;
|
||||
this.setSubQuery(subQuery);
|
||||
}
|
||||
|
||||
public SQLExistsExpr(SQLSelect subQuery, boolean not){
|
||||
|
||||
this.subQuery = subQuery;
|
||||
this.setSubQuery(subQuery);
|
||||
this.not = not;
|
||||
}
|
||||
|
||||
@@ -55,16 +53,10 @@ public class SQLExistsExpr extends SQLExprImpl implements Serializable {
|
||||
}
|
||||
|
||||
public void setSubQuery(SQLSelect subQuery) {
|
||||
this.subQuery = subQuery;
|
||||
}
|
||||
|
||||
public void output(StringBuffer buf) {
|
||||
if (this.not) {
|
||||
buf.append("NOT ");
|
||||
if (subQuery != null) {
|
||||
subQuery.setParent(this);
|
||||
}
|
||||
buf.append("EXISTS (");
|
||||
this.subQuery.output(buf);
|
||||
buf.append(")");
|
||||
this.subQuery = subQuery;
|
||||
}
|
||||
|
||||
protected void accept0(SQLASTVisitor visitor) {
|
||||
|
||||
@@ -21,17 +21,17 @@ import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
|
||||
public class SQLSelect extends SQLObjectImpl {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
protected SQLWithSubqueryClause withSubQuery;
|
||||
protected SQLSelectQuery query;
|
||||
protected SQLOrderBy orderBy;
|
||||
protected SQLSelectQuery query;
|
||||
protected SQLOrderBy orderBy;
|
||||
|
||||
public SQLSelect(){
|
||||
|
||||
}
|
||||
|
||||
public SQLSelect(SQLSelectQuery query) {
|
||||
|
||||
public SQLSelect(SQLSelectQuery query){
|
||||
this.setQuery(query);
|
||||
}
|
||||
|
||||
@@ -62,15 +62,6 @@ public class SQLSelect extends SQLObjectImpl {
|
||||
this.orderBy = orderBy;
|
||||
}
|
||||
|
||||
public void output(StringBuffer buf) {
|
||||
this.query.output(buf);
|
||||
buf.append(" ");
|
||||
|
||||
if (this.orderBy != null) {
|
||||
this.orderBy.output(buf);
|
||||
}
|
||||
}
|
||||
|
||||
protected void accept0(SQLASTVisitor visitor) {
|
||||
if (visitor.visit(this)) {
|
||||
acceptChild(visitor, this.query);
|
||||
@@ -80,4 +71,32 @@ public class SQLSelect extends SQLObjectImpl {
|
||||
visitor.endVisit(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((orderBy == null) ? 0 : orderBy.hashCode());
|
||||
result = prime * result + ((query == null) ? 0 : query.hashCode());
|
||||
result = prime * result + ((withSubQuery == null) ? 0 : withSubQuery.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) return true;
|
||||
if (obj == null) return false;
|
||||
if (getClass() != obj.getClass()) return false;
|
||||
SQLSelect other = (SQLSelect) obj;
|
||||
if (orderBy == null) {
|
||||
if (other.orderBy != null) return false;
|
||||
} else if (!orderBy.equals(other.orderBy)) return false;
|
||||
if (query == null) {
|
||||
if (other.query != null) return false;
|
||||
} else if (!query.equals(other.query)) return false;
|
||||
if (withSubQuery == null) {
|
||||
if (other.withSubQuery != null) return false;
|
||||
} else if (!withSubQuery.equals(other.withSubQuery)) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -19,7 +19,6 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLExpr;
|
||||
import com.alibaba.druid.sql.ast.SQLSetQuantifier;
|
||||
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
|
||||
public class SQLSelectQueryBlock extends SQLSelectQuery {
|
||||
@@ -103,40 +102,42 @@ public class SQLSelectQueryBlock extends SQLSelectQuery {
|
||||
visitor.endVisit(this);
|
||||
}
|
||||
|
||||
public void output(StringBuffer buf) {
|
||||
buf.append("SELECT ");
|
||||
|
||||
if (SQLSetQuantifier.ALL == this.distionOption) {
|
||||
buf.append("ALL ");
|
||||
} else if (SQLSetQuantifier.DISTINCT == this.distionOption) {
|
||||
buf.append("DISTINCT ");
|
||||
} else if (SQLSetQuantifier.UNIQUE == this.distionOption) {
|
||||
buf.append("UNIQUE ");
|
||||
}
|
||||
|
||||
int i = 0;
|
||||
for (int size = this.selectList.size(); i < size; ++i) {
|
||||
if (i != 0) {
|
||||
buf.append(", ");
|
||||
}
|
||||
((SQLSelectItem) this.selectList.get(i)).output(buf);
|
||||
}
|
||||
|
||||
buf.append(" FROM ");
|
||||
if (this.from == null) {
|
||||
buf.append("DUAL");
|
||||
} else {
|
||||
this.from.output(buf);
|
||||
}
|
||||
|
||||
if (this.where != null) {
|
||||
buf.append(" WHERE ");
|
||||
this.where.output(buf);
|
||||
}
|
||||
|
||||
if (this.groupBy != null) {
|
||||
buf.append(" ");
|
||||
this.groupBy.output(buf);
|
||||
}
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + distionOption;
|
||||
result = prime * result + ((from == null) ? 0 : from.hashCode());
|
||||
result = prime * result + ((groupBy == null) ? 0 : groupBy.hashCode());
|
||||
result = prime * result + ((into == null) ? 0 : into.hashCode());
|
||||
result = prime * result + ((selectList == null) ? 0 : selectList.hashCode());
|
||||
result = prime * result + ((where == null) ? 0 : where.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) return true;
|
||||
if (obj == null) return false;
|
||||
if (getClass() != obj.getClass()) return false;
|
||||
SQLSelectQueryBlock other = (SQLSelectQueryBlock) obj;
|
||||
if (distionOption != other.distionOption) return false;
|
||||
if (from == null) {
|
||||
if (other.from != null) return false;
|
||||
} else if (!from.equals(other.from)) return false;
|
||||
if (groupBy == null) {
|
||||
if (other.groupBy != null) return false;
|
||||
} else if (!groupBy.equals(other.groupBy)) return false;
|
||||
if (into == null) {
|
||||
if (other.into != null) return false;
|
||||
} else if (!into.equals(other.into)) return false;
|
||||
if (selectList == null) {
|
||||
if (other.selectList != null) return false;
|
||||
} else if (!selectList.equals(other.selectList)) return false;
|
||||
if (where == null) {
|
||||
if (other.where != null) return false;
|
||||
} else if (!where.equals(other.where)) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user