jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From alexparvule...@apache.org
Subject svn commit: r1207838 - in /jackrabbit/trunk: jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/SQL2NodeLocalNameTest.java jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/query/qom/OperandEvaluator.java
Date Tue, 29 Nov 2011 11:48:35 GMT
Author: alexparvulescu
Date: Tue Nov 29 11:48:34 2011
New Revision: 1207838

URL: http://svn.apache.org/viewvc?rev=1207838&view=rev
Log:
JCR-3159 LOWER operand with nested LOCALNAME operand not work with SQL2

Modified:
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/SQL2NodeLocalNameTest.java
    jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/query/qom/OperandEvaluator.java

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/SQL2NodeLocalNameTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/SQL2NodeLocalNameTest.java?rev=1207838&r1=1207837&r2=1207838&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/SQL2NodeLocalNameTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/SQL2NodeLocalNameTest.java
Tue Nov 29 11:48:34 2011
@@ -91,4 +91,31 @@ public class SQL2NodeLocalNameTest exten
                         + testRootNode.getPath()
                         + "]) AND localname(NODE) like '%' "), 2);
     }
+
+    /**
+     * test for JCR-3159
+     */
+    public void testLowerLocalName() throws Exception {
+        checkResult(
+                executeSQL2Query("SELECT * FROM [nt:base] as NODE WHERE LOWER(localname(NODE))
like 'sql2nodelocalnametest%'"),
+                2);
+    }
+
+    /**
+     * test for JCR-3159
+     */
+    public void testUpperLocalName() throws Exception {
+        checkResult(
+                executeSQL2Query("SELECT * FROM [nt:base] as NODE WHERE UPPER(localname(NODE))
like 'SQL2NODELOCALNAMETEST%'"),
+                2);
+    }
+
+    /**
+     * test for JCR-3159
+     */
+    public void testLowerName() throws Exception {
+        checkResult(
+                executeSQL2Query("SELECT * FROM [nt:base] as NODE WHERE LOWER(name(NODE))
like 'sql2nodelocalnametest%'"),
+                2);
+    }
 }

Modified: jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/query/qom/OperandEvaluator.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/query/qom/OperandEvaluator.java?rev=1207838&r1=1207837&r2=1207838&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/query/qom/OperandEvaluator.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/query/qom/OperandEvaluator.java
Tue Nov 29 11:48:34 2011
@@ -188,10 +188,13 @@ public class OperandEvaluator {
             return new Value[] { factory.createValue(score) };
         } else if (operand instanceof NodeName) {
             NodeName nn = (NodeName) operand;
-            Value value = factory.createValue(
-                    row.getNode(nn.getSelectorName()).getName(),
-                    PropertyType.NAME);
-            return new Value[] { value };
+            String name = row.getNode(nn.getSelectorName()).getName();
+            // root node
+            if ("".equals(name)) {
+                return new Value[] { factory.createValue(name,
+                        PropertyType.STRING) };
+            }
+            return new Value[] { factory.createValue(name, PropertyType.NAME) };
         } else if (operand instanceof Length) {
             return getLengthValues((Length) operand, row);
         } else if (operand instanceof LowerCase) {
@@ -227,9 +230,13 @@ public class OperandEvaluator {
             return new Value[] { factory.createValue(defaultScore) };
         }
         if (operand instanceof NodeName) {
-            Value value = factory
-                    .createValue(node.getName(), PropertyType.NAME);
-            return new Value[] { value };
+            String name = node.getName();
+            // root node
+            if ("".equals(name)) {
+                return new Value[] { factory.createValue(name,
+                        PropertyType.STRING) };
+            }
+            return new Value[] { factory.createValue(name, PropertyType.NAME) };
         }
         if (operand instanceof Length) {
             return getLengthValues((Length) operand, node);
@@ -415,6 +422,11 @@ public class OperandEvaluator {
     private Value[] getNodeLocalNameValues(NodeLocalName operand, Node node)
             throws RepositoryException {
         String name = node.getName();
+
+        // root node has no local name
+        if ("".equals(name)) {
+            return new Value[] { factory.createValue("", PropertyType.STRING) };
+        }
         int colon = name.indexOf(':');
         if (colon != -1) {
             name = name.substring(colon + 1);



Mime
View raw message