You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by th...@apache.org on 2013/09/04 09:57:04 UTC

svn commit: r1519928 - in /jackrabbit/oak/trunk/oak-core/src: main/java/org/apache/jackrabbit/oak/query/XPathToSQL2Converter.java test/resources/org/apache/jackrabbit/oak/query/xpath.txt

Author: thomasm
Date: Wed Sep  4 07:57:04 2013
New Revision: 1519928

URL: http://svn.apache.org/r1519928
Log:
OAK-989 Query parser doesn't decode paths
OAK-994 XPath to SQL-2 conversion error for "element(..)"

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

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=1519928&r1=1519927&r2=1519928&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 Wed Sep  4 07:57:04 2013
@@ -17,6 +17,7 @@
 package org.apache.jackrabbit.oak.query;
 
 import org.apache.jackrabbit.oak.commons.PathUtils;
+import org.apache.jackrabbit.util.ISO9075;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -176,10 +177,9 @@ public class XPathToSQL2Converter {
                         // any
                         pathPattern += "%";
                     } else {
-                        currentSelector.isChild = false;
-                        String name = readIdentifier();
+                        String name = readPathSegment();
                         pathPattern += name;
-                        currentSelector.path = PathUtils.concat(currentSelector.path, name);
+                        appendNodeName(name);
                     }
                     if (readIf(",")) {
                         currentSelector.nodeType = readIdentifier();
@@ -210,24 +210,9 @@ public class XPathToSQL2Converter {
                 read(")");
             } else if (currentTokenType == IDENTIFIER) {
                 // path restriction
-                String name = readIdentifier();
+                String name = readPathSegment();
                 pathPattern += name;
-                if (!currentSelector.isChild) {
-                    currentSelector.nodeName = name;
-                } else {
-                    if (selectors.size() > 0) {
-                        // no explicit path restriction - so it's a node name restriction
-                        currentSelector.isChild = true;
-                        currentSelector.nodeName = name;
-                    } else {
-                        if (currentSelector.isChild) {
-                            currentSelector.isChild = false;
-                            String oldPath = currentSelector.path;
-                            // further extending the path
-                            currentSelector.path = PathUtils.concat(oldPath, name);
-                        }
-                    }
-                }
+                appendNodeName(name);
             } else if (readIf(".")) {
                 // just "." this is simply ignored, so that
                 // "a/./b" is the same as "a/b"
@@ -366,6 +351,23 @@ public class XPathToSQL2Converter {
         return buff.toString();
     }
     
+    private void appendNodeName(String name) {
+        if (!currentSelector.isChild) {
+            currentSelector.nodeName = name;
+        } else {
+            if (selectors.size() > 0) {
+                // no explicit path restriction - so it's a node name restriction
+                currentSelector.isChild = true;
+                currentSelector.nodeName = name;
+            } else {
+                currentSelector.isChild = false;
+                String oldPath = currentSelector.path;
+                // further extending the path
+                currentSelector.path = PathUtils.concat(oldPath, name);
+            }
+        }
+    }
+    
     /**
      * Switch back to the old selector when reading a property. This occurs
      * after reading a "/", but then reading a property or a list of properties.
@@ -725,6 +727,11 @@ public class XPathToSQL2Converter {
         }
     }
 
+    private String readPathSegment() throws ParseException {
+        String raw = readIdentifier();
+        return ISO9075.decode(raw);
+    }
+
     private String readIdentifier() throws ParseException {
         if (currentTokenType != IDENTIFIER) {
             throw getSyntaxError("identifier");

Modified: jackrabbit/oak/trunk/oak-core/src/test/resources/org/apache/jackrabbit/oak/query/xpath.txt
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/resources/org/apache/jackrabbit/oak/query/xpath.txt?rev=1519928&r1=1519927&r2=1519928&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/resources/org/apache/jackrabbit/oak/query/xpath.txt (original)
+++ jackrabbit/oak/trunk/oak-core/src/test/resources/org/apache/jackrabbit/oak/query/xpath.txt Wed Sep  4 07:57:04 2013
@@ -97,6 +97,9 @@ select [jcr:path], [jcr:score], * from [
 xpath2sql //*
 select [jcr:path], [jcr:score], * from [nt:base] as a /* xpath: //* */
 
+xpath2sql //element(hello, nt:base)
+select [jcr:path], [jcr:score], * from [nt:base] as a where name(a) = 'hello' /* xpath: //element(hello, nt:base) */
+
 xpath2sql test/*
 select [jcr:path], [jcr:score], * from [nt:base] as a where ischildnode(a, '/test') /* xpath: test/* */