jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From alexparvule...@apache.org
Subject svn commit: r1484393 - 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 08:20:17 GMT
Author: alexparvulescu
Date: Mon May 20 08:20:17 2013
New Revision: 1484393

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

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=1484393&r1=1484392&r2=1484393&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 08:20:17 2013
@@ -1247,6 +1247,7 @@ 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(')');
@@ -1254,6 +1255,7 @@ public class XPathToSQL2Converter {
                     buff.append(left.toString());
                 }
                 buff.append(' ');
+                shouldWrap = left instanceof Condition;
             }
             buff.append(operator);
             if (right != null) {
@@ -1263,6 +1265,11 @@ 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=1484393&r1=1484392&r2=1484393&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 08:20:17 2013
@@ -16,6 +16,7 @@
  */
 package org.apache.jackrabbit.oak.query;
 
+import static junit.framework.Assert.assertTrue;
 import static org.apache.jackrabbit.JcrConstants.JCR_SYSTEM;
 import static org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState.EMPTY_NODE;
 import static org.apache.jackrabbit.oak.plugins.nodetype.NodeTypeConstants.JCR_NODE_TYPES;
@@ -49,4 +50,16 @@ public class SQL2ParserTest {
                 .convert("/jcr:root/test/*/nt:resource[@jcr:encoding]"));
     }
 
+    /**
+     * @see <a
+     *      href="https://issues.apache.org/jira/browse/OAK-OAK-830">OAK-OAK-830:
+     *      XPathToSQL2Converter fails to wrap or clauses</a>
+     */
+    @Test
+    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')";
+        assertTrue(q.contains(token));
+    }
 }



Mime
View raw message