From commits-return-33970-apmail-directory-commits-archive=directory.apache.org@directory.apache.org Thu Apr 26 10:22:54 2012 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 64EC89CA2 for ; Thu, 26 Apr 2012 10:22:54 +0000 (UTC) Received: (qmail 53567 invoked by uid 500); 26 Apr 2012 10:22:54 -0000 Delivered-To: apmail-directory-commits-archive@directory.apache.org Received: (qmail 53517 invoked by uid 500); 26 Apr 2012 10:22:54 -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 53510 invoked by uid 99); 26 Apr 2012 10:22:54 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 26 Apr 2012 10:22:54 +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; Thu, 26 Apr 2012 10:22:41 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 003BD23888CD for ; Thu, 26 Apr 2012 10:22:19 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1330754 [1/3] - in /directory/apacheds/branches/index-work: core-constants/src/main/java/org/apache/directory/server/constants/ jdbm-partition/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/ ldif-partition/src/mai... Date: Thu, 26 Apr 2012 10:22:15 -0000 To: commits@directory.apache.org From: elecharny@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20120426102219.003BD23888CD@eris.apache.org> Author: elecharny Date: Thu Apr 26 10:22:13 2012 New Revision: 1330754 URL: http://svn.apache.org/viewvc?rev=1330754&view=rev Log: o Removed the SublevelIndex, replaced by the RdnIndex o Added a DescendantCursor to browse the RdnIndex for SUBTREE searches o Changed the IndexEntry interface to reflect the nature of the stored elements : namely, a key and an ID. The getValue/setValue have been renamed getKey/setKey Added: directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/DescendantCursor.java Modified: directory/apacheds/branches/index-work/core-constants/src/main/java/org/apache/directory/server/constants/ApacheSchemaConstants.java directory/apacheds/branches/index-work/jdbm-partition/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmIndexTest.java directory/apacheds/branches/index-work/jdbm-partition/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmRdnIndexTest.java directory/apacheds/branches/index-work/ldif-partition/src/main/java/org/apache/directory/server/core/partition/ldif/LdifPartition.java directory/apacheds/branches/index-work/ldif-partition/src/main/java/org/apache/directory/server/core/partition/ldif/SingleFileLdifPartition.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/IndexEnumeration.java directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/AbstractIndexEntry.java directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/ForwardIndexEntry.java directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/IndexEntry.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/ReverseIndexEntry.java directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/Store.java directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/AllEntriesCursor.java directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/ChildrenCursor.java directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/DefaultOptimizer.java directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/GreaterEqCursor.java directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/GreaterEqEvaluator.java directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/LessEqCursor.java directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/LessEqEvaluator.java directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/OneLevelScopeCursor.java directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/PresenceCursor.java directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/SubstringCursor.java directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/SubstringEvaluator.java directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/SubtreeScopeCursor.java directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/SubtreeScopeEvaluator.java directory/apacheds/branches/index-work/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/ForwardIndexEntryTest.java directory/apacheds/branches/index-work/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/PartitionTest.java directory/apacheds/branches/index-work/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/ReverseIndexEntryTest.java directory/apacheds/branches/index-work/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/SingletonIndexCursorTest.java directory/apacheds/branches/index-work/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/impl/avl/AvlPartitionTest.java directory/apacheds/branches/index-work/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/impl/avl/AvlRdnIndexTest.java directory/apacheds/branches/index-work/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/search/impl/AndCursorTest.java directory/apacheds/branches/index-work/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/search/impl/GreaterEqTest.java directory/apacheds/branches/index-work/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/search/impl/LessEqTest.java directory/apacheds/branches/index-work/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/search/impl/NestedFilterTest.java directory/apacheds/branches/index-work/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/search/impl/NotCursorTest.java directory/apacheds/branches/index-work/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/search/impl/OneLevelScopeTest.java directory/apacheds/branches/index-work/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/search/impl/OrCursorTest.java directory/apacheds/branches/index-work/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/search/impl/PresenceTest.java directory/apacheds/branches/index-work/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/search/impl/SubstringTest.java directory/apacheds/branches/index-work/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/search/impl/SubtreeScopeTest.java directory/apacheds/branches/index-work/xdbm-tools/src/main/java/org/apache/directory/server/core/partition/impl/btree/gui/IndexDialog.java directory/apacheds/branches/index-work/xdbm-tools/src/main/java/org/apache/directory/server/xdbm/tools/IndexDialog.java Modified: directory/apacheds/branches/index-work/core-constants/src/main/java/org/apache/directory/server/constants/ApacheSchemaConstants.java URL: http://svn.apache.org/viewvc/directory/apacheds/branches/index-work/core-constants/src/main/java/org/apache/directory/server/constants/ApacheSchemaConstants.java?rev=1330754&r1=1330753&r2=1330754&view=diff ============================================================================== --- directory/apacheds/branches/index-work/core-constants/src/main/java/org/apache/directory/server/constants/ApacheSchemaConstants.java (original) +++ directory/apacheds/branches/index-work/core-constants/src/main/java/org/apache/directory/server/constants/ApacheSchemaConstants.java Thu Apr 26 10:22:13 2012 @@ -145,10 +145,6 @@ public final class ApacheSchemaConstants public final static String SUBSCHEMA_SUBENTRY_NAME_AT = "subschemaSubentryName"; public final static String SUBSCHEMA_SUBENTRY_NAME_AT_OID = "1.3.6.1.4.1.18060.0.4.1.2.37"; - // apacheSubLevel - public final static String APACHE_SUB_LEVEL_AT = "apacheSubLevel"; - public final static String APACHE_SUB_LEVEL_AT_OID = "1.3.6.1.4.1.18060.0.4.1.2.43"; - // apacheRdn public final static String APACHE_RDN_AT = "apacheRdn"; public final static String APACHE_RDN_AT_OID = "1.3.6.1.4.1.18060.0.4.1.2.50"; Modified: directory/apacheds/branches/index-work/jdbm-partition/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmIndexTest.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/JdbmIndexTest.java?rev=1330754&r1=1330753&r2=1330754&view=diff ============================================================================== --- directory/apacheds/branches/index-work/jdbm-partition/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmIndexTest.java (original) +++ directory/apacheds/branches/index-work/jdbm-partition/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmIndexTest.java Thu Apr 26 10:22:13 2012 @@ -532,17 +532,17 @@ public class JdbmIndexTest cursor.next(); IndexEntry e1 = cursor.get(); assertEquals( 555L, ( long ) e1.getId() ); - assertEquals( "bar", e1.getValue() ); + assertEquals( "bar", e1.getKey() ); cursor.next(); IndexEntry e2 = cursor.get(); assertEquals( 333L, ( long ) e2.getId() ); - assertEquals( "foo", e2.getValue() ); + assertEquals( "foo", e2.getKey() ); cursor.next(); IndexEntry e3 = cursor.get(); assertEquals( 1234L, ( long ) e3.getId() ); - assertEquals( "foo", e3.getValue() ); + assertEquals( "foo", e3.getKey() ); cursor.close(); @@ -553,17 +553,17 @@ public class JdbmIndexTest cursor.next(); e1 = cursor.get(); assertEquals( 333L, ( long ) e1.getId() ); - assertEquals( "foo", e1.getValue() ); + assertEquals( "foo", e1.getKey() ); cursor.next(); e2 = cursor.get(); assertEquals( 555L, ( long ) e2.getId() ); - assertEquals( "bar", e2.getValue() ); + assertEquals( "bar", e2.getKey() ); cursor.next(); e3 = cursor.get(); assertEquals( 1234L, ( long ) e3.getId() ); - assertEquals( "foo", e3.getValue() ); + assertEquals( "foo", e3.getKey() ); cursor.close(); } Modified: directory/apacheds/branches/index-work/jdbm-partition/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmRdnIndexTest.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/JdbmRdnIndexTest.java?rev=1330754&r1=1330753&r2=1330754&view=diff ============================================================================== --- directory/apacheds/branches/index-work/jdbm-partition/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmRdnIndexTest.java (original) +++ directory/apacheds/branches/index-work/jdbm-partition/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmRdnIndexTest.java Thu Apr 26 10:22:13 2012 @@ -353,20 +353,20 @@ public class JdbmRdnIndexTest cursor.next(); IndexEntry, Long> e1 = cursor.get(); assertEquals( 0, ( long ) e1.getId() ); - assertEquals( "cn=key", e1.getValue().getRdns()[0].getName() ); - assertEquals( 0, e1.getValue().getParentId().longValue() ); + assertEquals( "cn=key", e1.getKey().getRdns()[0].getName() ); + assertEquals( 0, e1.getKey().getParentId().longValue() ); cursor.next(); IndexEntry, Long> e2 = cursor.get(); assertEquals( 1, ( long ) e2.getId() ); - assertEquals( "cn=key1", e2.getValue().getRdns()[0].getName() ); - assertEquals( 1, e2.getValue().getParentId().longValue() ); + assertEquals( "cn=key1", e2.getKey().getRdns()[0].getName() ); + assertEquals( 1, e2.getKey().getParentId().longValue() ); cursor.next(); IndexEntry, Long> e3 = cursor.get(); assertEquals( 2, ( long ) e3.getId() ); - assertEquals( "cn=key2", e3.getValue().getRdns()[0].getName() ); - assertEquals( 2, e3.getValue().getParentId().longValue() ); + assertEquals( "cn=key2", e3.getKey().getRdns()[0].getName() ); + assertEquals( 2, e3.getKey().getParentId().longValue() ); cursor.close(); } Modified: directory/apacheds/branches/index-work/ldif-partition/src/main/java/org/apache/directory/server/core/partition/ldif/LdifPartition.java URL: http://svn.apache.org/viewvc/directory/apacheds/branches/index-work/ldif-partition/src/main/java/org/apache/directory/server/core/partition/ldif/LdifPartition.java?rev=1330754&r1=1330753&r2=1330754&view=diff ============================================================================== --- directory/apacheds/branches/index-work/ldif-partition/src/main/java/org/apache/directory/server/core/partition/ldif/LdifPartition.java (original) +++ directory/apacheds/branches/index-work/ldif-partition/src/main/java/org/apache/directory/server/core/partition/ldif/LdifPartition.java Thu Apr 26 10:22:13 2012 @@ -34,14 +34,19 @@ import org.apache.directory.server.core. import org.apache.directory.server.core.api.interceptor.context.MoveOperationContext; import org.apache.directory.server.core.api.interceptor.context.RenameOperationContext; import org.apache.directory.server.i18n.I18n; +import org.apache.directory.server.xdbm.ForwardIndexEntry; import org.apache.directory.server.xdbm.IndexCursor; import org.apache.directory.server.xdbm.IndexEntry; +import org.apache.directory.server.xdbm.ParentIdAndRdn; +import org.apache.directory.server.xdbm.SingletonIndexCursor; +import org.apache.directory.server.xdbm.search.impl.DescendantCursor; import org.apache.directory.shared.ldap.model.constants.SchemaConstants; import org.apache.directory.shared.ldap.model.entry.DefaultEntry; import org.apache.directory.shared.ldap.model.entry.Entry; import org.apache.directory.shared.ldap.model.entry.Modification; import org.apache.directory.shared.ldap.model.exception.LdapException; import org.apache.directory.shared.ldap.model.exception.LdapInvalidDnException; +import org.apache.directory.shared.ldap.model.exception.LdapOperationErrorException; import org.apache.directory.shared.ldap.model.exception.LdapOperationException; import org.apache.directory.shared.ldap.model.ldif.LdifEntry; import org.apache.directory.shared.ldap.model.ldif.LdifReader; @@ -299,7 +304,14 @@ public class LdifPartition extends Abstr // Get the modified entry Entry modifiedEntry = lookup( id ); - entryMoved( oldDn, modifiedEntry, id ); + try + { + entryMoved( oldDn, modifiedEntry, id ); + } + catch ( Exception e ) + { + throw new LdapOperationErrorException( e.getMessage(), e ); + } } @@ -317,7 +329,14 @@ public class LdifPartition extends Abstr Entry modifiedEntry = lookup( id ); moveAndRenameContext.setModifiedEntry( modifiedEntry ); - entryMoved( oldDn, modifiedEntry, id ); + try + { + entryMoved( oldDn, modifiedEntry, id ); + } + catch ( Exception e ) + { + throw new LdapOperationErrorException( e.getMessage(), e ); + } } @@ -338,7 +357,14 @@ public class LdifPartition extends Abstr // Now move the potential children for the old entry // and remove the old entry - entryMoved( oldDn, modifiedEntry, id ); + try + { + entryMoved( oldDn, modifiedEntry, id ); + } + catch ( Exception e ) + { + throw new LdapOperationErrorException( e.getMessage(), e ); + } } @@ -352,19 +378,31 @@ public class LdifPartition extends Abstr * @param deleteOldEntry a flag to tell whether to delete the old entry files * @throws Exception */ - private void entryMoved( Dn oldEntryDn, Entry modifiedEntry, Long entryIdOld ) throws LdapException + private void entryMoved( Dn oldEntryDn, Entry modifiedEntry, Long entryIdOld ) throws Exception { // First, add the new entry addEntry( modifiedEntry ); + + Long baseId = getEntryId( modifiedEntry.getDn() ); + + + ParentIdAndRdn parentIdAndRdn = getRdnIndex().reverseLookup( baseId ); + IndexEntry indexEntry = new ForwardIndexEntry(); + + indexEntry.setId(baseId); + indexEntry.setKey( parentIdAndRdn ); + + IndexCursor,Entry, Long> cursor = new SingletonIndexCursor, Long>( indexEntry ); + Long parentId = parentIdAndRdn.getParentId(); + + IndexCursor scopeCursor = new DescendantCursor( this, baseId, parentId, cursor ); // Then, if there are some children, move then to the new place try { - IndexCursor cursor = getSubLevelIndex().forwardCursor( entryIdOld ); - - while ( cursor.next() ) + while ( scopeCursor.next() ) { - IndexEntry entry = cursor.get(); + IndexEntry entry = scopeCursor.get(); // except the parent entry add the rest of entries if ( entry.getId() != entryIdOld ) @@ -373,13 +411,13 @@ public class LdifPartition extends Abstr } } - cursor.close(); + scopeCursor.close(); } catch ( Exception e ) { throw new LdapOperationException( e.getMessage(), e ); } - + // And delete the old entry's LDIF file File file = getFile( oldEntryDn, DELETE ); boolean deleted = deleteFile( file ); Modified: directory/apacheds/branches/index-work/ldif-partition/src/main/java/org/apache/directory/server/core/partition/ldif/SingleFileLdifPartition.java URL: http://svn.apache.org/viewvc/directory/apacheds/branches/index-work/ldif-partition/src/main/java/org/apache/directory/server/core/partition/ldif/SingleFileLdifPartition.java?rev=1330754&r1=1330753&r2=1330754&view=diff ============================================================================== --- directory/apacheds/branches/index-work/ldif-partition/src/main/java/org/apache/directory/server/core/partition/ldif/SingleFileLdifPartition.java (original) +++ directory/apacheds/branches/index-work/ldif-partition/src/main/java/org/apache/directory/server/core/partition/ldif/SingleFileLdifPartition.java Thu Apr 26 10:22:13 2012 @@ -331,7 +331,7 @@ public class SingleFileLdifPartition ext IndexCursor,Entry,Long> cursor = rdnIdx.forwardCursor(); IndexEntry, Long> startingPos = new ForwardIndexEntry, Long>(); - startingPos.setValue( new ParentIdAndRdn( id, (Rdn[]) null ) ); + startingPos.setKey( new ParentIdAndRdn( id, (Rdn[]) null ) ); cursor.before( startingPos ); int countChildren = 0; @@ -346,7 +346,7 @@ public class SingleFileLdifPartition ext countChildren++; // And now, the children - int nbChildren = element.getValue().getNbChildren(); + int nbChildren = element.getKey().getNbChildren(); if ( nbChildren > 0 ) { 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=1330754&r1=1330753&r2=1330754&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 Thu Apr 26 10:22:13 2012 @@ -150,9 +150,6 @@ public abstract class AbstractBTreeParti /** a system index on objectClass attribute*/ protected Index objectClassIdx; - /** a system index on the entries of descendants of root Dn */ - protected Index subLevelIdx; - /** the attribute presence index */ protected Index presenceIdx; @@ -180,8 +177,8 @@ public abstract class AbstractBTreeParti private static final boolean NO_REVERSE = Boolean.FALSE; private static final boolean WITH_REVERSE = Boolean.TRUE; - private static final boolean ADD_CHILD = true; - private static final boolean REMOVE_CHILD = false; + protected static final boolean ADD_CHILD = true; + protected static final boolean REMOVE_CHILD = false; // ------------------------------------------------------------------------ // C O N S T R U C T O R S @@ -296,12 +293,6 @@ public abstract class AbstractBTreeParti addIndex( index ); } - if ( getSubLevelIndex() == null ) - { - Index index = createSystemIndex( ApacheSchemaConstants.APACHE_SUB_LEVEL_AT_OID, partitionPath, WITH_REVERSE ); - addIndex( index ); - } - if ( getRdnIndex() == null ) { Index, Entry, ID> index = createSystemIndex( ApacheSchemaConstants.APACHE_RDN_AT_OID, partitionPath, WITH_REVERSE ); @@ -355,7 +346,6 @@ public abstract class AbstractBTreeParti // set index shortcuts rdnIdx = ( Index, Entry, ID> ) systemIndices.get( ApacheSchemaConstants.APACHE_RDN_AT_OID ); presenceIdx = ( Index ) systemIndices.get( ApacheSchemaConstants.APACHE_PRESENCE_AT_OID ); - subLevelIdx = ( Index ) systemIndices.get( ApacheSchemaConstants.APACHE_SUB_LEVEL_AT_OID ); aliasIdx = ( Index ) systemIndices.get( ApacheSchemaConstants.APACHE_ALIAS_AT_OID ); oneAliasIdx = ( Index ) systemIndices.get( ApacheSchemaConstants.APACHE_ONE_ALIAS_AT_OID ); subAliasIdx = ( Index ) systemIndices.get( ApacheSchemaConstants.APACHE_SUB_ALIAS_AT_OID ); @@ -550,13 +540,13 @@ public abstract class AbstractBTreeParti } - private void dumpRdnIdx( ID id, String tabs ) throws Exception + public 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 ) ); + startingPos.setKey( new ParentIdAndRdn( id, (Rdn[]) null ) ); cursor.before( startingPos ); while ( cursor.next() ) @@ -575,7 +565,7 @@ public abstract class AbstractBTreeParti IndexCursor,Entry,ID> cursor = rdnIdx.forwardCursor(); IndexEntry, ID> startingPos = new ForwardIndexEntry, ID>(); - startingPos.setValue( new ParentIdAndRdn( id, (Rdn[]) null ) ); + startingPos.setKey( new ParentIdAndRdn( id, (Rdn[]) null ) ); cursor.before( startingPos ); int countChildren = 0; @@ -586,7 +576,7 @@ public abstract class AbstractBTreeParti countChildren++; // And now, the children - int nbChildren = entry.getValue().getNbChildren(); + int nbChildren = entry.getKey().getNbChildren(); if ( nbChildren > 0 ) { @@ -683,18 +673,6 @@ public abstract class AbstractBTreeParti addAliasIndices( id, entryDn, aliasAttr.getString() ); } - // Update the SubLevel index - ID tempId = parentId; - - while ( ( tempId != null ) && ( !tempId.equals( getRootId() ) ) && ( !tempId.equals( getSuffixId() ) ) ) - { - subLevelIdx.add( tempId, id ); - tempId = getParentId( tempId ); - } - - // making entry an ancestor/descendent of itself in sublevel index - subLevelIdx.add( id, id ); - // Update the EntryCsn index Attribute entryCsn = entry.get( ENTRY_CSN_AT ); @@ -794,7 +772,7 @@ public abstract class AbstractBTreeParti } - private void updateRdnIdx( ID parentId, boolean addRemove, int nbDescendant ) throws Exception + protected void updateRdnIdx( ID parentId, boolean addRemove, int nbDescendant ) throws Exception { boolean isFirst = true; @@ -831,6 +809,8 @@ public abstract class AbstractBTreeParti } // Inject the modified element into the index + // we first need to drop it so that the key can be replaced + rdnIdx.drop( parentId ); rdnIdx.add( parent, parentId ); parentId = parent.getParentId(); @@ -879,7 +859,6 @@ public abstract class AbstractBTreeParti dumpRdnIdx(); - subLevelIdx.drop( id ); entryCsnIdx.drop( entry.get( ENTRY_CSN_AT ).getString(), id ); entryUuidIdx.drop( entry.get( ENTRY_UUID_AT ).getString(), id ); @@ -950,7 +929,7 @@ public abstract class AbstractBTreeParti IndexCursor,Entry, ID> cursor = rdnIdx.forwardCursor(); IndexEntry, ID> startingPos = new ForwardIndexEntry, ID>(); - startingPos.setValue( new ParentIdAndRdn( id, (Rdn[]) null ) ); + startingPos.setKey( new ParentIdAndRdn( id, (Rdn[]) null ) ); cursor.before( startingPos ); dumpRdnIdx(); @@ -1526,12 +1505,6 @@ public abstract class AbstractBTreeParti */ dropMovedAliasIndices( oldDn ); - /* - * Drop the old parent child relationship and add the new one - * Set the new parent id for the child replacing the old parent id - */ - updateSubLevelIndex( entryId, oldParentId, newParentId ); - // Update the Rdn index // First drop the old entry ParentIdAndRdn movedEntry = rdnIdx.reverseLookup( entryId ); @@ -1711,12 +1684,6 @@ public abstract class AbstractBTreeParti dropMovedAliasIndices( oldDn ); /* - * Drop the old parent child relationship and add the new one - * Set the new parent id for the child replacing the old parent id - */ - updateSubLevelIndex( entryId, oldParentId, newParentId ); - - /* * Update the Rdn index */ // First drop the old entry @@ -1910,9 +1877,18 @@ public abstract class AbstractBTreeParti * No need to calculate the new Dn. */ ID parentId = getParentId( oldId ); + + // Get the old parentIdAndRdn to get the nb of children and descendant + ParentIdAndRdn parentIdAndRdn = rdnIdx.reverseLookup( oldId ); + + // Now we can drop it rdnIdx.drop( oldId ); - ParentIdAndRdn key = new ParentIdAndRdn( parentId, newRdn ); - rdnIdx.add( key, oldId ); + + // Update the descendants + parentIdAndRdn.setParentId( parentId ); + parentIdAndRdn.setRdns( newRdn ); + + rdnIdx.add( parentIdAndRdn, oldId ); if ( isSyncOnWrite.get() ) { @@ -1973,69 +1949,6 @@ public abstract class AbstractBTreeParti } - /** - * Updates the SubLevel Index as part of a move operation. - * - * @param entryId child id to be moved - * @param oldParentId old parent's id - * @param newParentId new parent's id - * @throws Exception - */ - private void updateSubLevelIndex( ID entryId, ID oldParentId, ID newParentId ) throws Exception - { - ID tempId = oldParentId; - List parentIds = new ArrayList(); - - // find all the parents of the oldParentId - while ( ( tempId != null ) && !tempId.equals( getRootId() ) && !tempId.equals( getSuffixId() ) ) - { - parentIds.add( tempId ); - tempId = getParentId( tempId ); - } - - // find all the children of the childId - Cursor> cursor = subLevelIdx.forwardCursor( entryId ); - - List childIds = new ArrayList(); - childIds.add( entryId ); - - while ( cursor.next() ) - { - childIds.add( cursor.get().getId() ); - } - - cursor.close(); - - // detach the childId and all its children from oldParentId and all it parents excluding the root - for ( ID pid : parentIds ) - { - for ( ID cid : childIds ) - { - subLevelIdx.drop( pid, cid ); - } - } - - parentIds.clear(); - tempId = newParentId; - - // find all the parents of the newParentId - while ( ( tempId != null ) && !tempId.equals( getRootId() ) && !tempId.equals( getSuffixId() ) ) - { - parentIds.add( tempId ); - tempId = getParentId( tempId ); - } - - // attach the childId and all its children to newParentId and all it parents excluding the root - for ( ID id : parentIds ) - { - for ( ID cid : childIds ) - { - subLevelIdx.add( id, cid ); - } - } - } - - // ------------------------------------------------------------------------ // Index and master table Operations // ------------------------------------------------------------------------ @@ -2343,16 +2256,6 @@ public abstract class AbstractBTreeParti * {@inheritDoc} */ @SuppressWarnings("unchecked") - public Index getSubLevelIndex() - { - return ( Index ) systemIndices.get( ApacheSchemaConstants.APACHE_SUB_LEVEL_AT_OID ); - } - - - /** - * {@inheritDoc} - */ - @SuppressWarnings("unchecked") public Index getAliasIndex() { return ( Index ) systemIndices.get( ApacheSchemaConstants.APACHE_ALIAS_AT_OID ); Modified: directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/IndexEnumeration.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/IndexEnumeration.java?rev=1330754&r1=1330753&r2=1330754&view=diff ============================================================================== --- directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/IndexEnumeration.java (original) +++ directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/IndexEnumeration.java Thu Apr 26 10:22:13 2012 @@ -170,7 +170,7 @@ public class IndexEnumeration impleme // If regex is null just transfer into prefetched from tmp record // but if it is not then use it to match. Successful match shorts // while loop. - if ( null == re || re.matcher( ( String ) tmp.getValue() ).matches() ) + if ( null == re || re.matcher( ( String ) tmp.getKey() ).matches() ) { prefetched.copy( tmp ); return; Modified: directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/AbstractIndexEntry.java URL: http://svn.apache.org/viewvc/directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/AbstractIndexEntry.java?rev=1330754&r1=1330753&r2=1330754&view=diff ============================================================================== --- directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/AbstractIndexEntry.java (original) +++ directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/AbstractIndexEntry.java Thu Apr 26 10:22:13 2012 @@ -28,10 +28,10 @@ import org.apache.directory.shared.ldap. * Abstract class managing the object for index entries. * * @author Apache Directory Project - * @param The value stored in the Tuple, associated key for the object + * @param The key stored in the Tuple, associated key for the object * @param The ID of the object */ -public abstract class AbstractIndexEntry implements IndexEntry +public abstract class AbstractIndexEntry implements IndexEntry { /** The referenced Entry if loaded from the store */ private Entry entry; @@ -51,13 +51,13 @@ public abstract class AbstractIndexEntry /** * {@inheritDoc} */ - public abstract V getValue(); + public abstract K getKey(); /** * {@inheritDoc} */ - public abstract void setValue( V value ); + public abstract void setKey( K value ); /** @@ -108,7 +108,7 @@ public abstract class AbstractIndexEntry /** * {@inheritDoc} */ - public void copy( IndexEntry entry ) + public void copy( IndexEntry entry ) { this.entry = entry.getEntry(); } Modified: directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/ForwardIndexEntry.java URL: http://svn.apache.org/viewvc/directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/ForwardIndexEntry.java?rev=1330754&r1=1330753&r2=1330754&view=diff ============================================================================== --- directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/ForwardIndexEntry.java (original) +++ directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/ForwardIndexEntry.java Thu Apr 26 10:22:13 2012 @@ -29,13 +29,13 @@ import org.apache.directory.shared.ldap. * indexed Entry if one has already been loaded. * * @author Apache Directory Project - * @param The value stored in the Tuple, associated key for the object + * @param The key stored in the Tuple, associated key for the object * @param The ID of the object */ -public class ForwardIndexEntry extends AbstractIndexEntry +public class ForwardIndexEntry extends AbstractIndexEntry { /** The underlying Tuple */ - private final Tuple tuple = new Tuple(); + private final Tuple tuple = new Tuple(); /** @@ -55,7 +55,7 @@ public class ForwardIndexEntry ex * @param tuple the tuple for the ForwardIndexEntry * @param entry the resuscitated Entry if any */ - public void setTuple( Tuple tuple, Entry entry ) + public void setTuple( Tuple tuple, Entry entry ) { setEntry( entry ); this.tuple.setKey( tuple.getKey() ); @@ -75,7 +75,7 @@ public class ForwardIndexEntry ex /** * {@inheritDoc} */ - public V getValue() + public K getKey() { return tuple.getKey(); } @@ -93,7 +93,7 @@ public class ForwardIndexEntry ex /** * {@inheritDoc} */ - public void setValue( V value ) + public void setKey( K value ) { tuple.setKey( value ); } @@ -102,7 +102,7 @@ public class ForwardIndexEntry ex /** * {@inheritDoc} */ - public Tuple getTuple() + public Tuple getTuple() { return tuple; } @@ -122,10 +122,10 @@ public class ForwardIndexEntry ex /** * {@inheritDoc} */ - public void copy( IndexEntry entry ) + public void copy( IndexEntry entry ) { super.copy( entry ); - tuple.setKey( entry.getValue() ); + tuple.setKey( entry.getKey() ); tuple.setValue( entry.getId() ); } Modified: directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/IndexEntry.java URL: http://svn.apache.org/viewvc/directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/IndexEntry.java?rev=1330754&r1=1330753&r2=1330754&view=diff ============================================================================== --- directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/IndexEntry.java (original) +++ directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/IndexEntry.java Thu Apr 26 10:22:13 2012 @@ -26,29 +26,29 @@ import org.apache.directory.shared.ldap. /** * Interface for index entries. An index entry associate an Entry with - * a value (the key) and the Entry ID in the table where it's stored. The Entry + * a key and the Entry ID in the table where it's stored. The Entry * may be present in this instance once we read it from the table. * * @author Apache Directory Project * @param The value stored in the Tuple, associated key for the object * @param The ID of the object */ -public interface IndexEntry +public interface IndexEntry { /** - * Gets the value referred to by this IndexEntry. + * Gets the key referred to by this IndexEntry. * - * @return the value of the Entry referred to + * @return the key of the Entry referred to */ - V getValue(); + K getKey(); /** - * Sets the value referred to by this IndexEntry. + * Sets the key referred to by this IndexEntry. * - * @param value the value of the Entry referred to + * @param key the key of the Entry referred to */ - void setValue( V value ); + void setKey( K key ); /** @@ -102,5 +102,5 @@ public interface IndexEntry * * @param entry the entry to copy fields of */ - void copy( IndexEntry entry ); + void copy( IndexEntry entry ); } Modified: directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/ParentIdAndRdn.java URL: http://svn.apache.org/viewvc/directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/ParentIdAndRdn.java?rev=1330754&r1=1330753&r2=1330754&view=diff ============================================================================== --- directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/ParentIdAndRdn.java (original) +++ directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/ParentIdAndRdn.java Thu Apr 26 10:22:13 2012 @@ -125,7 +125,7 @@ public class ParentIdAndRdnApache Directory Project - * @param The value stored in the Tuple, associated key for the Entry + * @param The key stored in the Tuple, associated key for the Entry * @param The ID of the Entry */ -public class ReverseIndexEntry extends AbstractIndexEntry +public class ReverseIndexEntry extends AbstractIndexEntry { /** The underlying Tuple */ - private final Tuple tuple = new Tuple(); + private final Tuple tuple = new Tuple(); /** @@ -55,7 +55,7 @@ public class ReverseIndexEntry ex * @param tuple the tuple for the ReverseIndexEntry * @param obj the resusitated Entry that is indexed if any */ - public void setTuple( Tuple tuple, Entry entry ) + public void setTuple( Tuple tuple, Entry entry ) { setEntry( entry ); this.tuple.setKey( tuple.getKey() ); @@ -75,7 +75,7 @@ public class ReverseIndexEntry ex /** * {@inheritDoc} */ - public V getValue() + public K getKey() { return tuple.getValue(); } @@ -93,7 +93,7 @@ public class ReverseIndexEntry ex /** * {@inheritDoc} */ - public void setValue( V key ) + public void setKey( K key ) { tuple.setValue( key ); } @@ -122,11 +122,11 @@ public class ReverseIndexEntry ex /** * {@inheritDoc} */ - public void copy( IndexEntry entry ) + public void copy( IndexEntry entry ) { setEntry( entry.getEntry() ); tuple.setKey( entry.getId() ); - tuple.setValue( entry.getValue() ); + tuple.setValue( entry.getKey() ); } Modified: directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/Store.java URL: http://svn.apache.org/viewvc/directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/Store.java?rev=1330754&r1=1330753&r2=1330754&view=diff ============================================================================== --- directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/Store.java (original) +++ directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/Store.java Thu Apr 26 10:22:13 2012 @@ -91,7 +91,6 @@ public interface Store getSubLevelIndex(); - - - /** * @return The Alias system index */ Index getAliasIndex(); Modified: directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/AllEntriesCursor.java URL: http://svn.apache.org/viewvc/directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/AllEntriesCursor.java?rev=1330754&r1=1330753&r2=1330754&view=diff ============================================================================== --- directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/AllEntriesCursor.java (original) +++ directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/AllEntriesCursor.java Thu Apr 26 10:22:13 2012 @@ -165,7 +165,7 @@ public class AllEntriesCursor wrappedEntry = wrapped.get(); indexEntry.setId( wrappedEntry.getId() ); - indexEntry.setValue( wrappedEntry.getId() ); + indexEntry.setKey( wrappedEntry.getId() ); indexEntry.setEntry( wrappedEntry.getEntry() ); return indexEntry; 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=1330754&r1=1330753&r2=1330754&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 Thu Apr 26 10:22:13 2012 @@ -146,9 +146,9 @@ public class ChildrenCursor entry = new ForwardIndexEntry(); entry.setId( (ID)cursorEntry.getId() ); - entry.setValue( ((ParentIdAndRdn)cursorEntry.getTuple().getKey()).getParentId() ); + entry.setKey( ((ParentIdAndRdn)cursorEntry.getTuple().getKey()).getParentId() ); - if ( entry.getValue().equals( parentId ) ) + if ( entry.getKey().equals( parentId ) ) { prefetched = entry; return true; Modified: directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/DefaultOptimizer.java URL: http://svn.apache.org/viewvc/directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/DefaultOptimizer.java?rev=1330754&r1=1330753&r2=1330754&view=diff ============================================================================== --- directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/DefaultOptimizer.java (original) +++ directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/DefaultOptimizer.java Thu Apr 26 10:22:13 2012 @@ -373,6 +373,7 @@ public class DefaultOptimizerApache Directory Project + */ +public class DescendantCursor> extends AbstractIndexCursor +{ + /** A dedicated log for cursors */ + private static final Logger LOG_CURSOR = LoggerFactory.getLogger( "CURSOR" ); + + /** Error message for unsupported operations */ + private static final String UNSUPPORTED_MSG = I18n.err( I18n.ERR_719 ); + + /** The entry database/store */ + private final Store db; + + /** The prefetched element */ + private IndexEntry prefetched; + + /** The current Cursor over the entries in the scope of the search base */ + private IndexCursor,Entry, ID> currentCursor; + + /** The current Parent ID */ + private ID currentParentId; + + /** The stack of cursors used to process the depth-first traversal */ + private ArrayStack cursorStack; + + /** The stack of parentIds used to process the depth-first traversal */ + private ArrayStack parentIdStack; + + /** The initial entry ID we are looking descendants for */ + private ID baseId; + + /** A flag to tell that we are in the top level cursor or not */ + private boolean topLevel; + + protected static final boolean TOP_LEVEL = true; + protected static final boolean INNER = false; + + + /** + * 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 + */ + public DescendantCursor( Store db, ID baseId, ID parentId, IndexCursor, Entry, ID> cursor ) + throws Exception + { + this( db, baseId, parentId, cursor, TOP_LEVEL ); + } + + /** + * 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 + */ + public DescendantCursor( Store db, ID baseId, ID parentId, IndexCursor, Entry, ID> cursor, boolean topLevel ) + throws Exception + { + LOG_CURSOR.debug( "Creating ChildrenCursor {}", this ); + this.db = db; + currentParentId = parentId; + currentCursor = cursor; + cursorStack = new ArrayStack(); + parentIdStack = new ArrayStack(); + this.baseId = baseId; + this.topLevel = topLevel; + } + + + /** + * {@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(); + + return next(); + } + + + public boolean last() throws Exception + { + throw new UnsupportedOperationException( getUnsupportedMessage() ); + } + + + public boolean previous() throws Exception + { + checkNotClosed( "next()" ); + + boolean hasPrevious = currentCursor.previous(); + + if ( hasPrevious ) + { + IndexEntry entry = currentCursor.get(); + + if ( ((ParentIdAndRdn)entry.getTuple().getKey()).getParentId().equals( currentParentId ) ) + { + prefetched = entry; + return true; + } + } + + return false; + } + + + /** + * {@inheritDoc} + */ + public boolean next() throws Exception + { + checkNotClosed( "next()" ); + boolean finished = false; + + while ( !finished ) + { + boolean hasNext = currentCursor.next(); + + // We will use a depth first approach. The alternative (Breadth-first) would be + // too memory consuming. + // The idea is to use a ChildrenCursor each time we have an entry with chidren, + // and process recursively. + if ( hasNext ) + { + IndexEntry cursorEntry = currentCursor.get(); + ParentIdAndRdn parentIdAndRdn = ((ParentIdAndRdn)(cursorEntry.getKey())); + + // Check that we aren't out of the cursor's limit + if ( !parentIdAndRdn.getParentId().equals( currentParentId ) ) + { + // Ok, we went too far. Unstack the cursor and return + finished = cursorStack.size() == 0; + + if ( !finished ) + { + currentCursor.close(); + currentCursor = (IndexCursor, Entry, ID> )cursorStack.pop(); + currentParentId = (ID)parentIdStack.pop(); + } + + // And continue... + } + else + { + // We have a candidate, it will be returned. + if ( topLevel ) + { + prefetched = new ForwardIndexEntry(); + prefetched.setId( (ID)cursorEntry.getId() ); + prefetched.setKey( baseId ); + } + else + { + prefetched = cursorEntry; + } + + // Check if the current entry has children or not. + if ( parentIdAndRdn.getNbDescendants() > 0 ) + { + ID newParentId = (ID)cursorEntry.getId(); + + // Yes, then create a new cursor and go down one level + IndexCursor,Entry, ID> cursor = db.getRdnIndex().forwardCursor(); + + IndexEntry, ID> startingPos = new ForwardIndexEntry, ID>(); + startingPos.setKey( new ParentIdAndRdn( newParentId, (Rdn[]) null ) ); + cursor.before( startingPos ); + + cursorStack.push( currentCursor ); + parentIdStack.push( currentParentId ); + + currentCursor = cursor; + currentParentId = newParentId; + } + + return true; + } + } + else + { + // The current cursor has been exhausted. Get back to the parent's cursor. + finished = cursorStack.size() == 0; + + if ( !finished ) + { + currentCursor.close(); + currentCursor = (IndexCursor, Entry, ID> )cursorStack.pop(); + currentParentId = (ID)parentIdStack.pop(); + } + // and continue... + } + } + + return false; + } + + + public IndexEntry get() throws Exception + { + checkNotClosed( "get()" ); + + return prefetched; + } + + + @Override + public void close() throws Exception + { + LOG_CURSOR.debug( "Closing ChildrenCursor {}", this ); + + // Close the cursors stored in the stack, if we have some + for ( Object cursor : cursorStack ) + { + ((IndexCursor)cursor).close(); + } + + // And finally, close the current cursor + currentCursor.close(); + + super.close(); + } + + + @Override + public void close( Exception cause ) throws Exception + { + LOG_CURSOR.debug( "Closing ChildrenCursor {}", this ); + + // Close the cursors stored in the stack, if we have some + for ( Object cursor : cursorStack ) + { + ((IndexCursor)cursor).close( cause ); + } + + // And finally, close the current cursor + currentCursor.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/GreaterEqCursor.java URL: http://svn.apache.org/viewvc/directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/GreaterEqCursor.java?rev=1330754&r1=1330753&r2=1330754&view=diff ============================================================================== --- directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/GreaterEqCursor.java (original) +++ directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/GreaterEqCursor.java Thu Apr 26 10:22:13 2012 @@ -199,7 +199,7 @@ public class GreaterEqCursor advanceTo = new ForwardIndexEntry(); - advanceTo.setValue( ( V ) greaterEqEvaluator.getExpression().getValue().getValue() ); + advanceTo.setKey( ( V ) greaterEqEvaluator.getExpression().getValue().getValue() ); userIdxCursor.before( advanceTo ); } else @@ -347,7 +347,7 @@ public class GreaterEqCursor candidate = userIdxCursor.get(); - if ( greaterEqEvaluator.getComparator().compare( candidate.getValue(), + if ( greaterEqEvaluator.getComparator().compare( candidate.getKey(), greaterEqEvaluator.getExpression().getValue().getValue() ) >= 0 ) { return setAvailable( true ); Modified: directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/GreaterEqEvaluator.java URL: http://svn.apache.org/viewvc/directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/GreaterEqEvaluator.java?rev=1330754&r1=1330753&r2=1330754&view=diff ============================================================================== --- directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/GreaterEqEvaluator.java (original) +++ directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/GreaterEqEvaluator.java Thu Apr 26 10:22:13 2012 @@ -218,7 +218,7 @@ public class GreaterEqEvaluator 0 ) @@ -246,7 +246,7 @@ public class LessEqCursor advanceTo = new ForwardIndexEntry(); //noinspection unchecked - advanceTo.setValue( ( V ) lessEqEvaluator.getExpression().getValue().getValue() ); + advanceTo.setKey( ( V ) lessEqEvaluator.getExpression().getValue().getValue() ); userIdxCursor.after( advanceTo ); } else @@ -377,7 +377,7 @@ public class LessEqCursor candidate = userIdxCursor.get(); - if ( lessEqEvaluator.getComparator().compare( candidate.getValue(), + if ( lessEqEvaluator.getComparator().compare( candidate.getKey(), lessEqEvaluator.getExpression().getValue().getValue() ) <= 0 ) { return setAvailable( true ); Modified: directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/LessEqEvaluator.java URL: http://svn.apache.org/viewvc/directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/LessEqEvaluator.java?rev=1330754&r1=1330753&r2=1330754&view=diff ============================================================================== --- directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/LessEqEvaluator.java (original) +++ directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/LessEqEvaluator.java Thu Apr 26 10:22:13 2012 @@ -215,7 +215,7 @@ public class LessEqEvaluator,Entry, ID> cursor = db.getRdnIndex().forwardCursor(); IndexEntry, ID> startingPos = new ForwardIndexEntry, ID>(); - startingPos.setValue( new ParentIdAndRdn( evaluator.getBaseId(), (Rdn[]) null ) ); + startingPos.setKey( new ParentIdAndRdn( evaluator.getBaseId(), (Rdn[]) null ) ); cursor.before( startingPos ); scopeCursor = new ChildrenCursor( db, evaluator.getBaseId(), cursor ); Modified: directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/PresenceCursor.java URL: http://svn.apache.org/viewvc/directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/PresenceCursor.java?rev=1330754&r1=1330753&r2=1330754&view=diff ============================================================================== --- directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/PresenceCursor.java (original) +++ directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/PresenceCursor.java Thu Apr 26 10:22:13 2012 @@ -290,7 +290,7 @@ public class PresenceCursor indexEntry = uuidCursor.get(); - indexEntry.setValue( presenceEvaluator.getAttributeType().getOid() ); + indexEntry.setKey( presenceEvaluator.getAttributeType().getOid() ); return indexEntry; } Modified: directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/SubstringCursor.java URL: http://svn.apache.org/viewvc/directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/SubstringCursor.java?rev=1330754&r1=1330753&r2=1330754&view=diff ============================================================================== --- directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/SubstringCursor.java (original) +++ directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/SubstringCursor.java Thu Apr 26 10:22:13 2012 @@ -96,7 +96,7 @@ public class SubstringCursor indexEntry = new ForwardIndexEntry(); - indexEntry.setValue( evaluator.getExpression().getInitial() ); + indexEntry.setKey( evaluator.getExpression().getInitial() ); wrapped.before( indexEntry ); } else @@ -113,7 +113,7 @@ public class SubstringCursor rec = entries.get(); // once match is found cleanup and return true - if ( regex.matcher( rec.getValue() ).matches() ) + if ( regex.matcher( rec.getKey() ).matches() ) { entries.close(); return true; @@ -231,7 +231,7 @@ public class SubstringEvaluator rec = entries.get(); // once match is found cleanup and return true - if ( regex.matcher( rec.getValue() ).matches() ) + if ( regex.matcher( rec.getKey() ).matches() ) { entries.close(); return true; @@ -368,7 +368,7 @@ public class SubstringEvaluator parentIdAndRdn = db.getRdnIndex().reverseLookup( baseId ); + IndexEntry indexEntry = new ForwardIndexEntry(); + + indexEntry.setId( baseId ); + indexEntry.setKey( parentIdAndRdn ); + + IndexCursor,Entry, ID> cursor = new SingletonIndexCursor, ID>( indexEntry ); + ID parentId = parentIdAndRdn.getParentId(); + + scopeCursor = new DescendantCursor( db, baseId, parentId, cursor ); } if ( evaluator.isDereferencing() ) @@ -246,6 +265,7 @@ public class SubtreeScopeCursor parentIdAndRdn = db.getRdnIndex().reverseLookup( tmp ); + + if ( parentIdAndRdn == null ) + { + return false; + } + + tmp = parentIdAndRdn.getParentId(); + + if ( tmp.equals( db.getRootId() ) ) + { + return false; + } + + if ( tmp.equals( baseId ) ) + { + return true; + } + } + } + /** * Asserts whether or not a candidate has sub level scope while taking @@ -134,7 +168,7 @@ public class SubtreeScopeEvaluator( "a", 1L ), new DefaultEntry() ); assertEquals( new Tuple( "a", 1L ), indexEntry.getTuple() ); @@ -99,11 +99,11 @@ public class ForwardIndexEntryTest indexEntry.clear(); assertNull( indexEntry.getId() ); - assertNull( indexEntry.getValue() ); + assertNull( indexEntry.getKey() ); assertNull( indexEntry.getEntry() ); assertNotNull( indexEntry.getTuple() ); assertNull( indexEntry.getTuple().getKey() ); - assertNull( indexEntry.getTuple().getValue() ); + assertNull( indexEntry.getTuple().getKey() ); } @@ -116,16 +116,16 @@ public class ForwardIndexEntryTest // create empty index entry and assert empty values ForwardIndexEntry indexEntry2 = new ForwardIndexEntry(); assertNull( indexEntry2.getId() ); - assertNull( indexEntry2.getValue() ); + assertNull( indexEntry2.getKey() ); assertNull( indexEntry2.getEntry() ); assertNotNull( indexEntry2.getTuple() ); assertNull( indexEntry2.getTuple().getKey() ); - assertNull( indexEntry2.getTuple().getValue() ); + assertNull( indexEntry2.getTuple().getKey() ); // copy values and assert non-empty values indexEntry2.copy( indexEntry ); assertEquals( Long.valueOf( 1L ), indexEntry2.getId() ); - assertEquals( "a", indexEntry2.getValue() ); + assertEquals( "a", indexEntry2.getKey() ); assertEquals( new DefaultEntry(), indexEntry2.getEntry() ); assertEquals( new Tuple( "a", 1L ), indexEntry2.getTuple() ); } Modified: directory/apacheds/branches/index-work/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/PartitionTest.java URL: http://svn.apache.org/viewvc/directory/apacheds/branches/index-work/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/PartitionTest.java?rev=1330754&r1=1330753&r2=1330754&view=diff ============================================================================== --- directory/apacheds/branches/index-work/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/PartitionTest.java (original) +++ directory/apacheds/branches/index-work/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/PartitionTest.java Thu Apr 26 10:22:13 2012 @@ -148,7 +148,6 @@ public class PartitionTest public void testExampleDataIndices() throws Exception { assertEquals( 11, partition.getRdnIndex().count() ); - assertEquals( 19, partition.getSubLevelIndex().count() ); assertEquals( 3, partition.getAliasIndex().count() ); assertEquals( 3, partition.getOneAliasIndex().count() ); assertEquals( 3, partition.getSubAliasIndex().count() ); Modified: directory/apacheds/branches/index-work/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/ReverseIndexEntryTest.java URL: http://svn.apache.org/viewvc/directory/apacheds/branches/index-work/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/ReverseIndexEntryTest.java?rev=1330754&r1=1330753&r2=1330754&view=diff ============================================================================== --- directory/apacheds/branches/index-work/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/ReverseIndexEntryTest.java (original) +++ directory/apacheds/branches/index-work/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/ReverseIndexEntryTest.java Thu Apr 26 10:22:13 2012 @@ -62,10 +62,10 @@ public class ReverseIndexEntryTest @Test public void testSetGetValue() { - assertNull( indexEntry.getValue() ); + assertNull( indexEntry.getKey() ); - indexEntry.setValue( "test" ); - assertEquals( "test", indexEntry.getValue() ); + indexEntry.setKey( "test" ); + assertEquals( "test", indexEntry.getKey() ); } @@ -99,7 +99,7 @@ public class ReverseIndexEntryTest indexEntry.clear(); assertNull( indexEntry.getId() ); - assertNull( indexEntry.getValue() ); + assertNull( indexEntry.getKey() ); assertNull( indexEntry.getEntry() ); assertNotNull( indexEntry.getTuple() ); assertNull( indexEntry.getTuple().getKey() ); @@ -116,7 +116,7 @@ public class ReverseIndexEntryTest // create empty index entry and assert empty values ReverseIndexEntry indexEntry2 = new ReverseIndexEntry(); assertNull( indexEntry2.getId() ); - assertNull( indexEntry2.getValue() ); + assertNull( indexEntry2.getKey() ); assertNull( indexEntry2.getEntry() ); assertNotNull( indexEntry2.getTuple() ); assertNull( indexEntry2.getTuple().getKey() ); @@ -125,7 +125,7 @@ public class ReverseIndexEntryTest // copy values and assert non-empty values indexEntry2.copy( indexEntry ); assertEquals( Long.valueOf( 1L ), indexEntry2.getId() ); - assertEquals( "a", indexEntry2.getValue() ); + assertEquals( "a", indexEntry2.getKey() ); assertEquals( new DefaultEntry(), indexEntry2.getEntry() ); assertEquals( new Tuple( 1L, "a" ), indexEntry2.getTuple() ); } Modified: directory/apacheds/branches/index-work/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/SingletonIndexCursorTest.java URL: http://svn.apache.org/viewvc/directory/apacheds/branches/index-work/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/SingletonIndexCursorTest.java?rev=1330754&r1=1330753&r2=1330754&view=diff ============================================================================== --- directory/apacheds/branches/index-work/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/SingletonIndexCursorTest.java (original) +++ directory/apacheds/branches/index-work/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/SingletonIndexCursorTest.java Thu Apr 26 10:22:13 2012 @@ -50,7 +50,7 @@ public class SingletonIndexCursorTest indexEntry = new ForwardIndexEntry(); indexEntry.setId( 1L ); indexEntry.setEntry( new DefaultEntry() ); - indexEntry.setValue( "test" ); + indexEntry.setKey( "test" ); indexCursor = new SingletonIndexCursor( indexEntry ); }