svn commit: r949603 - in /ofbiz/trunk/framework: entity/src/org/ofbiz/entity/sql/ sql/src/org/ofbiz/sql/ sql/src/org/ofbiz/sql/test/

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r949603 - in /ofbiz/trunk/framework: entity/src/org/ofbiz/entity/sql/ sql/src/org/ofbiz/sql/ sql/src/org/ofbiz/sql/test/

doogie-3
Author: doogie
Date: Sun May 30 22:06:31 2010
New Revision: 949603

URL: http://svn.apache.org/viewvc?rev=949603&view=rev
Log:
Remove FieldDefFieldValue, and merge FieldDefValue into FieldDef.

Removed:
    ofbiz/trunk/framework/sql/src/org/ofbiz/sql/FieldDefFieldValue.java
    ofbiz/trunk/framework/sql/src/org/ofbiz/sql/FieldDefValue.java
Modified:
    ofbiz/trunk/framework/entity/src/org/ofbiz/entity/sql/EntityPlanner.java
    ofbiz/trunk/framework/sql/src/org/ofbiz/sql/FieldDef.java
    ofbiz/trunk/framework/sql/src/org/ofbiz/sql/Parser.jj
    ofbiz/trunk/framework/sql/src/org/ofbiz/sql/test/SQLTest.java

Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/sql/EntityPlanner.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/sql/EntityPlanner.java?rev=949603&r1=949602&r2=949603&view=diff
==============================================================================
--- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/sql/EntityPlanner.java (original)
+++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/sql/EntityPlanner.java Sun May 30 22:06:31 2010
@@ -41,8 +41,6 @@ import org.ofbiz.sql.ConditionList;
 import org.ofbiz.sql.ConstantValue;
 import org.ofbiz.sql.FieldAll;
 import org.ofbiz.sql.FieldDef;
-import org.ofbiz.sql.FieldDefFieldValue;
-import org.ofbiz.sql.FieldDefValue;
 import org.ofbiz.sql.FieldValue;
 import org.ofbiz.sql.FunctionCall;
 import org.ofbiz.sql.Joined;
