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/04/26 12:22:15 UTC

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...

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<String, Long> e1 = cursor.get();
         assertEquals( 555L, ( long ) e1.getId() );
-        assertEquals( "bar", e1.getValue() );
+        assertEquals( "bar", e1.getKey() );
 
         cursor.next();
         IndexEntry<String, Long> e2 = cursor.get();
         assertEquals( 333L, ( long ) e2.getId() );
-        assertEquals( "foo", e2.getValue() );
+        assertEquals( "foo", e2.getKey() );
 
         cursor.next();
         IndexEntry<String, Long> 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<ParentIdAndRdn<Long>, 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<ParentIdAndRdn<Long>, 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<ParentIdAndRdn<Long>, 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<Long> parentIdAndRdn = getRdnIndex().reverseLookup( baseId ); 
+        IndexEntry indexEntry = new ForwardIndexEntry();
+        
+        indexEntry.setId(baseId);
+        indexEntry.setKey( parentIdAndRdn );
+
+        IndexCursor<ParentIdAndRdn<Long>,Entry, Long> cursor = new SingletonIndexCursor<ParentIdAndRdn<Long>, Long>( indexEntry );
+        Long parentId = parentIdAndRdn.getParentId();
+
+        IndexCursor<Long, Entry, Long> scopeCursor = new DescendantCursor( this, baseId, parentId, cursor );
 
         // Then, if there are some children, move then to the new place
         try
         {
-            IndexCursor<Long, Entry, Long> cursor = getSubLevelIndex().forwardCursor( entryIdOld );
-
-            while ( cursor.next() )
+            while ( scopeCursor.next() )
             {
-                IndexEntry<Long, Long> entry = cursor.get();
+                IndexEntry<Long, Long> 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<ParentIdAndRdn<Long>,Entry,Long> cursor = rdnIdx.forwardCursor();
         
         IndexEntry<ParentIdAndRdn<Long>, Long> startingPos = new ForwardIndexEntry<ParentIdAndRdn<Long>, Long>();
-        startingPos.setValue( new ParentIdAndRdn<Long>( id, (Rdn[]) null ) );
+        startingPos.setKey( new ParentIdAndRdn<Long>( 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<String, Entry, ID> objectClassIdx;
 
-    /** a system index on the entries of descendants of root Dn */
-    protected Index<ID, Entry, ID> subLevelIdx;
-
     /** the attribute presence index */
     protected Index<String, Entry, ID> 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<ID, Entry, ID> index = createSystemIndex( ApacheSchemaConstants.APACHE_SUB_LEVEL_AT_OID, partitionPath, WITH_REVERSE );
-            addIndex( index );
-        }
-
         if ( getRdnIndex() == null )
         {
             Index<ParentIdAndRdn<ID>, 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<ParentIdAndRdn<ID>, Entry, ID> ) systemIndices.get( ApacheSchemaConstants.APACHE_RDN_AT_OID );
         presenceIdx = ( Index<String, Entry, ID> ) systemIndices.get( ApacheSchemaConstants.APACHE_PRESENCE_AT_OID );
-        subLevelIdx = ( Index<ID, Entry, ID> ) systemIndices.get( ApacheSchemaConstants.APACHE_SUB_LEVEL_AT_OID );
         aliasIdx = ( Index<String, Entry, ID> ) systemIndices.get( ApacheSchemaConstants.APACHE_ALIAS_AT_OID );
         oneAliasIdx = ( Index<ID, Entry, ID> ) systemIndices.get( ApacheSchemaConstants.APACHE_ONE_ALIAS_AT_OID );
         subAliasIdx = ( Index<ID, Entry, ID> ) 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<ParentIdAndRdn<ID>,Entry,ID> cursor = rdnIdx.forwardCursor();
         
         IndexEntry<ParentIdAndRdn<ID>, ID> startingPos = new ForwardIndexEntry<ParentIdAndRdn<ID>, 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<ParentIdAndRdn<ID>,Entry,ID> cursor = rdnIdx.forwardCursor();
         
         IndexEntry<ParentIdAndRdn<ID>, ID> startingPos = new ForwardIndexEntry<ParentIdAndRdn<ID>, 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<ParentIdAndRdn<ID>,Entry, ID> cursor = rdnIdx.forwardCursor();
             
             IndexEntry<ParentIdAndRdn<ID>, ID> startingPos = new ForwardIndexEntry<ParentIdAndRdn<ID>, 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<ID> 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<ID> parentIdAndRdn = rdnIdx.reverseLookup( oldId );
+        
+        // Now we can drop it
         rdnIdx.drop( oldId );
-        ParentIdAndRdn<ID> key = new ParentIdAndRdn<ID>( 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<ID> parentIds = new ArrayList<ID>();
-
-        // 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<IndexEntry<ID, ID>> cursor = subLevelIdx.forwardCursor( entryId );
-
-        List<ID> childIds = new ArrayList<ID>();
-        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<ID, Entry, ID> getSubLevelIndex()
-    {
-        return ( Index<ID, Entry, ID> ) systemIndices.get( ApacheSchemaConstants.APACHE_SUB_LEVEL_AT_OID );
-    }
-
-
-    /**
-     * {@inheritDoc}
-     */
-    @SuppressWarnings("unchecked")
     public Index<String, Entry, ID> getAliasIndex()
     {
         return ( Index<String, Entry, ID> ) 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<T> 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 <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
- * @param <V> The value stored in the Tuple, associated key for the object
+ * @param <K> The key stored in the Tuple, associated key for the object
  * @param <ID> The ID of the object
  */
-public abstract class AbstractIndexEntry<V, ID> implements IndexEntry<V, ID>
+public abstract class AbstractIndexEntry<K, ID> implements IndexEntry<K, ID>
 {
     /** 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<V, ID> entry )
+    public void copy( IndexEntry<K, ID> 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 <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
- * @param <V> The value stored in the Tuple, associated key for the object
+ * @param <V> The key stored in the Tuple, associated key for the object
  * @param <ID> The ID of the object
  */
-public class ForwardIndexEntry<V, ID> extends AbstractIndexEntry<V, ID>
+public class ForwardIndexEntry<K, ID> extends AbstractIndexEntry<K, ID>
 {
     /** The underlying Tuple */
-    private final Tuple<V, ID> tuple = new Tuple<V, ID>();
+    private final Tuple<K, ID> tuple = new Tuple<K, ID>();
 
 
     /**
@@ -55,7 +55,7 @@ public class ForwardIndexEntry<V, ID> ex
      * @param tuple the tuple for the ForwardIndexEntry
      * @param entry the resuscitated Entry if any
      */
-    public void setTuple( Tuple<V, ID> tuple, Entry entry )
+    public void setTuple( Tuple<K, ID> tuple, Entry entry )
     {
         setEntry( entry );
         this.tuple.setKey( tuple.getKey() );
@@ -75,7 +75,7 @@ public class ForwardIndexEntry<V, ID> ex
     /**
      * {@inheritDoc}
      */
-    public V getValue()
+    public K getKey()
     {
         return tuple.getKey();
     }
@@ -93,7 +93,7 @@ public class ForwardIndexEntry<V, ID> ex
     /**
      * {@inheritDoc}
      */
-    public void setValue( V value )
+    public void setKey( K value )
     {
         tuple.setKey( value );
     }
@@ -102,7 +102,7 @@ public class ForwardIndexEntry<V, ID> ex
     /**
      * {@inheritDoc}
      */
-    public Tuple<V, ID> getTuple()
+    public Tuple<K, ID> getTuple()
     {
         return tuple;
     }
@@ -122,10 +122,10 @@ public class ForwardIndexEntry<V, ID> ex
     /**
      * {@inheritDoc}
      */
-    public void copy( IndexEntry<V, ID> entry )
+    public void copy( IndexEntry<K, ID> 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 <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @param <V> The value stored in the Tuple, associated key for the object
  * @param <ID> The ID of the object
  */
-public interface IndexEntry<V, ID>
+public interface IndexEntry<K, ID>
 {
     /**
-     * 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<V, ID>
      *
      * @param entry the entry to copy fields of
      */
-    void copy( IndexEntry<V, ID> entry );
+    void copy( IndexEntry<K, ID> 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 ParentIdAndRdn<ID extends C
      * 
      * @param rdns the new Rdn
      */
-    public void setRdns( Rdn[] rdns )
+    public void setRdns( Rdn... rdns )
     {
         this.rdns = rdns;
     }

Modified: directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/ReverseIndexEntry.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/ReverseIndexEntry.java?rev=1330754&r1=1330753&r2=1330754&view=diff
==============================================================================
--- directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/ReverseIndexEntry.java (original)
+++ directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/ReverseIndexEntry.java Thu Apr 26 10:22:13 2012
@@ -29,13 +29,13 @@ import org.apache.directory.shared.ldap.
  * if one has already been loaded.
  *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
- * @param <V> The value stored in the Tuple, associated key for the Entry
+ * @param <K> The key stored in the Tuple, associated key for the Entry
  * @param <ID> The ID of the Entry
  */
-public class ReverseIndexEntry<V, ID> extends AbstractIndexEntry<V, ID>
+public class ReverseIndexEntry<K, ID> extends AbstractIndexEntry<K, ID>
 {
     /** The underlying Tuple */
-    private final Tuple<ID, V> tuple = new Tuple<ID, V>();
+    private final Tuple<ID, K> tuple = new Tuple<ID, K>();
 
 
     /**
@@ -55,7 +55,7 @@ public class ReverseIndexEntry<V, ID> ex
      * @param tuple the tuple for the ReverseIndexEntry
      * @param obj the resusitated Entry that is indexed if any
      */
-    public void setTuple( Tuple<ID, V> tuple, Entry entry )
+    public void setTuple( Tuple<ID, K> tuple, Entry entry )
     {
         setEntry( entry );
         this.tuple.setKey( tuple.getKey() );
@@ -75,7 +75,7 @@ public class ReverseIndexEntry<V, ID> ex
     /**
      * {@inheritDoc}
      */
-    public V getValue()
+    public K getKey()
     {
         return tuple.getValue();
     }
@@ -93,7 +93,7 @@ public class ReverseIndexEntry<V, ID> ex
     /**
      * {@inheritDoc}
      */
-    public void setValue( V key )
+    public void setKey( K key )
     {
         tuple.setValue( key );
     }
@@ -122,11 +122,11 @@ public class ReverseIndexEntry<V, ID> ex
     /**
      * {@inheritDoc}
      */
-    public void copy( IndexEntry<V, ID> entry )
+    public void copy( IndexEntry<K, ID> 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<E, ID extends Com
     public static final String[] SYS_INDEX_OID_ARRAY =
         {
             ApacheSchemaConstants.APACHE_PRESENCE_AT_OID,
-            ApacheSchemaConstants.APACHE_SUB_LEVEL_AT_OID,
             ApacheSchemaConstants.APACHE_RDN_AT_OID,
             ApacheSchemaConstants.APACHE_ALIAS_AT_OID,
             ApacheSchemaConstants.APACHE_ONE_ALIAS_AT_OID,
@@ -179,12 +178,6 @@ public interface Store<E, ID extends Com
 
 
     /**
-     * @return The SubLevel system index
-     */
-    Index<ID, E, ID> getSubLevelIndex();
-
-
-    /**
      * @return The Alias system index
      */
     Index<String, E, ID> 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<ID extends
         // Create the returned IndexEntry, copying what we get from the wrapped cursor
         IndexEntry<String, ID> 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<ID extends C
             IndexEntry cursorEntry = cursor.get();
             IndexEntry<ID, ID> entry = new ForwardIndexEntry();
             entry.setId( (ID)cursorEntry.getId() );
-            entry.setValue( ((ParentIdAndRdn<ID>)cursorEntry.getTuple().getKey()).getParentId() );
+            entry.setKey( ((ParentIdAndRdn<ID>)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 DefaultOptimizer<E, ID exte
     private long getScopeScan( ScopeNode node ) throws Exception
     {
         ID id = db.getEntryId( node.getBaseDn() );
+        
         switch ( node.getScope() )
         {
             case OBJECT:
@@ -388,7 +389,7 @@ public class DefaultOptimizer<E, ID exte
                 }
                 else
                 {
-                    return db.getSubLevelIndex().count( id );
+                    return db.getRdnIndex().reverseLookup( id ).getNbDescendants() + 1;
                 }
 
             default:

Added: directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/DescendantCursor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/DescendantCursor.java?rev=1330754&view=auto
==============================================================================
--- directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/DescendantCursor.java (added)
+++ directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/DescendantCursor.java Thu Apr 26 10:22:13 2012
@@ -0,0 +1,304 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.directory.server.xdbm.search.impl;
+
+
+import org.apache.commons.collections.ArrayStack;
+import org.apache.directory.server.i18n.I18n;
+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;
+import org.apache.directory.server.xdbm.ParentIdAndRdn;
+import org.apache.directory.server.xdbm.Store;
+import org.apache.directory.shared.ldap.model.entry.Entry;
+import org.apache.directory.shared.ldap.model.name.Rdn;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * A Cursor over entries satisfying one level scope constraints with alias
+ * dereferencing considerations when enabled during search.
+ * We use the Rdn index to fetch all the descendants of a given entry.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class DescendantCursor<ID extends Comparable<ID>> extends AbstractIndexCursor<ID, Entry, ID>
+{
+    /** 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<Entry, ID> db;
+    
+    /** The prefetched element */
+    private IndexEntry prefetched;
+    
+    /** The current Cursor over the entries in the scope of the search base */
+    private IndexCursor<ParentIdAndRdn<ID>,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<Entry, ID> db, ID baseId, ID parentId, IndexCursor<ParentIdAndRdn<ID>, 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<Entry, ID> db, ID baseId, ID parentId, IndexCursor<ParentIdAndRdn<ID>, 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<ID>)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<ID> parentIdAndRdn = ((ParentIdAndRdn<ID>)(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<ParentIdAndRdn<ID>, 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<ParentIdAndRdn<ID>,Entry, ID> cursor = db.getRdnIndex().forwardCursor();
+                        
+                        IndexEntry<ParentIdAndRdn<ID>, ID> startingPos = new ForwardIndexEntry<ParentIdAndRdn<ID>, 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<ParentIdAndRdn<ID>, Entry, ID> )cursorStack.pop();
+                    currentParentId = (ID)parentIdStack.pop();
+                }
+                // and continue...
+            }
+        }
+        
+        return false;
+    }
+    
+
+    public IndexEntry<ID, ID> 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<V, ID exten
              * userIdxCursor before the first element.  Otherwise we let the
              * underlying userIdx Cursor position the element.
              */
-            if ( greaterEqEvaluator.getComparator().compare( element.getValue(),
+            if ( greaterEqEvaluator.getComparator().compare( element.getKey(),
                 greaterEqEvaluator.getExpression().getValue().getValue() ) <= 0 )
             {
                 beforeFirst();
@@ -225,7 +225,7 @@ public class GreaterEqCursor<V, ID exten
 
         if ( userIdxCursor != null )
         {
-            int comparedValue = greaterEqEvaluator.getComparator().compare( element.getValue(),
+            int comparedValue = greaterEqEvaluator.getComparator().compare( element.getKey(),
                 greaterEqEvaluator.getExpression().getValue().getValue() );
 
             /*
@@ -273,7 +273,7 @@ public class GreaterEqCursor<V, ID exten
         if ( userIdxCursor != null )
         {
             IndexEntry<V, ID> advanceTo = new ForwardIndexEntry<V, ID>();
-            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<V, ID exten
                 checkNotClosed( "previous()" );
                 IndexEntry<?, ID> 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<T, ID ex
             {
                 if ( indexEntry != null )
                 {
-                    indexEntry.setValue( value.getNormValue() );
+                    indexEntry.setKey( value.getNormValue() );
                 }
                 return true;
             }

Modified: directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/LessEqCursor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/LessEqCursor.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/LessEqCursor.java (original)
+++ directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/LessEqCursor.java Thu Apr 26 10:22:13 2012
@@ -170,7 +170,7 @@ public class LessEqCursor<V, ID extends 
              * If the element's value is smaller, then we delegate to the
              * before() method of the userIdxCursor.
              */
-            int compareValue = lessEqEvaluator.getComparator().compare( element.getValue(),
+            int compareValue = lessEqEvaluator.getComparator().compare( element.getKey(),
                 lessEqEvaluator.getExpression().getValue().getValue() );
 
             if ( compareValue > 0 )
@@ -246,7 +246,7 @@ public class LessEqCursor<V, ID extends 
 
         if ( userIdxCursor != null )
         {
-            int comparedValue = lessEqEvaluator.getComparator().compare( element.getValue(),
+            int comparedValue = lessEqEvaluator.getComparator().compare( element.getKey(),
                 lessEqEvaluator.getExpression().getValue().getValue() );
 
             /*
@@ -301,7 +301,7 @@ public class LessEqCursor<V, ID extends 
         {
             IndexEntry<V, ID> advanceTo = new ForwardIndexEntry<V, ID>();
             //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<V, ID extends 
                 checkNotClosed( "next()" );
                 IndexEntry<?, ID> 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<T, ID exten
             {
                 if ( indexEntry != null )
                 {
-                    indexEntry.setValue( value.getNormValue() );
+                    indexEntry.setKey( value.getNormValue() );
                 }
                 return true;
             }

Modified: directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/OneLevelScopeCursor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/OneLevelScopeCursor.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/OneLevelScopeCursor.java (original)
+++ directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/OneLevelScopeCursor.java Thu Apr 26 10:22:13 2012
@@ -86,7 +86,7 @@ public class OneLevelScopeCursor<ID exte
         IndexCursor<ParentIdAndRdn<ID>,Entry, ID> cursor = db.getRdnIndex().forwardCursor();
         
         IndexEntry<ParentIdAndRdn<ID>, ID> startingPos = new ForwardIndexEntry<ParentIdAndRdn<ID>, 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<ID extends C
              * set that accordingly here.
              */
             IndexEntry<String, ID> 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<ID extends 
         if ( evaluator.getExpression().getInitial() != null && hasIndex )
         {
             ForwardIndexEntry<String, ID> indexEntry = new ForwardIndexEntry<String, ID>();
-            indexEntry.setValue( evaluator.getExpression().getInitial() );
+            indexEntry.setKey( evaluator.getExpression().getInitial() );
             wrapped.before( indexEntry );
         }
         else
@@ -113,7 +113,7 @@ public class SubstringCursor<ID extends 
         setAvailable( false );
         indexEntry.setEntry( null );
         indexEntry.setId( null );
-        indexEntry.setValue( null );
+        indexEntry.setKey( null );
     }
 
 
@@ -140,7 +140,7 @@ public class SubstringCursor<ID extends 
     {
         if ( hasIndex )
         {
-            return evaluator.getPattern().matcher( indexEntry.getValue() ).matches();
+            return evaluator.getPattern().matcher( indexEntry.getKey() ).matches();
         }
         else
         {
@@ -167,7 +167,7 @@ public class SubstringCursor<ID extends 
             {
                 setAvailable( true );
                 this.indexEntry.setId( entry.getId() );
-                this.indexEntry.setValue( entry.getValue() );
+                this.indexEntry.setKey( entry.getKey() );
                 this.indexEntry.setEntry( entry.getEntry() );
                 return true;
             }
@@ -189,7 +189,7 @@ public class SubstringCursor<ID extends 
             {
                 setAvailable( true );
                 this.indexEntry.setId( entry.getId() );
-                this.indexEntry.setValue( entry.getValue() );
+                this.indexEntry.setKey( entry.getKey() );
                 this.indexEntry.setEntry( entry.getEntry() );
                 return true;
             }

Modified: directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/SubstringEvaluator.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/SubstringEvaluator.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/SubstringEvaluator.java (original)
+++ directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/SubstringEvaluator.java Thu Apr 26 10:22:13 2012
@@ -195,7 +195,7 @@ public class SubstringEvaluator<ID exten
             IndexEntry<String, ID> 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<ID exten
             IndexEntry<String, ID> 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<ID exten
                     if ( regex.matcher( strValue ).matches() )
                     {
                         // before returning we set the normalized value
-                        indexEntry.setValue( strValue );
+                        indexEntry.setKey( strValue );
                         return true;
                     }
                 }
@@ -387,7 +387,7 @@ public class SubstringEvaluator<ID exten
                     if ( check( byteValue ) )
                     {
                         // before returning we set the normalized value
-                        indexEntry.setValue( byteValue );
+                        indexEntry.setKey( byteValue );
                         return true;
                     }
                     */
@@ -430,7 +430,7 @@ public class SubstringEvaluator<ID exten
                         if ( regex.matcher( strValue ).matches() )
                         {
                             // before returning we set the normalized value
-                            indexEntry.setValue( strValue );
+                            indexEntry.setKey( strValue );
                             return true;
                         }
                     }

Modified: directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/SubtreeScopeCursor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/SubtreeScopeCursor.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/SubtreeScopeCursor.java (original)
+++ directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/SubtreeScopeCursor.java Thu Apr 26 10:22:13 2012
@@ -20,14 +20,21 @@
 package org.apache.directory.server.xdbm.search.impl;
 
 
+import java.util.List;
+
 import org.apache.directory.server.core.api.partition.Partition;
 import org.apache.directory.server.i18n.I18n;
 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;
+import org.apache.directory.server.xdbm.ParentIdAndRdn;
+import org.apache.directory.server.xdbm.SingletonIndexCursor;
 import org.apache.directory.server.xdbm.Store;
 import org.apache.directory.shared.ldap.model.cursor.InvalidCursorPositionException;
+import org.apache.directory.shared.ldap.model.cursor.SingletonCursor;
 import org.apache.directory.shared.ldap.model.entry.Entry;
+import org.apache.directory.shared.ldap.model.name.Rdn;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -83,7 +90,19 @@ public class SubtreeScopeCursor<ID exten
         }
         else
         {
-            scopeCursor = db.getSubLevelIndex().forwardCursor( evaluator.getBaseId() );
+            // We use the RdnIndex to get all the entries from a starting point
+            // and below up to the number of children
+            ID baseId = evaluator.getBaseId();
+            ParentIdAndRdn<ID> parentIdAndRdn = db.getRdnIndex().reverseLookup( baseId ); 
+            IndexEntry indexEntry = new ForwardIndexEntry();
+            
+            indexEntry.setId( baseId );
+            indexEntry.setKey( parentIdAndRdn );
+
+            IndexCursor<ParentIdAndRdn<ID>,Entry, ID> cursor = new SingletonIndexCursor<ParentIdAndRdn<ID>, ID>( indexEntry );
+            ID parentId = parentIdAndRdn.getParentId();
+
+            scopeCursor = new DescendantCursor( db, baseId, parentId, cursor );
         }
 
         if ( evaluator.isDereferencing() )
@@ -246,6 +265,7 @@ public class SubtreeScopeCursor<ID exten
     public boolean next() throws Exception
     {
         checkNotClosed( "next()" );
+        
         // if the cursor hasn't been set position it before the first element
         if ( cursor == null )
         {

Modified: directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/SubtreeScopeEvaluator.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/SubtreeScopeEvaluator.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/SubtreeScopeEvaluator.java (original)
+++ directory/apacheds/branches/index-work/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/impl/SubtreeScopeEvaluator.java Thu Apr 26 10:22:13 2012
@@ -23,6 +23,7 @@ package org.apache.directory.server.xdbm
 import org.apache.directory.server.core.api.partition.Partition;
 import org.apache.directory.server.i18n.I18n;
 import org.apache.directory.server.xdbm.IndexEntry;
+import org.apache.directory.server.xdbm.ParentIdAndRdn;
 import org.apache.directory.server.xdbm.Store;
 import org.apache.directory.server.xdbm.search.Evaluator;
 import org.apache.directory.shared.ldap.model.filter.ScopeNode;
@@ -112,6 +113,39 @@ public class SubtreeScopeEvaluator<E, ID
         return contextEntryId;
     }
 
+    
+    /**
+     * Tells if a candidate is a descendant of the base ID. We have to fetch all 
+     * the parentIdAndRdn up to the baseId. If we terminate on the context entry without 
+     * having found the baseId, then the candidate is not a descendant.
+     */
+    private boolean isDescendant( ID candidateId ) throws Exception
+    {
+        ID tmp = candidateId;
+        
+        while ( true )
+        {
+            ParentIdAndRdn<ID> 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<E, ID
          * to all it's subordinates since that would be the entire set of 
          * entries in the db.
          */
-        boolean isDescendant = baseIsContextEntry || baseId.equals( id ) || db.getSubLevelIndex().forward( baseId, id );
+        boolean isDescendant = baseIsContextEntry || baseId.equals( id ) || isDescendant( id );
 
         /*
          * The candidate id could be any entry in the db.  If search

Modified: directory/apacheds/branches/index-work/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/ForwardIndexEntryTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/index-work/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/ForwardIndexEntryTest.java?rev=1330754&r1=1330753&r2=1330754&view=diff
==============================================================================
--- directory/apacheds/branches/index-work/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/ForwardIndexEntryTest.java (original)
+++ directory/apacheds/branches/index-work/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/ForwardIndexEntryTest.java Thu Apr 26 10:22:13 2012
@@ -62,10 +62,10 @@ public class ForwardIndexEntryTest
     @Test
     public void testSetGetValue()
     {
-        assertNull( indexEntry.getValue() );
+        assertNull( indexEntry.getKey() );
 
-        indexEntry.setValue( "test" );
-        assertEquals( "test", indexEntry.getValue() );
+        indexEntry.setKey( "test" );
+        assertEquals( "test", indexEntry.getKey() );
     }
 
 
@@ -84,7 +84,7 @@ public class ForwardIndexEntryTest
     {
         assertNotNull( indexEntry.getTuple() );
         assertNull( indexEntry.getTuple().getKey() );
-        assertNull( indexEntry.getTuple().getValue() );
+        assertNull( indexEntry.getTuple().getKey() );
 
         indexEntry.setTuple( new Tuple<String, Long>( "a", 1L ), new DefaultEntry() );
         assertEquals( new Tuple<String, Long>( "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<String, Long> indexEntry2 = new ForwardIndexEntry<String, Long>();
         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<String, Long>( "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<String, Long> indexEntry2 = new ReverseIndexEntry<String, Long>();
         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<Long, String>( 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<String, Long>();
         indexEntry.setId( 1L );
         indexEntry.setEntry( new DefaultEntry() );
-        indexEntry.setValue( "test" );
+        indexEntry.setKey( "test" );
         indexCursor = new SingletonIndexCursor<String, Long>( indexEntry );
     }