jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thom...@apache.org
Subject svn commit: r1409134 - in /jackrabbit/oak/trunk: oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/old/ oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/ oak-core/src/main/java/org/apache/jackrabbit/oak/spi/query/ oak-core/src/te...
Date Wed, 14 Nov 2012 10:04:56 GMT
Author: thomasm
Date: Wed Nov 14 10:04:55 2012
New Revision: 1409134

URL: http://svn.apache.org/viewvc?rev=1409134&view=rev
Log:
OAK-423 Query: org.apache.jackrabbit.oak.spi.query.Cursor.currentRow called too late - refactor
the Cursor interface to better match the Iterator interface

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/old/PrefixContentIndex.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/old/PropertyContentIndex.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/SelectorImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/query/Cursor.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/query/Cursors.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/nodetype/NodeTypeIndexTest.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/query/index/TraversingIndexTest.java
    jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexTest.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/old/PrefixContentIndex.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/old/PrefixContentIndex.java?rev=1409134&r1=1409133&r2=1409134&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/old/PrefixContentIndex.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/old/PrefixContentIndex.java
Wed Nov 14 10:04:55 2012
@@ -112,26 +112,22 @@ public class PrefixContentIndex implemen
 
         private final Iterator<String> it;
 
-        private String currentPath;
-
         public ContentCursor(Iterator<String> it) {
             this.it = it;
         }
 
         @Override