@@ -117,10 +115,11 @@ public class EntityPlanner extends Plann
     }
 
     private static void addFieldDef(DynamicViewEntity dve, List<String> groupBy, String alias, FieldDef fieldDef) {
-        if (fieldDef instanceof FieldDefFieldValue) {
-            addFieldDef(dve, groupBy, fieldDef.getAlias(), ((FieldDefFieldValue) fieldDef).getFieldValue(), null);
-        } else if (fieldDef instanceof FieldDefValue) {
-            addFieldDef(dve, groupBy, fieldDef.getAlias(), ((FieldDefValue) fieldDef).getValue());
+        StaticValue value = fieldDef.getValue();
+        if (value instanceof FieldValue) {
+            addFieldDef(dve, groupBy, fieldDef.getAlias(), (FieldValue) value, null);
+        } else if (value instanceof ConstantValue) {
+            addFieldDef(dve, groupBy, fieldDef.getAlias(), (ConstantValue) value);
         } else {
             throw new UnsupportedOperationException(alias + "[" + fieldDef + "]:" + fieldDef.getClass());
         }

Modified: ofbiz/trunk/framework/sql/src/org/ofbiz/sql/FieldDef.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/sql/src/org/ofbiz/sql/FieldDef.java?rev=949603&r1=949602&r2=949603&view=diff
==============================================================================
--- ofbiz/trunk/framework/sql/src/org/ofbiz/sql/FieldDef.java (original)
+++ ofbiz/trunk/framework/sql/src/org/ofbiz/sql/FieldDef.java Sun May 30 22:06:31 2010
@@ -18,14 +18,26 @@
  */
 package org.ofbiz.sql;
 
-public abstract class FieldDef extends Atom {
-    protected final String alias;
+public final class FieldDef extends Atom {
+    private final String alias;
+    private final StaticValue value;
 
-    protected FieldDef(String alias) {
-        this.alias = alias;
+    public FieldDef(StaticValue value, String alias) {
+        this.alias = alias == null ? value.getDefaultName() : alias;
+        this.value = value;
     }
 
     public final String getAlias() {
         return alias;
     }
+
+    public StaticValue getValue() {
+        return value;
+    }
+
+    public StringBuilder appendTo(StringBuilder sb) {
+        value.appendTo(sb);
+        sb.append(" AS ").append(alias);
+        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=949603&r1=949602&r2=949603&view=diff
==============================================================================
--- ofbiz/trunk/framework/sql/src/org/ofbiz/sql/Parser.jj (original)
+++ ofbiz/trunk/framework/sql/src/org/ofbiz/sql/Parser.jj Sun May 30 22:06:31 2010
@@ -554,13 +554,13 @@ private void FieldDef(Map<String, FieldD
                     <CLOSE_PAREN>
                 )?
                 { fieldAlls.add(new FieldAll(n, excludeList)); return; }
-            | fieldName=NamePart() ( <AS> fieldAlias=NamePart() )? { def = new FieldDefFieldValue(new FieldValue(n, fieldName), fieldAlias); }
+            | fieldName=NamePart() ( <AS> fieldAlias=NamePart() )? { def = new FieldDef(new FieldValue(n, fieldName), fieldAlias); }
             )
-        |    v=FunctionCallRest(n) ( <AS> fieldAlias=NamePart() )? { def = new FieldDefValue(v, fieldAlias); }
-        |    ( <AS> fieldAlias=NamePart() )? { def = new FieldDefFieldValue(new FieldValue(null, n), fieldAlias); }
+        |    v=FunctionCallRest(n) ( <AS> fieldAlias=NamePart() )? { def = new FieldDef(v, fieldAlias); }
+        |    ( <AS> fieldAlias=NamePart() )? { def = new FieldDef(new FieldValue(null, n), fieldAlias); }
         )
-    |    v=MathValue() ( <AS> fieldAlias=NamePart() )? { def = new FieldDefValue(v, fieldAlias); }
-    |   v=Count() ( <AS> fieldAlias=NamePart() )? { def = new FieldDefValue(v, fieldAlias); }
+    |    v=MathValue() ( <AS> fieldAlias=NamePart() )? { def = new FieldDef(v, fieldAlias); }
+    |   v=Count() ( <AS> fieldAlias=NamePart() )? { def = new FieldDef(v, fieldAlias); }
     ) {
         if (fieldDefs.containsKey(def.getAlias())) throw new ParseException("duplicate alias(" + def.getAlias() + ")");
         fieldDefs.put(def.getAlias(), def);

Modified: ofbiz/trunk/framework/sql/src/org/ofbiz/sql/test/SQLTest.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/sql/src/org/ofbiz/sql/test/SQLTest.java?rev=949603&r1=949602&r2=949603&view=diff
==============================================================================
--- ofbiz/trunk/framework/sql/src/org/ofbiz/sql/test/SQLTest.java (original)
+++ ofbiz/trunk/framework/sql/src/org/ofbiz/sql/test/SQLTest.java Sun May 30 22:06:31 2010
@@ -32,8 +32,6 @@ import junit.framework.TestCase;
 import org.ofbiz.sql.Condition;
 import org.ofbiz.sql.FieldAll;
 import org.ofbiz.sql.FieldDef;
-import org.ofbiz.sql.FieldDefFieldValue;
-import org.ofbiz.sql.FieldDefValue;
 import org.ofbiz.sql.FieldValue;
 import org.ofbiz.sql.FunctionCall;
 import org.ofbiz.sql.MathValue;
@@ -84,28 +82,32 @@ public class SQLTest extends GenericTest
             assertTrue("has first field def", fieldDefIt.hasNext());
             FieldDef fieldDef = fieldDefIt.next();
             assertEquals("first fieldDef.alias", "roleTypeId", fieldDef.getAlias());
-            assertTrue("first is FieldDefFieldValue", fieldDef instanceof FieldDefFieldValue);
-            FieldDefFieldValue fdfv = (FieldDefFieldValue) fieldDef;
-            assertEquals("first fieldDef.tableName", "d", fdfv.getFieldValue().getTableName());
-            assertEquals("first fieldDef.fieldName", "roleTypeId", fdfv.getFieldValue().getFieldName());
-            assertEquals("first fieldDef.defaultName", "roleTypeId", fdfv.getFieldValue().getDefaultName());
+            assertTrue("first is FieldDef", fieldDef instanceof FieldDef);
+            FieldDef fdfv = (FieldDef) fieldDef;
+            assertTrue("first has FieldValue", fdfv.getValue() instanceof FieldValue);
+            FieldValue fv = (FieldValue) fdfv.getValue();
+            assertEquals("first fieldDef.tableName", "d", fv.getTableName());
+            assertEquals("first fieldDef.fieldName", "roleTypeId", fv.getFieldName());
+            assertEquals("first fieldDef.defaultName", "roleTypeId", fv.getDefaultName());
 
             assertTrue("has second field def", fieldDefIt.hasNext());
             fieldDef = fieldDefIt.next();
             assertEquals("second fieldDef.alias", "roleDescription", fieldDef.getAlias());
-            assertTrue("second is FieldDefFieldValue", fieldDef instanceof FieldDefFieldValue);
-            fdfv = (FieldDefFieldValue) fieldDef;
-            assertEquals("second fieldDef.tableName", "d", fdfv.getFieldValue().getTableName());
-            assertEquals("second fieldDef.fieldName", "description", fdfv.getFieldValue().getFieldName());
-            assertEquals("second fieldDef.defaultName", "description", fdfv.getFieldValue().getDefaultName());
+            assertTrue("second is FieldDef", fieldDef instanceof FieldDef);
+            fdfv = (FieldDef) fieldDef;
+            assertTrue("second has FieldValue", fdfv.getValue() instanceof FieldValue);
+            fv = (FieldValue) fdfv.getValue();
+            assertEquals("second fieldDef.tableName", "d", fv.getTableName());
+            assertEquals("second fieldDef.fieldName", "description", fv.getFieldName());
+            assertEquals("second fieldDef.defaultName", "description", fv.getDefaultName());
 
             assertTrue("has third field def", fieldDefIt.hasNext());
             fieldDef = fieldDefIt.next();
             assertEquals("third fieldDef.alias", "SUM", fieldDef.getAlias());
-            assertTrue("third is FieldDefValue", fieldDef instanceof FieldDefValue);
-            FieldDefValue fdv = (FieldDefValue) fieldDef;
-            assertTrue("third fieldDefValue.staticValue is FunctionCall", fdv.getValue() instanceof FunctionCall);
-            FunctionCall fc = (FunctionCall) fdv.getValue();
+            assertTrue("third is FieldDef", fieldDef instanceof FieldDef);
+            FieldDef fd = (FieldDef) fieldDef;
+            assertTrue("third fieldDefValue.staticValue is FunctionCall", fd.getValue() instanceof FunctionCall);
+            FunctionCall fc = (FunctionCall) fd.getValue();
             assertEquals("third arg count", 1, fc.getArgCount());
             Iterator<Value> valueIt = fc.iterator();
             assertTrue("third args hasNext", valueIt.hasNext());
@@ -119,32 +121,32 @@ public class SQLTest extends GenericTest
             assertTrue("has fourth field def", fieldDefIt.hasNext());
             fieldDef = fieldDefIt.next();
             assertEquals("fourth fieldDef.alias", "baz", fieldDef.getAlias());
-            assertTrue("fourth is FieldDefValue", fieldDef instanceof FieldDefValue);
-            fdv = (FieldDefValue) fieldDef;
+            assertTrue("fourth is FieldDef", fieldDef instanceof FieldDef);
+            fd = (FieldDef) fieldDef;
 
             assertTrue("has fifth field def", fieldDefIt.hasNext());
             fieldDef = fieldDefIt.next();
             assertEquals("fifth fieldDef.alias", "one", fieldDef.getAlias());
-            assertTrue("fifth is FieldDefValue", fieldDef instanceof FieldDefValue);
-            fdv = (FieldDefValue) fieldDef;
+            assertTrue("fifth is FieldDef", fieldDef instanceof FieldDef);
+            fd = (FieldDef) fieldDef;
 
             assertTrue("has sixth field def", fieldDefIt.hasNext());
             fieldDef = fieldDefIt.next();
             assertEquals("sixth fieldDef.alias", "cnt1", fieldDef.getAlias());
-            assertTrue("sixth is FieldDefValue", fieldDef instanceof FieldDefValue);
-            fdv = (FieldDefValue) fieldDef;
+            assertTrue("sixth is FieldDef", fieldDef instanceof FieldDef);
+            fd = (FieldDef) fieldDef;
 
             assertTrue("has seventh field def", fieldDefIt.hasNext());
             fieldDef = fieldDefIt.next();
             assertEquals("seventh fieldDef.alias", "cnt2", fieldDef.getAlias());
-            assertTrue("seventh is FieldDefValue", fieldDef instanceof FieldDefValue);
-            fdv = (FieldDefValue) fieldDef;
+            assertTrue("seventh is FieldDef", fieldDef instanceof FieldDef);
+            fd = (FieldDef) fieldDef;
 
             assertTrue("has eighth field def", fieldDefIt.hasNext());
             fieldDef = fieldDefIt.next();
             assertEquals("eighth fieldDef.alias", "cnt3", fieldDef.getAlias());
-            assertTrue("eighth is FieldDefValue", fieldDef instanceof FieldDefValue);
-            fdv = (FieldDefValue) fieldDef;
+            assertTrue("eighth is FieldDef", fieldDef instanceof FieldDef);
+            fd = (FieldDef) fieldDef;
 
             assertFalse("has no more field def", fieldDefIt.hasNext());