Author: doogie
Date: Fri Dec 18 05:38:49 2009
New Revision: 892143

URL: http://svn.apache.org/viewvc?rev=892143&view=rev
Log:
Detect duplicate relations during parse, by making use of a map.  In
addition, store this map for later use.

Modified:
    ofbiz/trunk/framework/entity/src/org/ofbiz/entity/sql/EntityPlanner.java
    ofbiz/trunk/framework/sql/src/org/ofbiz/sql/Parser.jj
    ofbiz/trunk/framework/sql/src/org/ofbiz/sql/Relation.java
    ofbiz/trunk/framework/sql/src/org/ofbiz/sql/SQLSelect.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=892143&r1=892142&r2=892143&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 
Fri Dec 18 05:38:49 2009
@@ -85,7 +85,7 @@
         for (FieldAll fieldAll: selectStatement.getFieldAlls()) {
             dve.addAliasAll(fieldAll.getAlias(), null);
         }
-        for (Relation relation: selectStatement.getRelations()) {
+        for (Relation relation: selectStatement.getRelations().values()) {
             dve.addRelation(relation.getType(), relation.getTitle(), 
relation.getEntityName(), buildKeyMaps(relation));
         }
         List<String> groupBy = selectStatement.getGroupBy();

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=892143&r1=892142&r2=892143&view=diff
==============================================================================
--- ofbiz/trunk/framework/sql/src/org/ofbiz/sql/Parser.jj (original)
+++ ofbiz/trunk/framework/sql/src/org/ofbiz/sql/Parser.jj Fri Dec 18 05:38:49 
2009
@@ -278,8 +278,7 @@
        Map<String, FieldDef> fieldDefs = FastMap.newInstance();
        List<FieldAll> fieldAlls = FastList.newInstance();
        Table table;
-       List<Relation> relations = FastList.newInstance();
-       Relation relation;
+       Map<String, Relation> relations = FastMap.newInstance();
        Condition whereCondition = null, havingCondition = null;
        int offset = -1, limit = -1;
 }
@@ -289,7 +288,7 @@
                ( <COMMA> FieldDef(fieldDefs, fieldAlls) )*
        )
        <FROM> table=Table()
-       ( <RELATION> relation=Relation() { relations.add(relation); } )*
+       ( <RELATION> Relation(relations) )*
        ( <WHERE> whereCondition=ConditionExpression() )?
        ( <HAVING> havingCondition=ConditionExpression() )?
        ( <GROUP> <BY> groupBy=FieldList() )?
@@ -299,7 +298,7 @@
        { return new SQLSelect(fieldAlls, fieldDefs, table, relations, 
whereCondition, havingCondition, groupBy, orderBy, offset, limit); }
 }
 
-private Relation Relation():
+private void Relation(Map<String, Relation> relations):
 {
        String type = null, title = null, entityName;
        List<KeyMap> keyMaps;
@@ -309,7 +308,11 @@
        ( <TITLE> title=NamePart() )?
        <NAME> { entityName = getToken(0).image; }
        keyMaps=KeyMaps("cur", "other")
-       { return new Relation(type, title, entityName, keyMaps); }
+       {
+               Relation relation = new Relation(type, title, entityName, 
keyMaps);
+               if (relations.containsKey(relation.getName())) throw new 
IllegalArgumentException("Duplicate relation: " + relation);
+               relations.put(relation.getName(), relation);
+       }
 }
 
 

Modified: ofbiz/trunk/framework/sql/src/org/ofbiz/sql/Relation.java
URL: 
http://svn.apache.org/viewvc/ofbiz/trunk/framework/sql/src/org/ofbiz/sql/Relation.java?rev=892143&r1=892142&r2=892143&view=diff
==============================================================================
--- ofbiz/trunk/framework/sql/src/org/ofbiz/sql/Relation.java (original)
+++ ofbiz/trunk/framework/sql/src/org/ofbiz/sql/Relation.java Fri Dec 18 
05:38:49 2009
@@ -22,6 +22,7 @@
 import java.util.List;
 
 public final class Relation extends Atom implements Iterable<KeyMap> {
+    private final String name;
     private final String type;
     private final String title;
     private final String entityName;
@@ -32,6 +33,11 @@
         this.title = title;
         this.entityName = entityName;
         this.keyMaps = keyMaps;
+        this.name = title == null ? entityName : title + entityName;
+    }
+
+    public String getName() {
+        return name;
     }
 
     public String getType() {

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=892143&r1=892142&r2=892143&view=diff
==============================================================================
--- ofbiz/trunk/framework/sql/src/org/ofbiz/sql/SQLSelect.java (original)
+++ ofbiz/trunk/framework/sql/src/org/ofbiz/sql/SQLSelect.java Fri Dec 18 
05:38:49 2009
@@ -30,7 +30,7 @@
     private final List<FieldAll> fieldAlls;
     private final Map<String, FieldDef> fieldDefs;
     private final Table table;
-    private final List<Relation> relations;
+    private final Map<String, Relation> relations;
     private final Condition whereCondition;
     private final Condition havingCondition;
     private final int offset;
@@ -38,7 +38,7 @@
     private final List<OrderByItem> orderBy;
     private final List<String> groupBy;
 
-    public SQLSelect(List<FieldAll> fieldAlls, Map<String, FieldDef> 
fieldDefs, Table table, List<Relation> relations, Condition whereCondition, 
Condition havingCondition, List<String> groupBy, List<OrderByItem> orderBy, int 
offset, int limit) {
+    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) {
         this.fieldAlls = fieldAlls;
         this.fieldDefs = fieldDefs;
         this.table = table;
@@ -63,7 +63,7 @@
         return table;
     }
 
-    public List<Relation> getRelations() {
+    public Map<String, Relation> getRelations() {
         return relations;
     }
 
@@ -101,7 +101,7 @@
         sb.append(" FROM ");
         table.appendTo(sb);
         if (!relations.isEmpty()) {
-            StringUtil.appendTo(sb, relations, " ", null, ",");
+            StringUtil.appendTo(sb, relations.values(), " ", null, ",");
         }
         if (whereCondition != null) {
             sb.append(" WHERE ");


Reply via email to