修正SQL合并超长条件时的bug

This commit is contained in:
wenshao
2011-11-03 20:48:37 +08:00
parent 3d07d184de
commit 7711945dcc
6 changed files with 175 additions and 5 deletions
@@ -86,4 +86,48 @@ public class SQLBinaryOpExpr extends SQLExprImpl implements Serializable {
visitor.endVisit(this);
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((left == null) ? 0 : left.hashCode());
result = prime * result + ((operator == null) ? 0 : operator.hashCode());
result = prime * result + ((right == null) ? 0 : right.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (!(obj instanceof SQLBinaryOpExpr)) {
return false;
}
SQLBinaryOpExpr other = (SQLBinaryOpExpr) obj;
if (left == null) {
if (other.left != null) {
return false;
}
} else if (!left.equals(other.left)) {
return false;
}
if (operator != other.operator) {
return false;
}
if (right == null) {
if (other.right != null) {
return false;
}
} else if (!right.equals(other.right)) {
return false;
}
return true;
}
}
@@ -51,4 +51,36 @@ public class SQLIdentifierExpr extends SQLExprImpl implements SQLName {
visitor.endVisit(this);
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((name == null) ? 0 : name.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (!(obj instanceof SQLIdentifierExpr)) {
return false;
}
SQLIdentifierExpr other = (SQLIdentifierExpr) obj;
if (name == null) {
if (other.name != null) {
return false;
}
} else if (!name.equals(other.name)) {
return false;
}
return true;
}
}
@@ -66,4 +66,44 @@ public class SQLPropertyExpr extends SQLExprImpl implements SQLName {
visitor.endVisit(this);
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((name == null) ? 0 : name.hashCode());
result = prime * result + ((owner == null) ? 0 : owner.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (!(obj instanceof SQLPropertyExpr)) {
return false;
}
SQLPropertyExpr other = (SQLPropertyExpr) obj;
if (name == null) {
if (other.name != null) {
return false;
}
} else if (!name.equals(other.name)) {
return false;
}
if (owner == null) {
if (other.owner != null) {
return false;
}
} else if (!owner.equals(other.owner)) {
return false;
}
return true;
}
}
@@ -51,4 +51,36 @@ public class SQLVariantRefExpr extends SQLExprImpl {
visitor.endVisit(this);
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((name == null) ? 0 : name.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (!(obj instanceof SQLVariantRefExpr)) {
return false;
}
SQLVariantRefExpr other = (SQLVariantRefExpr) obj;
if (name == null) {
if (other.name != null) {
return false;
}
} else if (!name.equals(other.name)) {
return false;
}
return true;
}
}
@@ -42,7 +42,7 @@ public class MySqlParameterizedOutputVisitor extends MySqlOutputVisitor {
return super.visit(x);
}
public boolean visit(SQLNullExpr x) {
print('?');
return false;
@@ -65,8 +65,19 @@ public class MySqlParameterizedOutputVisitor extends MySqlOutputVisitor {
x = new SQLBinaryOpExpr(new SQLVariantRefExpr("?"), x.getOperator(), x.getRight());
}
if (x.getRight() instanceof SQLBinaryOpExpr) {
x = new SQLBinaryOpExpr(x.getLeft(), x.getOperator(), merge((SQLBinaryOpExpr) x.getRight()));
for (;;) {
if (x.getRight() instanceof SQLBinaryOpExpr) {
if (x.getLeft() instanceof SQLBinaryOpExpr) {
SQLBinaryOpExpr leftBinaryExpr = (SQLBinaryOpExpr) x.getLeft();
if (leftBinaryExpr.getRight().equals(x.getRight())) {
x = leftBinaryExpr;
continue;
}
}
x = new SQLBinaryOpExpr(x.getLeft(), x.getOperator(), merge((SQLBinaryOpExpr) x.getRight()));
}
break;
}
if (x.getLeft() instanceof SQLBinaryOpExpr) {
@@ -64,8 +64,19 @@ public class OracleParameterizedOutputVisitor extends OracleOutputVisitor {
x = new SQLBinaryOpExpr(new SQLVariantRefExpr("?"), x.getOperator(), x.getRight());
}
if (x.getRight() instanceof SQLBinaryOpExpr) {
x = new SQLBinaryOpExpr(x.getLeft(), x.getOperator(), merge((SQLBinaryOpExpr) x.getRight()));
for (;;) {
if (x.getRight() instanceof SQLBinaryOpExpr) {
if (x.getLeft() instanceof SQLBinaryOpExpr) {
SQLBinaryOpExpr leftBinaryExpr = (SQLBinaryOpExpr) x.getLeft();
if (leftBinaryExpr.getRight().equals(x.getRight())) {
x = leftBinaryExpr;
continue;
}
}
x = new SQLBinaryOpExpr(x.getLeft(), x.getOperator(), merge((SQLBinaryOpExpr) x.getRight()));
}
break;
}
if (x.getLeft() instanceof SQLBinaryOpExpr) {