jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r216172 - in /incubator/jackrabbit/trunk/core/src: java/org/apache/jackrabbit/core/query/lucene/ test/org/apache/jackrabbit/core/query/
Date Wed, 13 Jul 2005 14:59:07 GMT
Author: mreutegg
Date: Wed Jul 13 07:59:05 2005
New Revision: 216172

URL: http://svn.apache.org/viewcvs?rev=216172&view=rev
Log:
- Keep getPosition() values continuous even in case of invalid nodes.

Modified:
    incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/lucene/DocOrderNodeIteratorImpl.java
    incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/lucene/NodeIteratorImpl.java
    incubator/jackrabbit/trunk/core/src/test/org/apache/jackrabbit/core/query/SkipDeletedNodesTest.java

Modified: incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/lucene/DocOrderNodeIteratorImpl.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/lucene/DocOrderNodeIteratorImpl.java?rev=216172&r1=216171&r2=216172&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/lucene/DocOrderNodeIteratorImpl.java
(original)
+++ incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/lucene/DocOrderNodeIteratorImpl.java
Wed Jul 13 07:59:05 2005
@@ -107,12 +107,17 @@
      * of nodes actually returned by calls to hasNext() / getNextNode()! This
      * is because this iterator works on a lazy instantiation basis and while
      * iterating over the nodes some of them might have been deleted in the
-     * meantime. Those will not be returned by getNextNode().
+     * meantime. Those will not be returned by getNextNode(). As soon as an
+     * invalid node is detected, the size of this iterator is adjusted.
      *
      * @return the number of node in this iterator.
      */
     public long getSize() {
-        return uuids.length;
+        if (orderedNodes != null) {
+            return orderedNodes.getSize();
+        } else {
+            return uuids.length;
+        }
     }
 
     /**

Modified: incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/lucene/NodeIteratorImpl.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/lucene/NodeIteratorImpl.java?rev=216172&r1=216171&r2=216172&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/lucene/NodeIteratorImpl.java
(original)
+++ incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/lucene/NodeIteratorImpl.java
Wed Jul 13 07:59:05 2005
@@ -46,6 +46,9 @@
     /** Current position in the UUID array */
     protected int pos = -1;
 
+    /** Number of invalid nodes */
+    protected int invalid = 0;
+
     /** Reference to the next node instance */
     private NodeImpl next;
 
@@ -128,12 +131,13 @@
      * of nodes actually returned by calls to hasNext() / getNextNode()! This
      * is because this iterator works on a lazy instantiation basis and while
      * iterating over the nodes some of them might have been deleted in the
-     * meantime. Those will not be returned by getNextNode().
+     * meantime. Those will not be returned by getNextNode(). As soon as an
+     * invalid node is detected, the size of this iterator is adjusted.
      *
      * @return the number of node in this iterator.
      */
     public long getSize() {
-        return uuids.length;
+        return uuids.length - invalid;
     }
 
     /**
@@ -141,7 +145,7 @@
      * @return the current position in this <code>NodeIterator</code>.
      */
     public long getPosition() {
-        return pos;
+        return pos - invalid;
     }
 
     /**
@@ -187,9 +191,10 @@
             try {
                 next = (NodeImpl) itemMgr.getItem(new NodeId(uuids[pos + 1]));
             } catch (RepositoryException e) {
-                log.error("Exception retrieving Node with UUID: "
+                log.warn("Exception retrieving Node with UUID: "
                         + uuids[pos + 1] + ": " + e.toString());
                 // try next
+                invalid++;
                 pos++;
             }
         }

Modified: incubator/jackrabbit/trunk/core/src/test/org/apache/jackrabbit/core/query/SkipDeletedNodesTest.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/core/src/test/org/apache/jackrabbit/core/query/SkipDeletedNodesTest.java?rev=216172&r1=216171&r2=216172&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/core/src/test/org/apache/jackrabbit/core/query/SkipDeletedNodesTest.java
(original)
+++ incubator/jackrabbit/trunk/core/src/test/org/apache/jackrabbit/core/query/SkipDeletedNodesTest.java
Wed Jul 13 07:59:05 2005
@@ -71,7 +71,9 @@
 
         // iterate over nodes
         log.println("Result nodes:");
+        int count = 0;
         for (NodeIterator it = res.getNodes(); it.hasNext(); ) {
+            assertEquals("Wrong value for getPosition().", count++, it.getPosition());
             try {
                 log.println(it.nextNode().getPath());
             } catch (InvalidItemStateException e) {
@@ -100,8 +102,10 @@
         testRootNode.save();
 
         // iterate over nodes
+        int count = 0;
         log.println("Result nodes:");
         for (NodeIterator it = res.getNodes(); it.hasNext(); ) {
+            assertEquals("Wrong value for getPosition().", count++, it.getPosition());
             try {
                 log.println(it.nextNode().getPath());
             } catch (InvalidItemStateException e) {
@@ -130,8 +134,10 @@
         testRootNode.save();
 
         // iterate over nodes
+        int count = 0;
         log.println("Result nodes:");
         for (NodeIterator it = res.getNodes(); it.hasNext(); ) {
+            assertEquals("Wrong value for getPosition().", count++, it.getPosition());
             try {
                 log.println(it.nextNode().getPath());
             } catch (InvalidItemStateException e) {
@@ -166,8 +172,48 @@
         testRootNode.save();
 
         // iterate over nodes
+        int count = 0;
         log.println("Result nodes:");
         while (it.hasNext()) {
+            assertEquals("Wrong value for getPosition().", count++, it.getPosition());
+            try {
+                log.println(it.nextNode().getPath());
+            } catch (InvalidItemStateException e) {
+                // this is allowed
+                log.println("Invalid: <deleted>");
+            }
+        }
+    }
+
+    /**
+     * Executes a query with one session and removes a node from that query
+     * result with another session.
+     * </p>This test is different from the other tests that it removes the
+     * node after another session has called hasNext() to retrieve the node
+     * that gets deleted.
+     */
+    public void testRemoveSomeNodeAfterHasNext() throws RepositoryException {
+        testRootNode.addNode("node1");
+        Node n2 = testRootNode.addNode("node2");
+        testRootNode.addNode("node3");
+        testRootNode.save();
+
+        // query the workspace for all three nodes
+        String stmt = testPath + "/*";
+        QueryResult res = qm.createQuery(stmt, Query.XPATH).execute();
+
+        NodeIterator it = res.getNodes();
+        it.hasNext();
+
+        // now remove the second node
+        n2.remove();
+        testRootNode.save();
+
+        // iterate over nodes
+        int count = 0;
+        log.println("Result nodes:");
+        while (it.hasNext()) {
+            assertEquals("Wrong value for getPosition().", count++, it.getPosition());
             try {
                 log.println(it.nextNode().getPath());
             } catch (InvalidItemStateException e) {



Mime
View raw message