Return-Path: X-Original-To: apmail-directory-commits-archive@www.apache.org Delivered-To: apmail-directory-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id A60ED96E8 for ; Fri, 30 Mar 2012 19:44:55 +0000 (UTC) Received: (qmail 67648 invoked by uid 500); 30 Mar 2012 19:44:55 -0000 Delivered-To: apmail-directory-commits-archive@directory.apache.org Received: (qmail 67613 invoked by uid 500); 30 Mar 2012 19:44:55 -0000 Mailing-List: contact commits-help@directory.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@directory.apache.org Delivered-To: mailing list commits@directory.apache.org Received: (qmail 67602 invoked by uid 99); 30 Mar 2012 19:44:55 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 30 Mar 2012 19:44:55 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 30 Mar 2012 19:44:44 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 72FA5238897A for ; Fri, 30 Mar 2012 19:44:22 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1307585 - in /directory: apacheds/branches/index-work/jdbm-partition/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/ apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/core/parti... Date: Fri, 30 Mar 2012 19:44:22 -0000 To: commits@directory.apache.org From: elecharny@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20120330194422.72FA5238897A@eris.apache.org> Author: elecharny Date: Fri Mar 30 19:44:21 2012 New Revision: 1307585 URL: http://svn.apache.org/viewvc?rev=1307585&view=rev Log: o Used the RdnIndex instead of the OneLevelIndex for the List( ID ) method o Made the IndexCursorAdaptor class extends the AbstarctIndexCursor, removing some of its duplicated methods o Removed the useless TupleCursor o Fixed the ParentIdAndRdn compareTo() method o Added a ChildrenCursor to be able to browse the RdnIdx to find all the children of an entry o Fixed some tests, improving the checks Added: directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/ChildrenCursor.java Removed: directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/cursor/TupleCursor.java Modified: directory/apacheds/branches/index-work/jdbm-partition/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmStoreTest.java directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/AbstractBTreePartition.java directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/IndexCursorAdaptor.java directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/ParentIdAndRdn.java directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/DefaultSearchEngine.java directory/apacheds/branches/index-work/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/impl/avl/AvlPartitionTest.java directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/cursor/AbstractCursor.java Modified: directory/apacheds/branches/index-work/jdbm-partition/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmStoreTest.java URL: http://svn.apache.org/viewvc/directory/apacheds/branches/index-work/jdbm-partition/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmStoreTest.java?rev=1307585&r1=1307584&r2=1307585&view=diff ============================================================================== --- directory/apacheds/branches/index-work/jdbm-partition/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmStoreTest.java (original) +++ directory/apacheds/branches/index-work/jdbm-partition/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmStoreTest.java Fri Mar 30 19:44:21 2012 @@ -515,8 +515,13 @@ public class JdbmStoreTest assertNotNull( cursor ); cursor.beforeFirst(); assertTrue( cursor.next() ); - assertEquals( 2L, ( long ) cursor.get().getId() ); + assertEquals( 3L, ( long ) cursor.get().getId() ); + assertTrue( cursor.next() ); + assertEquals( 4L, ( long ) cursor.get().getId() ); assertTrue( cursor.next() ); + assertEquals( 2L, ( long ) cursor.get().getId() ); + assertFalse( cursor.next() ); + assertEquals( 3, store.getChildCount( 1L ) ); store.delete( 2L ); Modified: directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/AbstractBTreePartition.java URL: http://svn.apache.org/viewvc/directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/AbstractBTreePartition.java?rev=1307585&r1=1307584&r2=1307585&view=diff ============================================================================== --- directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/AbstractBTreePartition.java (original) +++ directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/AbstractBTreePartition.java Fri Mar 30 19:44:21 2012 @@ -63,6 +63,8 @@ import org.apache.directory.server.xdbm. import org.apache.directory.server.xdbm.Store; import org.apache.directory.server.xdbm.search.Optimizer; import org.apache.directory.server.xdbm.search.SearchEngine; +import org.apache.directory.server.xdbm.search.impl.ChildrenCursor; +import org.apache.directory.server.xdbm.search.impl.OneLevelScopeCursor; import org.apache.directory.shared.ldap.model.constants.SchemaConstants; import org.apache.directory.shared.ldap.model.cursor.Cursor; import org.apache.directory.shared.ldap.model.entry.Attribute; @@ -536,6 +538,15 @@ public abstract class AbstractBTreeParti } + + /* + private void dumpAllRdnIdx() throws Exception + { + dumpRdnIdx( getRootId(), "" ); + System.out.println( "-----------------------------" ); + } + */ + private void dumpRdnIdx() throws Exception { @@ -547,6 +558,27 @@ public abstract class AbstractBTreeParti } + /* + private void dumpRdnIdx( ID id, String tabs ) throws Exception + { + // Start with the root + IndexCursor,Entry,ID> cursor = rdnIdx.forwardCursor(); + + IndexEntry, ID> startingPos = new ForwardIndexEntry, ID>(); + startingPos.setValue( new ParentIdAndRdn( id, (Rdn[]) null ) ); + cursor.before( startingPos ); + + while ( cursor.next() ) + { + IndexEntry, ID> entry = cursor.get(); + System.out.println( tabs + entry ); + } + + cursor.close(); + } + */ + + private void dumpRdnIdx( ID id, int nbSibbling, String tabs ) throws Exception { // Start with the root @@ -560,7 +592,7 @@ public abstract class AbstractBTreeParti while ( cursor.next() && ( countChildren < nbSibbling ) ) { IndexEntry, ID> entry = cursor.get(); - System.out.println( tabs + entry.getValue() ); + System.out.println( tabs + entry ); countChildren++; // And now, the children @@ -910,12 +942,20 @@ public abstract class AbstractBTreeParti { try { + // Fetch the entry + ParentIdAndRdn parent = rdnIdx.reverseLookup( id ); + // We use the OneLevel index to get all the entries from a starting point - // and below - IndexCursor cursor = oneLevelIdx.forwardCursor( id ); - cursor.beforeValue( id, null ); + // and below up to the number of children + IndexCursor,Entry, ID> cursor = rdnIdx.forwardCursor(); + + IndexEntry, ID> startingPos = new ForwardIndexEntry, ID>(); + startingPos.setValue( new ParentIdAndRdn( id, (Rdn[]) null ) ); + cursor.before( startingPos ); + + dumpRdnIdx(); - return cursor; + return new ChildrenCursor( this, id, cursor ); } catch ( Exception e ) { Modified: directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/IndexCursorAdaptor.java URL: http://svn.apache.org/viewvc/directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/IndexCursorAdaptor.java?rev=1307585&r1=1307584&r2=1307585&view=diff ============================================================================== --- directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/IndexCursorAdaptor.java (original) +++ directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/IndexCursorAdaptor.java Fri Mar 30 19:44:21 2012 @@ -22,6 +22,7 @@ package org.apache.directory.server.core import java.util.Iterator; +import org.apache.directory.server.xdbm.AbstractIndexCursor; import org.apache.directory.server.xdbm.ForwardIndexEntry; import org.apache.directory.server.xdbm.IndexCursor; import org.apache.directory.server.xdbm.IndexEntry; @@ -31,7 +32,6 @@ import org.apache.directory.shared.ldap. import org.apache.directory.shared.ldap.model.cursor.Cursor; import org.apache.directory.shared.ldap.model.cursor.CursorIterator; import org.apache.directory.shared.ldap.model.cursor.Tuple; -import org.apache.directory.shared.ldap.model.cursor.TupleCursor; /** @@ -40,7 +40,7 @@ import org.apache.directory.shared.ldap. * * @author Apache Directory Project */ -public class IndexCursorAdaptor implements IndexCursor +public class IndexCursorAdaptor extends AbstractIndexCursor { @SuppressWarnings("unchecked") final Cursor wrappedCursor; @@ -80,26 +80,6 @@ public class IndexCursorAdaptor element ) throws Exception { wrappedCursor.before( element.getTuple() ); @@ -234,4 +214,12 @@ public class IndexCursorAdaptorApache Directory Project + */ +public class ChildrenCursor> extends AbstractIndexCursor +{ + /** Error message for unsupported operations */ + private static final String UNSUPPORTED_MSG = I18n.err( I18n.ERR_719 ); + + /** A Cursor over the entries in the scope of the search base */ + private final IndexCursor,Entry, ID> cursor; + + /** The entry database/store */ + private final Store db; + + /** The current position in the cursor */ + private int currentChild; + + /** The max number of childen */ + private int maxChildren; + + /** + * Creates a Cursor over entries satisfying one level scope criteria. + * + * @param db the entry store + * @param evaluator an IndexEntry (candidate) evaluator + * @throws Exception on db access failures + */ + //@SuppressWarnings("unchecked") + public ChildrenCursor( Store db, ID id, IndexCursor,Entry, ID> cursor ) + throws Exception + { + this.db = db; + ParentIdAndRdn parent = db.getRdnIndex().reverseLookup( id ); + currentChild = 0; + + if ( parent == null ) + { + maxChildren = 0; + } + else + { + maxChildren = parent.getNbChildren(); + } + + this.cursor = cursor; + } + + + /** + * {@inheritDoc} + */ + protected String getUnsupportedMessage() + { + return UNSUPPORTED_MSG; + } + + + public void beforeFirst() throws Exception + { + checkNotClosed( "beforeFirst()" ); + setAvailable( false ); + } + + + public void afterLast() throws Exception + { + throw new UnsupportedOperationException( getUnsupportedMessage() ); + } + + + public boolean first() throws Exception + { + beforeFirst(); + currentChild = -1; + + return next(); + } + + + public boolean last() throws Exception + { + throw new UnsupportedOperationException( getUnsupportedMessage() ); + } + + + public boolean previous() throws Exception + { + throw new UnsupportedOperationException( getUnsupportedMessage() ); + } + + + public boolean next() throws Exception + { + checkNotClosed( "next()" ); + + if ( currentChild < maxChildren ) + { + currentChild++; + + return cursor.next(); + } + else + { + return false; + } + } + + public IndexEntry get() throws Exception + { + checkNotClosed( "get()" ); + + IndexEntry entry = cursor.get(); + + return entry; + } + + + @Override + public void close() throws Exception + { + cursor.close(); + + super.close(); + } + + + @Override + public void close( Exception cause ) throws Exception + { + cursor.close( cause ); + + super.close( cause ); + } +} \ No newline at end of file Modified: directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/DefaultSearchEngine.java URL: http://svn.apache.org/viewvc/directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/DefaultSearchEngine.java?rev=1307585&r1=1307584&r2=1307585&view=diff ============================================================================== --- directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/DefaultSearchEngine.java (original) +++ directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/DefaultSearchEngine.java Fri Mar 30 19:44:21 2012 @@ -54,6 +54,7 @@ public class DefaultSearchEngine db; /** creates Cursors over entries satisfying filter expressions */ Modified: directory/apacheds/branches/index-work/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/impl/avl/AvlPartitionTest.java URL: http://svn.apache.org/viewvc/directory/apacheds/branches/index-work/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/impl/avl/AvlPartitionTest.java?rev=1307585&r1=1307584&r2=1307585&view=diff ============================================================================== --- directory/apacheds/branches/index-work/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/impl/avl/AvlPartitionTest.java (original) +++ directory/apacheds/branches/index-work/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/impl/avl/AvlPartitionTest.java Fri Mar 30 19:44:21 2012 @@ -414,12 +414,15 @@ public class AvlPartitionTest { assertEquals( 3, partition.getChildCount( 1L ) ); - Cursor> cursor = partition.list( 1L ); + Cursor> cursor = partition.list( 2L ); assertNotNull( cursor ); cursor.beforeFirst(); assertTrue( cursor.next() ); - assertEquals( 2L, ( long ) cursor.get().getId() ); + assertEquals( 6L, ( long ) cursor.get().getId() ); assertTrue( cursor.next() ); + assertEquals( 5L, ( long ) cursor.get().getId() ); + assertFalse( cursor.next() ); + assertEquals( 3, partition.getChildCount( 1L ) ); partition.delete( 2L ); Modified: directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/cursor/AbstractCursor.java URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/cursor/AbstractCursor.java?rev=1307585&r1=1307584&r2=1307585&view=diff ============================================================================== --- directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/cursor/AbstractCursor.java (original) +++ directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/cursor/AbstractCursor.java Fri Mar 30 19:44:21 2012 @@ -39,7 +39,7 @@ public abstract class AbstractCursor /** * {@inheritDoc} */ - public final void setClosureMonitor( ClosureMonitor monitor ) + public void setClosureMonitor( ClosureMonitor monitor ) { if ( monitor == null ) { @@ -65,7 +65,7 @@ public abstract class AbstractCursor /** * {@inheritDoc} */ - public final boolean isClosed() + public boolean isClosed() throws Exception { return monitor.isClosed(); }