svn commit: r836088 - /ofbiz/trunk/framework/entity/src/org/ofbiz/entity/sql/Parser.jj

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

svn commit: r836088 - /ofbiz/trunk/framework/entity/src/org/ofbiz/entity/sql/Parser.jj

doogie-3
Author: doogie
Date: Sat Nov 14 01:15:56 2009
New Revision: 836088

URL: http://svn.apache.org/viewvc?rev=836088&view=rev
Log:
Support complex aliases now.  Note, that string default values do not
work corretly, and ModelViewEntity does not do any encoding of the
value, and this parser doesn't handle that.

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

Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/sql/Parser.jj
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/sql/Parser.jj?rev=836088&r1=836087&r2=836088&view=diff
==============================================================================
--- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/sql/Parser.jj (original)
+++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/sql/Parser.jj Sat Nov 14 01:15:56 2009
@@ -42,6 +42,9 @@
 import org.ofbiz.entity.condition.OrderByList;
 import org.ofbiz.entity.model.DynamicViewEntity;
 import org.ofbiz.entity.model.ModelKeyMap;
+import org.ofbiz.entity.model.ModelViewEntity.ComplexAlias;
+import org.ofbiz.entity.model.ModelViewEntity.ComplexAliasField;
+import org.ofbiz.entity.model.ModelViewEntity.ComplexAliasMember;
 import org.ofbiz.entity.model.ModelViewEntity.ModelAlias;
 
 public class Parser {
@@ -85,6 +88,7 @@
 | <DELETE: "DELETE">
 | <UPDATE: "UPDATE">
 | <RELATION: "RELATION">
+| <COALESCE: "COALESCE">
 | <TYPE: "TYPE">
 | <TITLE: "TITLE">
 | <SET: "SET">
@@ -305,9 +309,21 @@
 {
  List<String> fieldUse;
  String tableAlias, fieldName, fieldAlias = null, function;
+ ComplexAliasMember complexAlias;
 }
 {
- function=AggregateFunction()
+ LOOKAHEAD(4) tableAlias=NamePart() <PERIOD>
+ (
+ <STAR> { dve.addAliasAll(tableAlias, null); }
+ | fieldName=NamePart() ( <AS> fieldAlias=NamePart() )? {
+ if (fieldAlias == null) {
+ dve.addAlias(tableAlias, fieldName);
+ } else {
+ dve.addAlias(tableAlias, fieldAlias, fieldName, null, null, null, null);
+ }
+ }
+ )
+| LOOKAHEAD(6) function=AggregateFunction()
  <OPEN_PAREN>
  tableAlias=NamePart() <PERIOD> fieldName=NamePart()
  <CLOSE_PAREN>
@@ -318,17 +334,73 @@
  dve.addAlias(tableAlias, fieldAlias, fieldName, null, null, null, function);
  }
  }
-| tableAlias=NamePart() <PERIOD>
- (
- <STAR> { dve.addAliasAll(tableAlias, null); }
- | fieldName=NamePart() ( <AS> fieldAlias=NamePart() )? {
- if (fieldAlias == null) {
- dve.addAlias(tableAlias, fieldName);
- } else {
- dve.addAlias(tableAlias, fieldAlias, fieldName, null, null, null, null);
+| complexAlias=ComplexAliasMember() <AS> fieldAlias=NamePart() {
+ dve.addAlias(null, fieldAlias, null, null, null, null, null, complexAlias);
+ }
+}
+
+private ComplexAliasMember ComplexAlias():
+{
+ List<ComplexAliasMember> list = FastList.newInstance();
+ ComplexAliasMember member;
+ String operator = null, newOperator;
+}
+{
+ <OPEN_PAREN>
+ member=ComplexAliasMember() { list.add(member); }
+ (
+ ( <AND> | <OR> ) { newOperator = getToken(0).image.toLowerCase(); }
+ member=ComplexAliasMember() {
+ if (operator == null) {
+ operator = newOperator;
+ } else if (!newOperator.equals(operator)) {
+ throw new IllegalArgumentException("Different operators in complex alias(" + operator + ":" + newOperator + ")");
+ }
+ list.add(member);
  }
- }
- )
+ )*
+ <CLOSE_PAREN>
+ {
+ if (list.size() == 1) return list.get(0);
+ ComplexAlias complexAlias = new ComplexAlias(operator);
+ complexAlias.addAllComplexAliasMembers(list);
+ return complexAlias;
+ }
+}
+
+private ComplexAliasMember ComplexAliasMember():
+{
+ ComplexAliasMember member;
+}
+{
+ member=ComplexAlias() { return member; }
+| member=ComplexAliasField() { return member; }
+}
+
+private ComplexAliasMember ComplexAliasField():
+{
+ String function = null, tableName, fieldName;
+ Object dflt = null;
+}
+{
+ (
+ function=AggregateFunction() <OPEN_PAREN> (
+ <COALESCE> <OPEN_PAREN>
+ tableName=NamePart() <PERIOD> fieldName=NamePart()
+ <COMMA>
+ dflt=ConstantValue()
+ <CLOSE_PAREN>
+ | tableName=NamePart() <PERIOD> fieldName=NamePart()
+ ) <CLOSE_PAREN>
+ | <COALESCE> <OPEN_PAREN>
+ tableName=NamePart() <PERIOD> fieldName=NamePart()
+ <COMMA>
+ dflt=ConstantValue()
+ <CLOSE_PAREN>
+ | tableName=NamePart() <PERIOD> fieldName=NamePart()
+ ) {
+ return new ComplexAliasField(tableName, fieldName, dflt != null ? dflt.toString() : null, function);
+ }
 }
 
 private String NamePart():
@@ -420,12 +492,20 @@
 private Object Expression():
 {
  EntityConditionValue ecv;
+ Object v;
+}
+{
+ ecv=FieldUse() { return ecv; }
+| v=ConstantValue() { return v; }
+}
+
+private Object ConstantValue():
+{
  String s;
  int i;
 }
 {
- ecv=FieldUse() { return ecv; }
-| i=Integer() { return i; }
+ i=Integer() { return i; }
 | s=SQuoted() { return s; }
 }