Detect duplicate relations during parse, by making use of a map. In
addition, store this map for later use. git-svn-id: https://svn.apache.org/repos/asf/ofbiz/trunk@892143 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
@@ -278,8 +278,7 @@ private SQLSelect Select():
|
||||
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 @@ private SQLSelect Select():
|
||||
( <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 @@ private SQLSelect Select():
|
||||
{ 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 @@ private Relation Relation():
|
||||
( <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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ import java.util.Iterator;
|
||||
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 @@ public final class Relation extends Atom implements Iterable<KeyMap> {
|
||||
this.title = title;
|
||||
this.entityName = entityName;
|
||||
this.keyMaps = keyMaps;
|
||||
this.name = title == null ? entityName : title + entityName;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
|
||||
@@ -30,7 +30,7 @@ public final class SQLSelect extends SQLStatement<SQLSelect> implements InsertSo
|
||||
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 @@ public final class SQLSelect extends SQLStatement<SQLSelect> implements InsertSo
|
||||
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 @@ public final class SQLSelect extends SQLStatement<SQLSelect> implements InsertSo
|
||||
return table;
|
||||
}
|
||||
|
||||
public List<Relation> getRelations() {
|
||||
public Map<String, Relation> getRelations() {
|
||||
return relations;
|
||||
}
|
||||
|
||||
@@ -101,7 +101,7 @@ public final class SQLSelect extends SQLStatement<SQLSelect> implements InsertSo
|
||||
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 ");
|
||||
|
||||
Reference in New Issue
Block a user