BUG FIX: CountAll needs to remember the tableName; also implement

equals.

git-svn-id: https://svn.apache.org/repos/asf/ofbiz/trunk@981627 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Adam Heath
2010-08-02 17:43:02 +00:00
parent 46b66d2bd2
commit f150eecfb9
3 changed files with 36 additions and 4 deletions
@@ -22,6 +22,12 @@ import org.ofbiz.base.lang.SourceMonitored;
@SourceMonitored
public final class CountAllFunction extends StaticValue {
private final String tableName;
public CountAllFunction(String tableName) {
this.tableName = tableName;
}
public void accept(Visitor visitor) {
visitor.visit(this);
}
@@ -30,8 +36,25 @@ public final class CountAllFunction extends StaticValue {
return "COUNT";
}
public String getTableName() {
return tableName;
}
public boolean equals(Object o) {
if (o instanceof CountAllFunction) {
CountAllFunction other = (CountAllFunction) o;
return equalsHelper(tableName, other.tableName);
} else {
return false;
}
}
public StringBuilder appendTo(StringBuilder sb) {
sb.append("COUNT(*)");
sb.append("COUNT(");
if (tableName != null) {
sb.append(tableName).append('.');
}
sb.append("*)");
return sb;
}
}
+1 -1
View File
@@ -575,7 +575,7 @@ private StaticValue Count(): {
<COUNT> <OPEN_PAREN> (
n=NamePart() (
<PERIOD> (
<STAR> <CLOSE_PAREN> { return new CountAllFunction(); }
<STAR> <CLOSE_PAREN> { return new CountAllFunction(n); }
| fieldName=NamePart() <CLOSE_PAREN> { return new CountFunction(false, new FieldValue(n, fieldName)); }
)
| <CLOSE_PAREN> { return new CountFunction(false, new FieldValue(null, n)); }
@@ -72,9 +72,18 @@ public class ValuesTest extends GenericTestCaseBase {
assertTrue(label + ":nothing-else-visited", visitor.counts.isEmpty());
}
private static void countAllFunctionTest(String label, CountAllFunction v, String tableName, String s, CountAllFunction o, boolean matches) {
assertEquals(label + ":left", tableName, v.getTableName());
basicTest(label, CountAllFunction.class, v, "COUNT", s, o, matches);
}
public void testCountAllFunction() {
CountAllFunction v1 = new CountAllFunction();
basicTest("count-all", CountAllFunction.class, v1, "COUNT", "COUNT(*)", null, false);
CountAllFunction v1 = new CountAllFunction("a");
countAllFunctionTest("v1", v1, "a", "COUNT(a.*)", null, false);
CountAllFunction v2 = new CountAllFunction(null);
countAllFunctionTest("v2", v2, null, "COUNT(*)", v1, false);
CountAllFunction v3 = new CountAllFunction("a");
countAllFunctionTest("v3", v3, "a", "COUNT(a.*)", v1, true);
}
private static void countFunctionTest(String label, CountFunction v, boolean isDistinct, FieldValue fv, String s, CountFunction o, boolean matches) {