IN PROGRESS - issue DRUID-81: SQLExpr的派生类实现Equals和HashCode方法

http://code.alibabatech.com/jira/browse/DRUID-81
This commit is contained in:
wenshao
2011-11-07 15:51:51 +08:00
parent 72c0d1c7b5
commit 01fd745646
45 changed files with 1514 additions and 1 deletions
@@ -81,4 +81,46 @@ public class SQLAggregateExpr extends SQLExprImpl implements Serializable {
visitor.endVisit(this);
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((arguments == null) ? 0 : arguments.hashCode());
result = prime * result + ((methodName == null) ? 0 : methodName.hashCode());
result = prime * result + option;
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
SQLAggregateExpr other = (SQLAggregateExpr) obj;
if (arguments == null) {
if (other.arguments != null) {
return false;
}
} else if (!arguments.equals(other.arguments)) {
return false;
}
if (methodName == null) {
if (other.methodName != null) {
return false;
}
} else if (!methodName.equals(other.methodName)) {
return false;
}
if (option != other.option) {
return false;
}
return true;
}
}
@@ -21,7 +21,7 @@ import com.alibaba.druid.sql.visitor.SQLASTVisitor;
public class SQLAllColumnExpr extends SQLExprImpl {
private static final long serialVersionUID = 1L;
public SQLAllColumnExpr(){
}
@@ -34,4 +34,12 @@ public class SQLAllColumnExpr extends SQLExprImpl {
visitor.visit(this);
visitor.endVisit(this);
}
public int hashCode() {
return 0;
}
public boolean equals(Object o) {
return o instanceof SQLAllColumnExpr;
}
}
@@ -53,4 +53,35 @@ public class SQLAllExpr extends SQLExprImpl {
visitor.endVisit(this);
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((subQuery == null) ? 0 : subQuery.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;
}
SQLAllExpr other = (SQLAllExpr) obj;
if (subQuery == null) {
if (other.subQuery != null) {
return false;
}
} else if (!subQuery.equals(other.subQuery)) {
return false;
}
return true;
}
}
@@ -53,4 +53,34 @@ public class SQLAnyExpr extends SQLExprImpl {
visitor.endVisit(this);
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((subQuery == null) ? 0 : subQuery.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;
}
SQLAnyExpr other = (SQLAnyExpr) obj;
if (subQuery == null) {
if (other.subQuery != null) {
return false;
}
} else if (!subQuery.equals(other.subQuery)) {
return false;
}
return true;
}
}
@@ -99,4 +99,54 @@ public class SQLBetweenExpr extends SQLExprImpl implements Serializable {
public void setEndExpr(SQLExpr endExpr) {
this.endExpr = endExpr;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((beginExpr == null) ? 0 : beginExpr.hashCode());
result = prime * result + ((endExpr == null) ? 0 : endExpr.hashCode());
result = prime * result + (not ? 1231 : 1237);
result = prime * result + ((testExpr == null) ? 0 : testExpr.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;
}
SQLBetweenExpr other = (SQLBetweenExpr) obj;
if (beginExpr == null) {
if (other.beginExpr != null) {
return false;
}
} else if (!beginExpr.equals(other.beginExpr)) {
return false;
}
if (endExpr == null) {
if (other.endExpr != null) {
return false;
}
} else if (!endExpr.equals(other.endExpr)) {
return false;
}
if (not != other.not) {
return false;
}
if (testExpr == null) {
if (other.testExpr != null) {
return false;
}
} else if (!testExpr.equals(other.testExpr)) {
return false;
}
return true;
}
}
@@ -60,4 +60,34 @@ public class SQLBitStringLiteralExpr extends SQLLiteralExpr {
}
buf.append("'");
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((value == null) ? 0 : value.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;
}
SQLBitStringLiteralExpr other = (SQLBitStringLiteralExpr) obj;
if (value == null) {
if (other.value != null) {
return false;
}
} else if (!value.equals(other.value)) {
return false;
}
return true;
}
}
@@ -134,4 +134,52 @@ public class SQLCaseExpr extends SQLExprImpl implements Serializable {
visitor.endVisit(this);
}
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((elseExpr == null) ? 0 : elseExpr.hashCode());
result = prime * result + ((items == null) ? 0 : items.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;
}
SQLCaseExpr other = (SQLCaseExpr) obj;
if (elseExpr == null) {
if (other.elseExpr != null) {
return false;
}
} else if (!elseExpr.equals(other.elseExpr)) {
return false;
}
if (items == null) {
if (other.items != null) {
return false;
}
} else if (!items.equals(other.items)) {
return false;
}
if (valueExpr == null) {
if (other.valueExpr != null) {
return false;
}
} else if (!valueExpr.equals(other.valueExpr)) {
return false;
}
return true;
}
}
@@ -62,4 +62,43 @@ public class SQLCastExpr extends SQLExprImpl {
}
visitor.endVisit(this);
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((dataType == null) ? 0 : dataType.hashCode());
result = prime * result + ((expr == null) ? 0 : expr.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;
}
SQLCastExpr other = (SQLCastExpr) obj;
if (dataType == null) {
if (other.dataType != null) {
return false;
}
} else if (!dataType.equals(other.dataType)) {
return false;
}
if (expr == null) {
if (other.expr != null) {
return false;
}
} else if (!expr.equals(other.expr)) {
return false;
}
return true;
}
}
@@ -51,4 +51,34 @@ public class SQLCurrentOfCursorExpr extends SQLExprImpl {
visitor.endVisit(this);
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((cursorName == null) ? 0 : cursorName.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;
}
SQLCurrentOfCursorExpr other = (SQLCurrentOfCursorExpr) obj;
if (cursorName == null) {
if (other.cursorName != null) {
return false;
}
} else if (!cursorName.equals(other.cursorName)) {
return false;
}
return true;
}
}
@@ -48,4 +48,34 @@ public class SQLDateLiteralExpr extends SQLLiteralExpr {
visitor.endVisit(this);
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((value == null) ? 0 : value.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;
}
SQLDateLiteralExpr other = (SQLDateLiteralExpr) obj;
if (value == null) {
if (other.value != null) {
return false;
}
} else if (!value.equals(other.value)) {
return false;
}
return true;
}
}
@@ -74,4 +74,38 @@ public class SQLExistsExpr extends SQLExprImpl implements Serializable {
visitor.endVisit(this);
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + (not ? 1231 : 1237);
result = prime * result + ((subQuery == null) ? 0 : subQuery.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;
}
SQLExistsExpr other = (SQLExistsExpr) obj;
if (not != other.not) {
return false;
}
if (subQuery == null) {
if (other.subQuery != null) {
return false;
}
} else if (!subQuery.equals(other.subQuery)) {
return false;
}
return true;
}
}
@@ -46,4 +46,34 @@ public class SQLHexExpr extends SQLLiteralExpr {
visitor.visit(this);
visitor.endVisit(this);
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((hex == null) ? 0 : hex.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;
}
SQLHexExpr other = (SQLHexExpr) obj;
if (hex == null) {
if (other.hex != null) {
return false;
}
} else if (!hex.equals(other.hex)) {
return false;
}
return true;
}
}
@@ -47,4 +47,34 @@ public class SQLHexStringLiteralExpr extends SQLLiteralExpr {
buf.append(value);
buf.append("'");
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((value == null) ? 0 : value.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;
}
SQLHexStringLiteralExpr other = (SQLHexStringLiteralExpr) obj;
if (value == null) {
if (other.value != null) {
return false;
}
} else if (!value.equals(other.value)) {
return false;
}
return true;
}
}
@@ -96,4 +96,46 @@ public class SQLInListExpr extends SQLExprImpl implements Serializable {
visitor.endVisit(this);
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((expr == null) ? 0 : expr.hashCode());
result = prime * result + (not ? 1231 : 1237);
result = prime * result + ((targetList == null) ? 0 : targetList.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;
}
SQLInListExpr other = (SQLInListExpr) obj;
if (expr == null) {
if (other.expr != null) {
return false;
}
} else if (!expr.equals(other.expr)) {
return false;
}
if (not != other.not) {
return false;
}
if (targetList == null) {
if (other.targetList != null) {
return false;
}
} else if (!targetList.equals(other.targetList)) {
return false;
}
return true;
}
}
@@ -76,4 +76,46 @@ public class SQLInSubQueryExpr extends SQLExprImpl implements Serializable {
visitor.endVisit(this);
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((expr == null) ? 0 : expr.hashCode());
result = prime * result + (not ? 1231 : 1237);
result = prime * result + ((subQuery == null) ? 0 : subQuery.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;
}
SQLInSubQueryExpr other = (SQLInSubQueryExpr) obj;
if (expr == null) {
if (other.expr != null) {
return false;
}
} else if (!expr.equals(other.expr)) {
return false;
}
if (not != other.not) {
return false;
}
if (subQuery == null) {
if (other.subQuery != null) {
return false;
}
} else if (!subQuery.equals(other.subQuery)) {
return false;
}
return true;
}
}
@@ -49,4 +49,34 @@ public class SQLIntegerExpr extends SQLNumericLiteralExpr {
visitor.endVisit(this);
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((number == null) ? 0 : number.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;
}
SQLIntegerExpr other = (SQLIntegerExpr) obj;
if (number == null) {
if (other.number != null) {
return false;
}
} else if (!number.equals(other.number)) {
return false;
}
return true;
}
}
@@ -56,4 +56,34 @@ public class SQLIntervalLiteralExpr extends SQLLiteralExpr {
visitor.endVisit(this);
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((sign == null) ? 0 : sign.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;
}
SQLIntervalLiteralExpr other = (SQLIntervalLiteralExpr) obj;
if (sign == null) {
if (other.sign != null) {
return false;
}
} else if (!sign.equals(other.sign)) {
return false;
}
return true;
}
}
@@ -24,4 +24,35 @@ public class SQLListExpr extends SQLExprImpl {
}
visitor.endVisit(this);
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((items == null) ? 0 : items.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;
}
SQLListExpr other = (SQLListExpr) obj;
if (items == null) {
if (other.items != null) {
return false;
}
} else if (!items.equals(other.items)) {
return false;
}
return true;
}
}
@@ -101,4 +101,50 @@ public class SQLMethodInvokeExpr extends SQLExprImpl implements Serializable {
visitor.endVisit(this);
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((methodName == null) ? 0 : methodName.hashCode());
result = prime * result + ((owner == null) ? 0 : owner.hashCode());
result = prime * result + ((parameters == null) ? 0 : parameters.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;
}
SQLMethodInvokeExpr other = (SQLMethodInvokeExpr) obj;
if (methodName == null) {
if (other.methodName != null) {
return false;
}
} else if (!methodName.equals(other.methodName)) {
return false;
}
if (owner == null) {
if (other.owner != null) {
return false;
}
} else if (!owner.equals(other.owner)) {
return false;
}
if (parameters == null) {
if (other.parameters != null) {
return false;
}
} else if (!parameters.equals(other.parameters)) {
return false;
}
return true;
}
}
@@ -56,4 +56,34 @@ public class SQLNotExpr extends SQLExprImpl implements Serializable {
visitor.endVisit(this);
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((expr == null) ? 0 : expr.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;
}
SQLNotExpr other = (SQLNotExpr) obj;
if (expr == null) {
if (other.expr != null) {
return false;
}
} else if (!expr.equals(other.expr)) {
return false;
}
return true;
}
}
@@ -34,4 +34,12 @@ public class SQLNullExpr extends SQLLiteralExpr {
visitor.endVisit(this);
}
public int hashCode() {
return 0;
}
public boolean equals(Object o) {
return o instanceof SQLNullExpr;
}
}
@@ -48,4 +48,34 @@ public class SQLNumberExpr extends SQLNumericLiteralExpr {
visitor.visit(this);
visitor.endVisit(this);
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((number == null) ? 0 : number.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;
}
SQLNumberExpr other = (SQLNumberExpr) obj;
if (number == null) {
if (other.number != null) {
return false;
}
} else if (!number.equals(other.number)) {
return false;
}
return true;
}
}
@@ -51,4 +51,42 @@ public class SQLObjectCreateExpr extends SQLExprImpl implements Serializable {
visitor.endVisit(this);
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((objType == null) ? 0 : objType.hashCode());
result = prime * result + ((paramList == null) ? 0 : paramList.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;
}
SQLObjectCreateExpr other = (SQLObjectCreateExpr) obj;
if (objType == null) {
if (other.objType != null) {
return false;
}
} else if (!objType.equals(other.objType)) {
return false;
}
if (paramList == null) {
if (other.paramList != null) {
return false;
}
} else if (!paramList.equals(other.paramList)) {
return false;
}
return true;
}
}
@@ -55,4 +55,34 @@ public class SQLQueryExpr extends SQLExprImpl implements Serializable {
visitor.endVisit(this);
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((subQuery == null) ? 0 : subQuery.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;
}
SQLQueryExpr other = (SQLQueryExpr) obj;
if (subQuery == null) {
if (other.subQuery != null) {
return false;
}
} else if (!subQuery.equals(other.subQuery)) {
return false;
}
return true;
}
}
@@ -53,4 +53,34 @@ public class SQLSomeExpr extends SQLExprImpl {
visitor.endVisit(this);
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((subQuery == null) ? 0 : subQuery.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;
}
SQLSomeExpr other = (SQLSomeExpr) obj;
if (subQuery == null) {
if (other.subQuery != null) {
return false;
}
} else if (!subQuery.equals(other.subQuery)) {
return false;
}
return true;
}
}
@@ -37,4 +37,34 @@ public abstract class SQLTextLiteralExpr extends SQLLiteralExpr {
public void setText(String text) {
this.text = text;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((text == null) ? 0 : text.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;
}
SQLTextLiteralExpr other = (SQLTextLiteralExpr) obj;
if (text == null) {
if (other.text != null) {
return false;
}
} else if (!text.equals(other.text)) {
return false;
}
return true;
}
}
@@ -65,4 +65,38 @@ public class SQLUnaryExpr extends SQLExprImpl implements Serializable {
visitor.endVisit(this);
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((expr == null) ? 0 : expr.hashCode());
result = prime * result + ((operator == null) ? 0 : operator.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;
}
SQLUnaryExpr other = (SQLUnaryExpr) obj;
if (expr == null) {
if (other.expr != null) {
return false;
}
} else if (!expr.equals(other.expr)) {
return false;
}
if (operator != other.operator) {
return false;
}
return true;
}
}