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 2016/05/19 08:45:46 UTC
svn commit: r1744535 - in /jackrabbit/oak/trunk/oak-core/src:
main/java/org/apache/jackrabbit/oak/query/xpath/XPathToSQL2Converter.java
test/resources/org/apache/jackrabbit/oak/query/xpath.txt
Author: thomasm
Date: Thu May 19 08:45:46 2016
New Revision: 1744535
URL: http://svn.apache.org/viewvc?rev=1744535&view=rev
Log:
OAK-4376 XPath: queries starting with "//" are not always converted correctly
Modified:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/xpath/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/xpath/XPathToSQL2Converter.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/xpath/XPathToSQL2Converter.java?rev=1744535&r1=1744534&r2=1744535&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/xpath/XPathToSQL2Converter.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/xpath/XPathToSQL2Converter.java Thu May 19 08:45:46 2016
@@ -162,6 +162,10 @@ public class XPathToSQL2Converter {
} else if (readIf("/")) {
// "//" was read
pathPattern += "%";
+ if (currentSelector.isDescendant) {
+ // the query started with "//", and now "//" was read
+ nextSelector(true);
+ }
currentSelector.isDescendant = true;
} else {
// the token "/" was read
@@ -169,6 +173,10 @@ public class XPathToSQL2Converter {
if (startOfQuery) {
currentSelector.path = "/";
} else {
+ if (currentSelector.isDescendant) {
+ // the query started with "//", and now "/" was read
+ nextSelector(true);
+ }
currentSelector.isChild = true;
}
}
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=1744535&r1=1744534&r2=1744535&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 Thu May 19 08:45:46 2016
@@ -24,6 +24,22 @@
# * new tests are typically be added on top, after the syntax docs
# * use ascii character only
+# OAK-4376
+
+xpath2sql //element(*, oak:QueryIndexDefinition)/*
+select b.[jcr:path] as [jcr:path], b.[jcr:score] as [jcr:score], b.*
+ from [oak:QueryIndexDefinition] as a
+ inner join [nt:base] as b
+ on ischildnode(b, a)
+ /* xpath ... */
+
+xpath2sql //element(*, oak:QueryIndexDefinition)//*
+select b.[jcr:path] as [jcr:path], b.[jcr:score] as [jcr:score], b.*
+ from [oak:QueryIndexDefinition] as a
+ inner join [nt:base] as b
+ on isdescendantnode(b, a)
+ /* xpath ... */
+
# nested conditions are converted to union
xpath2sql /jcr:root/test//element(*, nt:unstructured)[