Author: doogie
Date: Mon Aug 2 17:43:02 2010
New Revision: 981627
URL: http://svn.apache.org/viewvc?rev=981627&view=rev
Log:
BUG FIX: CountAll needs to remember the tableName; also implement
equals.
Modified:
ofbiz/trunk/framework/sql/src/org/ofbiz/sql/CountAllFunction.java
ofbiz/trunk/framework/sql/src/org/ofbiz/sql/Parser.jj
ofbiz/trunk/framework/sql/src/org/ofbiz/sql/test/ValuesTest.java
Modified: ofbiz/trunk/framework/sql/src/org/ofbiz/sql/CountAllFunction.java
URL:
http://svn.apache.org/viewvc/ofbiz/trunk/framework/sql/src/org/ofbiz/sql/CountAllFunction.java?rev=981627&r1=981626&r2=981627&view=diff
==============================================================================
--- ofbiz/trunk/framework/sql/src/org/ofbiz/sql/CountAllFunction.java (original)
+++ ofbiz/trunk/framework/sql/src/org/ofbiz/sql/CountAllFunction.java Mon Aug
2 17:43:02 2010
@@ -22,6 +22,12 @@ import org.ofbiz.base.lang.SourceMonitor
@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 exte
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;
}
}
Modified: ofbiz/trunk/framework/sql/src/org/ofbiz/sql/Parser.jj
URL:
http://svn.apache.org/viewvc/ofbiz/trunk/framework/sql/src/org/ofbiz/sql/Parser.jj?rev=981627&r1=981626&r2=981627&view=diff
==============================================================================
--- ofbiz/trunk/framework/sql/src/org/ofbiz/sql/Parser.jj (original)
+++ ofbiz/trunk/framework/sql/src/org/ofbiz/sql/Parser.jj Mon Aug 2 17:43:02
2010
@@ -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)); }
Modified: ofbiz/trunk/framework/sql/src/org/ofbiz/sql/test/ValuesTest.java
URL:
http://svn.apache.org/viewvc/ofbiz/trunk/framework/sql/src/org/ofbiz/sql/test/ValuesTest.java?rev=981627&r1=981626&r2=981627&view=diff
==============================================================================
--- ofbiz/trunk/framework/sql/src/org/ofbiz/sql/test/ValuesTest.java (original)
+++ ofbiz/trunk/framework/sql/src/org/ofbiz/sql/test/ValuesTest.java Mon Aug 2
17:43:02 2010
@@ -72,9 +72,18 @@ public class ValuesTest extends GenericT
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) {