jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From alexparvule...@apache.org
Subject svn commit: r1127001 - in /jackrabbit/trunk/jackrabbit-core/src: main/java/org/apache/jackrabbit/core/query/lucene/LuceneQueryFactory.java test/java/org/apache/jackrabbit/core/query/SQL2NodeLocalNameTest.java
Date Tue, 24 May 2011 12:24:25 GMT
Author: alexparvulescu
Date: Tue May 24 12:24:24 2011
New Revision: 1127001

URL: http://svn.apache.org/viewvc?rev=1127001&view=rev
Log:
JCR-2956 SQL2: Implement LIKE support for node names
this fix has already been applied to 2.2 in rev #1099087, just making sure trunk does not
get left behind

Added:
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/SQL2NodeLocalNameTest.java
  (with props)
Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/LuceneQueryFactory.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/LuceneQueryFactory.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/LuceneQueryFactory.java?rev=1127001&r1=1127000&r2=1127001&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/LuceneQueryFactory.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/LuceneQueryFactory.java
Tue May 24 12:24:24 2011
@@ -330,10 +330,8 @@ public class LuceneQueryFactory {
             StaticOperand right = c.getOperand2();
             if (left instanceof Length
                     || left instanceof FullTextSearchScore
-                    || ((!JCR_OPERATOR_EQUAL_TO.equals(operator)
-                            || transform.transform != TRANSFORM_NONE)
-                            && (left instanceof NodeName
-                                    || left instanceof NodeLocalName))) {
+                    || (((!JCR_OPERATOR_EQUAL_TO.equals(operator) && !JCR_OPERATOR_LIKE
+                            .equals(operator)) || transform.transform != TRANSFORM_NONE)
&& (left instanceof NodeName || left instanceof NodeLocalName))) {
                 try {
                     int type = PropertyType.UNDEFINED;
                     if (left instanceof Length) {
@@ -615,15 +613,18 @@ public class LuceneQueryFactory {
         }
     }
 
-    protected Query getNodeLocalNameQuery(
-            int transform, String operator, StaticOperand right)
-            throws RepositoryException {
+    protected Query getNodeLocalNameQuery(int transform, String operator,
+            StaticOperand right) throws RepositoryException {
         if (transform != TRANSFORM_NONE
-                || !JCR_OPERATOR_EQUAL_TO.equals(operator)) {
+                || (!JCR_OPERATOR_EQUAL_TO.equals(operator) && !JCR_OPERATOR_LIKE
+                        .equals(operator))) {
             throw new UnsupportedRepositoryOperationException();
         }
-
         String name = evaluator.getValue(right).getString();
+
+        if (JCR_OPERATOR_LIKE.equals(operator)) {
+            return new WildcardQuery(LOCAL_NAME, null, name, transform, cache);
+        }
         return new JackrabbitTermQuery(new Term(LOCAL_NAME, name));
     }
 

Added: 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=1127001&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/SQL2NodeLocalNameTest.java
(added)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/SQL2NodeLocalNameTest.java
Tue May 24 12:24:24 2011
@@ -0,0 +1,94 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.core.query;
+
+import javax.jcr.Node;
+
+import org.apache.jackrabbit.commons.JcrUtils;
+
+/**
+ * Test case for Node LocalName queries with JCR_SQL2
+ * 
+ * Inspired by <a
+ * href="https://issues.apache.org/jira/browse/JCR-2956">JCR-2956</a>
+ */
+public class SQL2NodeLocalNameTest extends AbstractQueryTest {
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+        testRootNode.addNode("SQL2NodeLocalNameTest_node1");
+        testRootNode.addNode("SQL2NodeLocalNameTest_node2");
+        testRootNode.getSession().save();
+    }
+
+    @Override
+    protected void tearDown() throws Exception {
+        for (Node c : JcrUtils.getChildNodes(testRootNode)) {
+            testRootNode.getSession().removeItem(c.getPath());
+        }
+        superuser.save();
+        super.tearDown();
+    }
+
+    public void testEq() throws Exception {
+        checkResult(
+                executeSQL2Query("SELECT * FROM [nt:base] as NODE WHERE localname(NODE) =
'SQL2NodeLocalNameTest_node1' "),
+                1);
+    }
+
+    public void testLikeEnd() throws Exception {
+        checkResult(
+                executeSQL2Query("SELECT * FROM [nt:base] as NODE WHERE localname(NODE) like
'SQL2NodeLocalNameTest%' "),
+                2);
+    }
+
+    public void testLikeMiddle() throws Exception {
+        checkResult(
+                executeSQL2Query("SELECT * FROM [nt:base] as NODE WHERE localname(NODE) like
'%NodeLocalNameTest%' "),
+                2);
+    }
+
+    public void testLikeNoHits() throws Exception {
+        checkResult(
+                executeSQL2Query("SELECT * FROM [nt:base] as NODE WHERE localname(NODE) like
'XXX_NodeLocalNameTest_XXX' "),
+                0);
+    }
+
+    /**
+     * funny enough, this will return the <b>root</b> node
+     */
+    public void testLikeEmpty() throws Exception {
+        checkResult(
+                executeSQL2Query("SELECT * FROM [nt:base] as NODE WHERE localname(NODE) like
'' "),
+                1);
+    }
+
+    public void testLikeEmptyAsChild() throws Exception {
+        checkResult(
+                executeSQL2Query("SELECT * FROM [nt:base] as NODE WHERE ischildnode(NODE,
["
+                        + testRootNode.getPath()
+                        + "]) AND localname(NODE) like '' "), 0);
+    }
+
+    public void testLikeAllAsChild() throws Exception {
+        checkResult(
+                executeSQL2Query("SELECT * FROM [nt:base] as NODE WHERE ischildnode(NODE,
["
+                        + testRootNode.getPath()
+                        + "]) AND localname(NODE) like '%' "), 2);
+    }
+}

Propchange: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/SQL2NodeLocalNameTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message