jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r668086 - in /jackrabbit/trunk: jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/DerefTest.java jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/query/NAryQueryNode.java
Date Mon, 16 Jun 2008 09:25:02 GMT
Author: mreutegg
Date: Mon Jun 16 02:25:02 2008
New Revision: 668086

URL: http://svn.apache.org/viewvc?rev=668086&view=rev
Log:
JCR-1650: XPathQueryBuilder may not handle multiple jcr:deref correctly

Modified:
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/DerefTest.java
    jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/query/NAryQueryNode.java

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/DerefTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/DerefTest.java?rev=668086&r1=668085&r2=668086&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/DerefTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/DerefTest.java
Mon Jun 16 02:25:02 2008
@@ -50,9 +50,9 @@
      *            + eric (worksfor -> company/sun)
      *      + frank (worksfor -> company/microsoft)
      *   + company
-     *      + sun
-     *      + microsoft
-     *      + ibm
+     *      + sun (eotm -> andrew)
+     *      + microsoft (eotm -> carl)
+     *      + ibm (eotm -> daren)
      * </pre>
      */
     protected void setUp() throws Exception {
@@ -72,18 +72,26 @@
         ibm.setProperty("ceo", "Palmisano");
 
         andrew = people.addNode("andrew");
+        andrew.addMixin(mixReferenceable);
         andrew.setProperty("worksfor", sun);
         bill = andrew.addNode("bill");
         bill.setProperty("worksfor", ibm);
         carl = people.addNode("carl");
+        carl.addMixin(mixReferenceable);
         carl.setProperty("worksfor", microsoft);
         daren = carl.addNode("daren");
+        daren.addMixin(mixReferenceable);
         daren.setProperty("worksfor", ibm);
         eric = daren.addNode("eric");
         eric.setProperty("worksfor", sun);
         frank = people.addNode("frank");
         frank.setProperty("worksfor", microsoft);
 
+        // Employees of the month
+        sun.setProperty("eotm", andrew);
+        microsoft.setProperty("eotm", carl);
+        ibm.setProperty("eotm", daren);
+
         testRootNode.save();
     }
 
@@ -155,4 +163,27 @@
             assertTrue(node.getProperty("jcr:frozenUuid").getString().equals(referenced.getUUID()));
         }
     }
+
+    /**
+     * Tests various XPath queries with multiple jcr:deref() function.
+     */
+    public void testMultipleDeref() throws RepositoryException {
+        executeXPathQuery(testPath + "/people/frank/jcr:deref(@worksfor, '*')/jcr:deref(@eotm,
'*')",
+                new Node[]{carl});
+        executeXPathQuery(testPath + "/people/frank/jcr:deref(@worksfor, '*')/jcr:deref(@eotm,
'*')[@jcr:uuid]",
+                new Node[]{carl});
+        executeXPathQuery(testPath + "/people/frank/jcr:deref(@worksfor, '*')[@jcr:uuid]/jcr:deref(@eotm,
'*')[@jcr:uuid]",
+                new Node[]{carl});
+        executeXPathQuery(testPath + "/people/frank/jcr:deref(@worksfor, '*')[@jcr:uuid]/jcr:deref(@eotm,
'*')",
+                new Node[]{carl});
+
+        executeXPathQuery(testPath + "/people//jcr:deref(@worksfor, '*')/jcr:deref(@eotm,
'*')",
+                new Node[]{andrew, carl, daren});
+        executeXPathQuery(testPath + "/people//jcr:deref(@worksfor, '*')/jcr:deref(@eotm,
'*')[@jcr:uuid]",
+                new Node[]{andrew, carl, daren});
+        executeXPathQuery(testPath + "/people//jcr:deref(@worksfor, '*')[@jcr:uuid]/jcr:deref(@eotm,
'*')[@jcr:uuid]",
+                new Node[]{andrew, carl, daren});
+        executeXPathQuery(testPath + "/people//jcr:deref(@worksfor, '*')[@jcr:uuid]/jcr:deref(@eotm,
'*')",
+                new Node[]{andrew, carl, daren});
+    }
 }

Modified: jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/query/NAryQueryNode.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/query/NAryQueryNode.java?rev=668086&r1=668085&r2=668086&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/query/NAryQueryNode.java
(original)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/query/NAryQueryNode.java
Mon Jun 16 02:25:02 2008
@@ -85,7 +85,15 @@
         if (operands == null) {
             return false;
         }
-        return operands.remove(operand);
+        // JCR-1650 search the operand without relying on Object#equals(Object)
+        Iterator it = operands.iterator();
+        while (it.hasNext()) {
+            if (it.next() == operand) {
+                it.remove();
+                return true;
+            }
+        }
+        return false;
     }
 
     /**



Mime
View raw message