svn commit: r949600 - in /ofbiz/trunk/framework/sql/src/org/ofbiz/sql: Parser.jj SQLSelect.java

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

svn commit: r949600 - in /ofbiz/trunk/framework/sql/src/org/ofbiz/sql: Parser.jj SQLSelect.java

doogie-3
Author: doogie
Date: Sun May 30 22:06:17 2010
New Revision: 949600

URL: http://svn.apache.org/viewvc?rev=949600&view=rev
Log:
Start adding DISTINCT support to SELECT.

Modified:
    ofbiz/trunk/framework/sql/src/org/ofbiz/sql/Parser.jj
    ofbiz/trunk/framework/sql/src/org/ofbiz/sql/SQLSelect.java

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=949600&r1=949599&r2=949600&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:17 2010
@@ -278,6 +278,7 @@ private SQLView View():
 private SQLSelect Select():
 {
     Integer i;
+    boolean isDistinct = false;
     List<OrderByItem> orderBy = null;
     List<String> groupBy = null;
     Map<String, FieldDef> fieldDefs = FastMap.newInstance();
@@ -289,7 +290,7 @@ private SQLSelect Select():
     int offset = -1, limit = -1;
 }
 {
-    <SELECT> (
+    <SELECT> (<DISTINCT> { isDistinct = true; })? (
         FieldDef(fieldDefs, fieldAlls, fieldAllAliases)
         ( <COMMA> FieldDef(fieldDefs, fieldAlls, fieldAllAliases) )*
     )
@@ -301,7 +302,7 @@ private SQLSelect Select():
     ( <ORDER> <BY> orderBy=OrderByList() )?
     ( <OFFSET> offset=Integer() )?
     ( <LIMIT> limit=Integer() )?
-    { return new SQLSelect(fieldAlls, fieldDefs, table, relations, whereCondition, havingCondition, groupBy, orderBy, offset, limit); }
+    { return new SQLSelect(isDistinct, fieldAlls, fieldDefs, table, relations, whereCondition, havingCondition, groupBy, orderBy, offset, limit); }
 }
 
 private void Relation(Map<String, Relation> relations):

Modified: ofbiz/trunk/framework/sql/src/org/ofbiz/sql/SQLSelect.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/sql/src/org/ofbiz/sql/SQLSelect.java?rev=949600&r1=949599&r2=949600&view=diff
==============================================================================
--- ofbiz/trunk/framework/sql/src/org/ofbiz/sql/SQLSelect.java (original)
+++ ofbiz/trunk/framework/sql/src/org/ofbiz/sql/SQLSelect.java Sun May 30 22:06:17 2010
@@ -27,6 +27,7 @@ import java.util.Map;
 import org.ofbiz.base.util.StringUtil;
 
 public final class SQLSelect extends SQLStatement<SQLSelect> implements InsertSource {
+    private final boolean isDistinct;
     private final List<FieldAll> fieldAlls;
     private final Map<String, FieldDef> fieldDefs;
     private final Table table;
@@ -38,7 +39,8 @@ public final class SQLSelect extends SQL
     private final List<OrderByItem> orderBy;
     private final List<String> groupBy;
 
-    public SQLSelect(List<FieldAll> fieldAlls, Map<String, FieldDef> fieldDefs, Table table, Map<String, Relation> relations, Condition whereCondition, Condition havingCondition, List<String> groupBy, List<OrderByItem> orderBy, int offset, int limit) {
+    public SQLSelect(boolean isDistinct, List<FieldAll> fieldAlls, Map<String, FieldDef> fieldDefs, Table table, Map<String, Relation> relations, Condition whereCondition, Condition havingCondition, List<String> groupBy, List<OrderByItem> orderBy, int offset, int limit) {
+        this.isDistinct = isDistinct;
         this.fieldAlls = fieldAlls;
         this.fieldDefs = fieldDefs;
         this.table = table;
@@ -55,6 +57,10 @@ public final class SQLSelect extends SQL
         visitor.visit(this);
     }
 
+    public boolean getIsDistinct() {
+        return isDistinct;
+    }
+
     public Collection<FieldAll> getFieldAlls() {
         return fieldAlls;
     }
@@ -97,6 +103,9 @@ public final class SQLSelect extends SQL
 
     public StringBuilder appendTo(StringBuilder sb) {
         sb.append("SELECT");
+        if (isDistinct) {
+            sb.append(" DISTINCT");
+        }
         StringUtil.appendTo(sb, fieldAlls, " ", null, ",");
         if (!fieldAlls.isEmpty() && !fieldDefs.isEmpty()) {
             sb.append(',');