jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From alexparvule...@apache.org
Subject svn commit: r1484404 - in /jackrabbit/oak/trunk/oak-core/src: main/java/org/apache/jackrabbit/oak/query/XPathToSQL2Converter.java test/java/org/apache/jackrabbit/oak/query/SQL2ParserTest.java
Date Mon, 20 May 2013 09:19:19 GMT
Author: alexparvulescu
Date: Mon May 20 09:19:18 2013
New Revision: 1484404

URL: http://svn.apache.org/r1484404
Log:
OAK-830 XPathToSQL2Converter fails to wrap or clauses
 - better fix

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/XPathToSQL2Converter.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/query/SQL2ParserTest.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/XPathToSQL2Converter.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/XPathToSQL2Converter.java?rev=1484404&r1=1484403&r2=1484404&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/XPathToSQL2Converter.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/XPathToSQL2Converter.java
Mon May 20 09:19:18 2013
@@ -355,7 +355,17 @@ public class XPathToSQL2Converter {
                 if (condition.length() > 0) {
                     condition.append(" and ");
                 }
-                condition.append(s.condition);
+                if (s.condition.getPrecedence() == Expression.PRECEDENCE_OR) {
+                    if (condition.length() > 0) {
+                        condition.append("(");
+                        condition.append(s.condition);
+                        condition.append(")");
+                    } else {
+                        condition.append(s.condition);
+                    }
+                } else {
+                    condition.append(s.condition);
+                }
             }
         }
         if (condition.length() > 0) {
@@ -1247,7 +1257,6 @@ public class XPathToSQL2Converter {
         @Override
         public String toString() {
             StringBuilder buff = new StringBuilder();
-            boolean shouldWrap = false;
             if (left != null) {
                 if (left.getPrecedence() < precedence) {
                     buff.append('(').append(left.toString()).append(')');
@@ -1255,7 +1264,6 @@ public class XPathToSQL2Converter {
                     buff.append(left.toString());
                 }
                 buff.append(' ');
-                shouldWrap = left instanceof Condition;
             }
             buff.append(operator);
             if (right != null) {
@@ -1265,11 +1273,6 @@ public class XPathToSQL2Converter {
                 } else {
                     buff.append(right.toString());
                 }
-                shouldWrap = shouldWrap || left instanceof Condition;
-            }
-            if (shouldWrap) {
-                buff.insert(0, "(");
-                buff.append(")");
             }
             return buff.toString();
         }

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/query/SQL2ParserTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/query/SQL2ParserTest.java?rev=1484404&r1=1484403&r2=1484404&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/query/SQL2ParserTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/query/SQL2ParserTest.java
Mon May 20 09:19:18 2013
@@ -59,7 +59,7 @@ public class SQL2ParserTest {
     public void testUnwrappedOr() throws ParseException {
         String q = new XPathToSQL2Converter()
                 .convert("/jcr:root/home//test/* [@type='t1' or @type='t2' or @type='t3']");
-        String token = "and ((b.[type] = 't1' or b.[type] = 't2') or b.[type] = 't3')";
+        String token = "and (b.[type] = 't1' or b.[type] = 't2' or b.[type] = 't3')";
         assertTrue(q.contains(token));
     }
 }



Mime
View raw message