olingo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From m...@apache.org
Subject [14/33] olingo-odata2 git commit: [OLINGO-478] Fix for operator precedence bug in ODataExpression parser for JPA
Date Wed, 10 Dec 2014 19:31:03 GMT
[OLINGO-478] Fix for operator precedence bug in ODataExpression parser
for JPA


Signed-off-by: Chandan V A <chandan.v.a@sap.com>

Project: http://git-wip-us.apache.org/repos/asf/olingo-odata2/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata2/commit/a92b4e82
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata2/tree/a92b4e82
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata2/diff/a92b4e82

Branch: refs/heads/Olingo-129_PocJpaDataStore
Commit: a92b4e826865215ad929398d1c76db6b2995996d
Parents: 95a11bc
Author: Chandan V A <chandan.v.a@sap.com>
Authored: Sat Nov 1 12:54:54 2014 +0530
Committer: Chandan V A <chandan.v.a@sap.com>
Committed: Sat Nov 1 12:54:54 2014 +0530

----------------------------------------------------------------------
 .../processor/core/ODataExpressionParser.java   | 36 ++++++++++++++------
 .../core/ODataExpressionParserTest.java         | 22 ++++++------
 2 files changed, 37 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/a92b4e82/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/ODataExpressionParser.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/ODataExpressionParser.java
b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/ODataExpressionParser.java
index 7da1e90..0e765be 100644
--- a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/ODataExpressionParser.java
+++ b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/ODataExpressionParser.java
@@ -80,7 +80,8 @@ public class ODataExpressionParser {
 
       switch (unaryExpression.getOperator()) {
       case NOT:
-        return JPQLStatement.Operator.NOT + "(" + operand + ")"; //$NON-NLS-1$ //$NON-NLS-2$
+        return JPQLStatement.Operator.NOT + JPQLStatement.DELIMITER.PARENTHESIS_LEFT + operand
+            + JPQLStatement.DELIMITER.PARENTHESIS_RIGHT; //$NON-NLS-1$ //$NON-NLS-2$
       case MINUS:
         if (operand.startsWith("-")) {
           return operand.substring(1);
@@ -106,22 +107,37 @@ public class ODataExpressionParser {
 
       switch (binaryExpression.getOperator()) {
       case AND:
-        return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.AND + JPQLStatement.DELIMITER.SPACE
-            + right;
+        return JPQLStatement.DELIMITER.PARENTHESIS_LEFT + left + JPQLStatement.DELIMITER.SPACE
+            + JPQLStatement.Operator.AND + JPQLStatement.DELIMITER.SPACE
+            + right + JPQLStatement.DELIMITER.PARENTHESIS_RIGHT;
       case OR:
-        return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.OR + JPQLStatement.DELIMITER.SPACE
+ right;
+        return JPQLStatement.DELIMITER.PARENTHESIS_LEFT + left + JPQLStatement.DELIMITER.SPACE
+            + JPQLStatement.Operator.OR + JPQLStatement.DELIMITER.SPACE + right
+            + JPQLStatement.DELIMITER.PARENTHESIS_RIGHT;
       case EQ:
-        return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.EQ + JPQLStatement.DELIMITER.SPACE
+ right;
+        return JPQLStatement.DELIMITER.PARENTHESIS_LEFT + left + JPQLStatement.DELIMITER.SPACE
+            + JPQLStatement.Operator.EQ + JPQLStatement.DELIMITER.SPACE + right
+            + JPQLStatement.DELIMITER.PARENTHESIS_RIGHT;
       case NE:
-        return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.NE + JPQLStatement.DELIMITER.SPACE
+ right;
+        return JPQLStatement.DELIMITER.PARENTHESIS_LEFT + left + JPQLStatement.DELIMITER.SPACE
+            + JPQLStatement.Operator.NE + JPQLStatement.DELIMITER.SPACE + right
+            + JPQLStatement.DELIMITER.PARENTHESIS_RIGHT;
       case LT:
-        return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.LT + JPQLStatement.DELIMITER.SPACE
+ right;
+        return JPQLStatement.DELIMITER.PARENTHESIS_LEFT + left + JPQLStatement.DELIMITER.SPACE
+            + JPQLStatement.Operator.LT + JPQLStatement.DELIMITER.SPACE + right
+            + JPQLStatement.DELIMITER.PARENTHESIS_RIGHT;
       case LE:
-        return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.LE + JPQLStatement.DELIMITER.SPACE
+ right;
+        return JPQLStatement.DELIMITER.PARENTHESIS_LEFT + left + JPQLStatement.DELIMITER.SPACE
+            + JPQLStatement.Operator.LE + JPQLStatement.DELIMITER.SPACE + right
+            + JPQLStatement.DELIMITER.PARENTHESIS_RIGHT;
       case GT:
-        return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.GT + JPQLStatement.DELIMITER.SPACE
+ right;
+        return JPQLStatement.DELIMITER.PARENTHESIS_LEFT + left + JPQLStatement.DELIMITER.SPACE
+            + JPQLStatement.Operator.GT + JPQLStatement.DELIMITER.SPACE + right
+            + JPQLStatement.DELIMITER.PARENTHESIS_RIGHT;
       case GE:
-        return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.GE + JPQLStatement.DELIMITER.SPACE
+ right;
+        return JPQLStatement.DELIMITER.PARENTHESIS_LEFT + left + JPQLStatement.DELIMITER.SPACE
+            + JPQLStatement.Operator.GE + JPQLStatement.DELIMITER.SPACE + right
+            + JPQLStatement.DELIMITER.PARENTHESIS_RIGHT;
       case PROPERTY_ACCESS:
         throw new ODataNotImplementedException();
       default:

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/a92b4e82/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/ODataExpressionParserTest.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/ODataExpressionParserTest.java
b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/ODataExpressionParserTest.java
index 422b5ab..3ca93c5 100644
--- a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/ODataExpressionParserTest.java
+++ b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/ODataExpressionParserTest.java
@@ -54,23 +54,23 @@ import org.junit.Test;
 
 public class ODataExpressionParserTest {
 
-  private static final String EXPECTED_STR_1 = "gwt1.SalesOrder = 1234";
-  private static final String EXPECTED_STR_2 = "gwt1.SalesOrder >= 1234 AND gwt1.SalesABC
<> XYZ";
-  private static final String EXPECTED_STR_3 = "gwt1.SalesOrder >= 1234 OR gwt1.SalesABC
<> XYZ";
-  private static final String EXPECTED_STR_4 = "gwt1.SalesOrder < 1234 AND gwt1.SalesABC
<= XYZ";
-  private static final String EXPECTED_STR_5 = "gwt1.LineItems > 2345 AND gwt1.SalesOrder
>= Amazon";
-  private static final String EXPECTED_STR_6 = "gwt1.Address.city = \'City_3\'";
-  private static final String EXPECTED_STR_7 = "gwt1.Address.city.area = \'BTM\'";
+  private static final String EXPECTED_STR_1 = "(gwt1.SalesOrder = 1234)";
+  private static final String EXPECTED_STR_2 = "((gwt1.SalesOrder >= 1234) AND (gwt1.SalesABC
<> XYZ))";
+  private static final String EXPECTED_STR_3 = "((gwt1.SalesOrder >= 1234) OR (gwt1.SalesABC
<> XYZ))";
+  private static final String EXPECTED_STR_4 = "((gwt1.SalesOrder < 1234) AND (gwt1.SalesABC
<= XYZ))";
+  private static final String EXPECTED_STR_5 = "((gwt1.LineItems > 2345) AND (gwt1.SalesOrder
>= Amazon))";
+  private static final String EXPECTED_STR_6 = "(gwt1.Address.city = \'City_3\')";
+  private static final String EXPECTED_STR_7 = "(gwt1.Address.city.area = \'BTM\')";
   private static final String EXPECTED_STR_8 = "gwt1.field1 = 1 AND gwt1.field2 = 'abc'";
   private static final String EXPECTED_STR_9 = "gwt1.BuyerAddress, gwt1.BuyerName, gwt1.BuyerId";
   private static final String EXPECTED_STR_10 = "gwt1.SalesOrder";
   private static final String EXPECTED_STR_11 = "NOT(gwt1.deliveryStatus)";
   private static final String EXPECTED_STR_12 =
