jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thom...@apache.org
Subject svn commit: r1563940 - in /jackrabbit/oak/trunk/oak-core/src: main/java/org/apache/jackrabbit/oak/query/xpath/ test/resources/org/apache/jackrabbit/oak/query/
Date Mon, 03 Feb 2014 14:58:25 GMT
Author: thomasm
Date: Mon Feb  3 14:58:24 2014
New Revision: 1563940

URL: http://svn.apache.org/r1563940
Log:
OAK-1369 XPath queries: compatibility for missing @ in front of property names

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/xpath/Expression.java
    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/Expression.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/xpath/Expression.java?rev=1563940&r1=1563939&r2=1563940&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/xpath/Expression.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/xpath/Expression.java
Mon Feb  3 14:58:24 2014
@@ -180,10 +180,6 @@ abstract class Expression {
             if (right == null) {
                 rightExpr = "";
             } else {
-                if (left != null && left instanceof Property && ((Property)
left).implicitAsterisk) {
-                    throw new IllegalArgumentException(
-                            "Missing @ in front of the property name: " + left);
-                }
                 if (leftExprIsName && !"like".equals(operator)) {
                     // need to de-escape _x0020_ and so on
                     if (!(right instanceof Literal)) {
@@ -275,8 +271,16 @@ abstract class Expression {
     
         @Override
         public String toString() {
-            StringBuilder buff = new StringBuilder("contains").
-                    append('(').append(left).append(", ").append(right).append(')');
+            StringBuilder buff = new StringBuilder("contains(");
+            Expression l = left;
+            if (l instanceof Property) {
+                Property p = (Property) l;
+                if (p.thereWasNoAt) {
+                    l = new Property(p.selector, p.name + "/*", true);
+                }
+            }
+            buff.append(l);
+            buff.append(", ").append(right).append(')');
             return buff.toString();
         }
     
@@ -386,12 +390,18 @@ abstract class Expression {
     
         final Selector selector;
         final String name;
-        final boolean implicitAsterisk;
+        
+        /**
+         * If there was no "@" character in front of the property name. If that
+         * was the case, then it is still considered a property, except for
+         * "contains(x, 'y')", where "x" is considered to be a node.
+         */
+        final boolean thereWasNoAt;
     
-        Property(Selector selector, String name, boolean implicitAsterisk) {
+        Property(Selector selector, String name, boolean thereWasNoAt) {
             this.selector = selector;
             this.name = name;
-            this.implicitAsterisk = implicitAsterisk;
+            this.thereWasNoAt = thereWasNoAt;
         }
     
         @Override

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=1563940&r1=1563939&r2=1563940&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
Mon Feb  3 14:58:24 2014
@@ -552,9 +552,7 @@ public class XPathToSQL2Converter {
             // path without all attributes, as in:
             // jcr:contains(jcr:content, 'x')
             if (buff.toString().equals(".")) {
-                buff = new StringBuilder("*");
-            } else {
-                buff.append("/*");
+                return new Expression.Property(currentSelector, "*", false);
             }
             return new Expression.Property(currentSelector, buff.toString(), 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=1563940&r1=1563939&r2=1563940&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
Mon Feb  3 14:58:24 2014
@@ -23,6 +23,11 @@
 # * new tests are typically be added on top, after the syntax docs
 # * use ascii character only
 
+# property names with missing @
+
+xpath2sql /jcr:root/test/*[@a='1' and b='2' and jcr:contains(c, '3') and jcr:contains(.,
'4') and jcr:contains(@d, '5')] order by e
+select [jcr:path], [jcr:score], * from [nt:base] as a where [a] = '1' and [b] = '2' and contains([c/*],
'3') and contains(*, '4') and contains([d], '5') and ischildnode(a, '/test') order by [e]
/* xpath: /jcr:root/test/*[@a='1' and b='2' and jcr:contains(c, '3') and jcr:contains(., '4')
and jcr:contains(@d, '5')] order by e */
+
 # wildcards in relative property paths
 
 xpath2sql /jcr:root/etc/test//*[@size='M' or */@size='M']
@@ -202,7 +207,7 @@ xpath2sql /jcr:root/testroot/*[jcr:conta
 select [jcr:path], [jcr:score], * from [nt:base] as a where contains(*, '"quick brown" -cat')
and ischildnode(a, '/testroot') /* xpath: /jcr:root/testroot/*[jcr:contains(., '"quick brown"
-cat')] */
 
 xpath2sql //element(*,rep:Authorizable)[(((jcr:contains(profile/givenName,'**') or jcr:contains(profile/familyName,'**'))
or jcr:contains(profile/email,'**')) or (jcr:like(rep:principalName,'%%') or jcr:like(fn:name(.),'%%')))]
order by rep:principalName ascending
-error: java.lang.IllegalArgumentException: Missing @ in front of the property name: [rep:principalName/*]
+select [jcr:path], [jcr:score], * from [rep:Authorizable] as a where contains([profile/givenName/*],
'**') or contains([profile/familyName/*], '**') or contains([profile/email/*], '**') or [rep:principalName]
like '%%' or name(a) like '%%' order by [rep:principalName] /* xpath: //element(*,rep:Authorizable)[(((jcr:contains(profile/givenName,'**')
or jcr:contains(profile/familyName,'**')) or jcr:contains(profile/email,'**')) or (jcr:like(rep:principalName,'%%')
or jcr:like(fn:name(.),'%%')))] order by rep:principalName ascending */
 
 xpath2sql //element(*,rep:Authorizable)[(((jcr:contains(profile/givenName,'**') or jcr:contains(profile/familyName,'**'))
or jcr:contains(profile/email,'**')) or (jcr:like(@rep:principalName,'%%') or jcr:like(fn:name(.),'%%')))]
order by @rep:principalName ascending
 select [jcr:path], [jcr:score], * from [rep:Authorizable] as a where contains([profile/givenName/*],
'**') or contains([profile/familyName/*], '**') or contains([profile/email/*], '**') or [rep:principalName]
like '%%' or name(a) like '%%' order by [rep:principalName] /* xpath: //element(*,rep:Authorizable)[(((jcr:contains(profile/givenName,'**')
or jcr:contains(profile/familyName,'**')) or jcr:contains(profile/email,'**')) or (jcr:like(@rep:principalName,'%%')
or jcr:like(fn:name(.),'%%')))] order by @rep:principalName ascending */



Mime
View raw message