You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2012/03/30 22:45:26 UTC
svn commit: r1307602 -
/directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/ChildrenCursor.java
Author: elecharny
Date: Fri Mar 30 20:45:25 2012
New Revision: 1307602
URL: http://svn.apache.org/viewvc?rev=1307602&view=rev
Log:
Used a better solution to fetch the children from the RdnIndex than simply counting the children we already have fetched. We can also now browse the index forward and backward.
Modified:
directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/ChildrenCursor.java
Modified: directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/ChildrenCursor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/ChildrenCursor.java?rev=1307602&r1=1307601&r2=1307602&view=diff
==============================================================================
--- directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/ChildrenCursor.java (original)
+++ directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/ChildrenCursor.java Fri Mar 30 20:45:25 2012
@@ -49,11 +49,11 @@ public class ChildrenCursor<ID extends C
/** The entry database/store */
private final Store<Entry, ID> db;
- /** The current position in the cursor */
- private int currentChild;
+ /** The Parent ID */
+ private ID parentId;
- /** The max number of childen */
- private int maxChildren;
+ /** The prefetched element */
+ private IndexEntry prefetched;
/**
* Creates a Cursor over entries satisfying one level scope criteria.
@@ -62,23 +62,11 @@ public class ChildrenCursor<ID extends C
* @param evaluator an IndexEntry (candidate) evaluator
* @throws Exception on db access failures
*/
- //@SuppressWarnings("unchecked")
- public ChildrenCursor( Store<Entry, ID> db, ID id, IndexCursor<ParentIdAndRdn<ID>,Entry, ID> cursor )
+ public ChildrenCursor( Store<Entry, ID> db, ID parentId, IndexCursor<ParentIdAndRdn<ID>,Entry, ID> cursor )
throws Exception
{
this.db = db;
- ParentIdAndRdn<ID> parent = db.getRdnIndex().reverseLookup( id );
- currentChild = 0;
-
- if ( parent == null )
- {
- maxChildren = 0;
- }
- else
- {
- maxChildren = parent.getNbChildren();
- }
-
+ this.parentId = parentId;
this.cursor = cursor;
}
@@ -108,7 +96,6 @@ public class ChildrenCursor<ID extends C
public boolean first() throws Exception
{
beforeFirst();
- currentChild = -1;
return next();
}
@@ -122,33 +109,54 @@ public class ChildrenCursor<ID extends C
public boolean previous() throws Exception
{
- throw new UnsupportedOperationException( getUnsupportedMessage() );
+ checkNotClosed( "next()" );
+
+ boolean hasPrevious = cursor.previous();
+
+ if ( hasPrevious )
+ {
+ IndexEntry entry = cursor.get();
+
+ if ( ((ParentIdAndRdn<ID>)entry.getTuple().getKey()).getParentId().equals( parentId ) )
+ {
+ prefetched = entry;
+ return true;
+ }
+ }
+
+ return false;
}
+ /**
+ * {@inheritDoc}
+ */
public boolean next() throws Exception
{
checkNotClosed( "next()" );
- if ( currentChild < maxChildren )
- {
- currentChild++;
-
- return cursor.next();
- }
- else
+ boolean hasNext = cursor.next();
+
+ if ( hasNext )
{
- return false;
+ IndexEntry entry = cursor.get();
+
+ if ( ((ParentIdAndRdn<ID>)entry.getTuple().getKey()).getParentId().equals( parentId ) )
+ {
+ prefetched = entry;
+ return true;
+ }
}
+
+ return false;
}
+
public IndexEntry<ID, ID> get() throws Exception
{
checkNotClosed( "get()" );
- IndexEntry entry = cursor.get();
-
- return entry;
+ return prefetched;
}