-      "(CASE WHEN (gwt1.currencyCode LIKE '%Ru%') THEN TRUE ELSE FALSE END) = true";
-  private static final String EXPECTED_STR_13 = "SUBSTRING(gwt1.currencyCode, 1 + 1 , 2)
= 'NR'";
-  private static final String EXPECTED_STR_14 = "LOWER(gwt1.currencyCode) = 'inr rupees'";
+      "((CASE WHEN (gwt1.currencyCode LIKE '%Ru%') THEN TRUE ELSE FALSE END) = true)";
+  private static final String EXPECTED_STR_13 = "(SUBSTRING(gwt1.currencyCode, 1 + 1 , 2)
= 'NR')";
+  private static final String EXPECTED_STR_14 = "(LOWER(gwt1.currencyCode) = 'inr rupees')";
   private static final String EXPECTED_STR_15 =
-      "(CASE WHEN (LOWER(gwt1.currencyCode) LIKE '%nr rupees%') THEN TRUE ELSE FALSE END)
= true";
+      "((CASE WHEN (LOWER(gwt1.currencyCode) LIKE '%nr rupees%') THEN TRUE ELSE FALSE END)
= true)";
   private static final String EXPECTED_STR_16 =
       "(CASE WHEN (gwt1.currencyCode LIKE '%INR%') THEN TRUE ELSE FALSE END) = true";
   private static final String EXPECTED_STR_17 =


Mime
View raw message