-        public IndexRow currentRow() {
-            return new IndexRowImpl(currentPath);
+        public IndexRow next() {
+            String pathAndProperty = it.next();
+            String path = PathUtils.getParentPath(pathAndProperty);
+            return new IndexRowImpl(path);
         }
-
+        
         @Override
-        public boolean next() {
-            if (it.hasNext()) {
-                String pathAndProperty = it.next();
-                currentPath = PathUtils.getParentPath(pathAndProperty);
-                return true;
-            }
-            return false;
+        public boolean hasNext() {
+            return it.hasNext();
         }
+        
     }
     
     @Override

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/old/PropertyContentIndex.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/old/PropertyContentIndex.java?rev=1409134&r1=1409133&r2=1409134&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/old/PropertyContentIndex.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/old/PropertyContentIndex.java
Wed Nov 14 10:04:55 2012
@@ -92,25 +92,21 @@ public class PropertyContentIndex implem
 
         private final Iterator<String> it;
 
-        private String currentPath;
-
         public ContentCursor(Iterator<String> it) {
             this.it = it;
         }
-
+        
         @Override
-        public IndexRow currentRow() {
-            return new IndexRowImpl(currentPath);
+        public IndexRow next() {
+            String path = it.next();
+            return new IndexRowImpl(path);
         }
-
+        
         @Override
-        public boolean next() {
-            if (it.hasNext()) {
-                currentPath = it.next();
-                return true;
-            }
-            return false;
+        public boolean hasNext() {
+            return it.hasNext();
         }
+        
     }
     
     @Override

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/SelectorImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/SelectorImpl.java?rev=1409134&r1=1409133&r2=1409134&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/SelectorImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/SelectorImpl.java
Wed Nov 14 10:04:55 2012
@@ -57,6 +57,7 @@ public class SelectorImpl extends Source
 
     private final String nodeTypeName, selectorName;
     private Cursor cursor;
+    private IndexRow currentRow;
     private int scanCount;
     /**
      * Iterable over selected node type and its subtypes
@@ -145,9 +146,10 @@ public class SelectorImpl extends Source
 
     @Override
     public boolean next() {
-        while (cursor != null && cursor.next()) {
+        while (cursor != null && cursor.hasNext()) {
             scanCount++;
-            Tree tree = getTree(cursor.currentRow().getPath());
+            currentRow = cursor.next();
+            Tree tree = getTree(currentRow.getPath());
             if (tree == null) {
                 continue;
             }
@@ -165,6 +167,7 @@ public class SelectorImpl extends Source
             return true;
         }
         cursor = null;
+        currentRow = null;
         return false;
     }
 
@@ -215,7 +218,7 @@ public class SelectorImpl extends Source
      * @return the path
      */
     public String currentPath() {
-        return cursor == null ? null : cursor.currentRow().getPath();
+        return cursor == null ? null : currentRow.getPath();
     }
 
     public PropertyValue currentProperty(String propertyName) {
@@ -234,7 +237,7 @@ public class SelectorImpl extends Source
         if (cursor == null) {
             return null;
         }
-        IndexRow r = cursor.currentRow();
+        IndexRow r = currentRow;
         if (r == null) {
             return null;
         }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/query/Cursor.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/query/Cursor.java?rev=1409134&r1=1409133&r2=1409134&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/query/Cursor.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/query/Cursor.java
Wed Nov 14 10:04:55 2012
@@ -24,14 +24,7 @@ package org.apache.jackrabbit.oak.spi.qu
 public interface Cursor {
 
     /**
-     * Skip to the next node if one is available.
-     *
-     * @return true if another row is available
-     */
-    boolean next();
-
-    /**
-     * The current row within this index.
+     * The next row within this index.
      * <p>
      * The row may only contains the path, if a path is available. It may also
      * (or just) contain so-called "pseudo-properties" such as "jcr:score" and
@@ -53,6 +46,8 @@ public interface Cursor {
      * 
      * @return the row
      */
-    IndexRow currentRow();
+    IndexRow next();
+    
+    boolean hasNext();
 
 }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/query/Cursors.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/query/Cursors.java?rev=1409134&r1=1409133&r2=1409134&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/query/Cursors.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/query/Cursors.java
Wed Nov 14 10:04:55 2012
@@ -74,28 +74,22 @@ public class Cursors {
 
         private final Iterator<String> iterator;
 
-        private String path;
-
         public PathCursor(Iterable<String> paths) {
             this.iterator = paths.iterator();
         }
 
         @Override
-        public boolean next() {
-            if (iterator.hasNext()) {
-                path = iterator.next();
-                return true;
-            } else {
-                path = null;
-                return false;
-            }
-        }
-
-        @Override
-        public IndexRow currentRow() {
+        public IndexRow next() {
             // TODO support jcr:score and possibly rep:exceprt
+            String path = iterator.next();
             return new IndexRowImpl(isAbsolute(path) ? path : "/" + path);
         }
+        
+        @Override
+        public boolean hasNext() {
+            return iterator.hasNext();
+        }
+        
     }
 
     /**
@@ -116,6 +110,8 @@ public class Cursors {
 
         private long readCount;
 
+        private boolean init;
+        
         private boolean closed;
 
         public TraversingCursor(Filter filter, NodeState root) {
@@ -165,15 +161,29 @@ public class Cursors {
         }
 
         @Override
-        public IndexRow currentRow() {
+        public IndexRow next() {
             if (closed) {
                 throw new IllegalStateException("This cursor is closed");
             }
-            return new IndexRowImpl(currentPath);
+            if (!init) {
+                fetchNext();
+                init = true;
+            }
+            IndexRowImpl result = new IndexRowImpl(currentPath);
+            fetchNext();
+            return result;
+        }
+        
+        @Override 
+        public boolean hasNext() {
+            if (!closed && !init) {
+                fetchNext();
+                init = true;
+            }
+            return !closed;
         }
 
-        @Override
-        public boolean next() {
+        private void fetchNext() {
             while (!nodeIterators.isEmpty()) {
                 Iterator<? extends ChildNodeEntry> iterator = nodeIterators.getLast();
                 if (iterator.hasNext()) {
@@ -196,7 +206,7 @@ public class Cursors {
                         nodeIterators.addLast(node.getChildNodeEntries().iterator());
                         parentPath = currentPath;
                     }
-                    return true;
+                    return;
                 } else {
                     nodeIterators.removeLast();
                     parentPath = PathUtils.getParentPath(parentPath);
@@ -204,7 +214,6 @@ public class Cursors {
             }
             currentPath = null;
             closed = true;
-            return false;
         }
 
     }

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/nodetype/NodeTypeIndexTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/nodetype/NodeTypeIndexTest.java?rev=1409134&r1=1409133&r2=1409134&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/nodetype/NodeTypeIndexTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/nodetype/NodeTypeIndexTest.java
Wed Nov 14 10:04:55 2012
@@ -100,8 +100,8 @@ public class NodeTypeIndexTest {
         Set<String> expected = Sets.newHashSet();
         expected.addAll(Arrays.asList(matches));
         Set<String> actual = Sets.newHashSet();
-        while (cursor.next()) {
-            actual.add(cursor.currentRow().getPath());
+        while (cursor.hasNext()) {
+            actual.add(cursor.next().getPath());
         }
         assertEquals(expected, actual);
     }

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/query/index/TraversingIndexTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/query/index/TraversingIndexTest.java?rev=1409134&r1=1409133&r2=1409134&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/query/index/TraversingIndexTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/query/index/TraversingIndexTest.java
Wed Nov 14 10:04:55 2012
@@ -74,8 +74,8 @@ public class TraversingIndexTest {
         f.setPath("/");
         List<String> paths = new ArrayList<String>();
         Cursor c = t.query(f, new KernelNodeState(mk, "/", head, cache));
-        while (c.next()) {
-            paths.add(c.currentRow().getPath());
+        while (c.hasNext()) {
+            paths.add(c.next().getPath());
         }
         Collections.sort(paths);
         assertEquals(Arrays.asList(
@@ -83,15 +83,15 @@ public class TraversingIndexTest {
                 "/children/c3", "/children/c4", "/parents",
                 "/parents/p0", "/parents/p1",  "/parents/p2"),
                 paths);
-        assertFalse(c.next());
+        assertFalse(c.hasNext());
         // endure it stays false
-        assertFalse(c.next());
+        assertFalse(c.hasNext());
 
         f.setPath("/nowhere");
         c = t.query(f, new KernelNodeState(mk, "/", head, cache));
-        assertFalse(c.next());
+        assertFalse(c.hasNext());
         // endure it stays false
-        assertFalse(c.next());
+        assertFalse(c.hasNext());
     }
 
 }

Modified: jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexTest.java?rev=1409134&r1=1409133&r2=1409134&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexTest.java
(original)
+++ jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexTest.java
Wed Nov 14 10:04:55 2012
@@ -63,9 +63,9 @@ public class LuceneIndexTest implements 
         filter.restrictProperty("foo", Operator.EQUAL,
                 PropertyValues.newString("bar"));
         Cursor cursor = queryIndex.query(filter, builder.getNodeState());
-        assertTrue(cursor.next());
-        assertEquals("/", cursor.currentRow().getPath());
-        assertFalse(cursor.next());
+        assertTrue(cursor.hasNext());
+        assertEquals("/", cursor.next().getPath());
+        assertFalse(cursor.hasNext());
     }
 
 }



Mime
View raw message