directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From seelm...@apache.org
Subject svn commit: r940073 [1/2] - in /directory/apacheds/trunk: avl-partition/src/main/java/org/apache/directory/server/core/partition/avl/ avl-partition/src/test/java/org/apache/directory/server/core/partition/avl/ jdbm-store/src/main/java/org/apache/direct...
Date Sat, 01 May 2010 16:25:20 GMT
Author: seelmann
Date: Sat May  1 16:25:19 2010
New Revision: 940073

URL: http://svn.apache.org/viewvc?rev=940073&view=rev
Log:
o Use RDN index for AVL partition
o Moved remaining common methods to AbstractStore


Added:
    directory/apacheds/trunk/avl-partition/src/test/java/org/apache/directory/server/core/partition/avl/AvlRdnIndexTest.java
Modified:
    directory/apacheds/trunk/avl-partition/src/main/java/org/apache/directory/server/core/partition/avl/AvlIndex.java
    directory/apacheds/trunk/avl-partition/src/main/java/org/apache/directory/server/core/partition/avl/AvlPartition.java
    directory/apacheds/trunk/avl-partition/src/main/java/org/apache/directory/server/core/partition/avl/AvlStore.java
    directory/apacheds/trunk/avl-partition/src/test/java/org/apache/directory/server/core/partition/avl/AvlStoreTest.java
    directory/apacheds/trunk/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmStore.java
    directory/apacheds/trunk/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmStoreTest.java
    directory/apacheds/trunk/ldif-partition/src/main/java/org/apache/directory/server/core/partition/ldif/LdifPartition.java
    directory/apacheds/trunk/xdbm-base/src/main/java/org/apache/directory/server/xdbm/AbstractStore.java

Modified: directory/apacheds/trunk/avl-partition/src/main/java/org/apache/directory/server/core/partition/avl/AvlIndex.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/avl-partition/src/main/java/org/apache/directory/server/core/partition/avl/AvlIndex.java?rev=940073&r1=940072&r2=940073&view=diff
==============================================================================
--- directory/apacheds/trunk/avl-partition/src/main/java/org/apache/directory/server/core/partition/avl/AvlIndex.java (original)
+++ directory/apacheds/trunk/avl-partition/src/main/java/org/apache/directory/server/core/partition/avl/AvlIndex.java Sat May  1 16:25:19 2010
@@ -34,6 +34,7 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.schema.LdapComparator;
 import org.apache.directory.shared.ldap.schema.MatchingRule;
 import org.apache.directory.shared.ldap.schema.Normalizer;
+import org.apache.directory.shared.ldap.schema.SchemaManager;
 
 
 /**
@@ -44,11 +45,11 @@ import org.apache.directory.shared.ldap.
  */
 public class AvlIndex<K, O> implements Index<K, O, Long>
 {
-    private Normalizer normalizer;
-    private AttributeType attributeType;
-    private AvlTable<K, Long> forward;
-    private AvlTable<Long, K> reverse;
-    private String attributeId;
+    protected Normalizer normalizer;
+    protected AttributeType attributeType;
+    protected AvlTable<K, Long> forward;
+    protected AvlTable<Long, K> reverse;
+    protected String attributeId;
 
 
     public AvlIndex()
@@ -62,7 +63,7 @@ public class AvlIndex<K, O> implements I
     }
 
 
-    void initialize( AttributeType attributeType ) throws Exception
+    public void init( SchemaManager schemaManager, AttributeType attributeType ) throws Exception
     {
         this.attributeType = attributeType;
 

Modified: directory/apacheds/trunk/avl-partition/src/main/java/org/apache/directory/server/core/partition/avl/AvlPartition.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/avl-partition/src/main/java/org/apache/directory/server/core/partition/avl/AvlPartition.java?rev=940073&r1=940072&r2=940073&view=diff
==============================================================================
--- directory/apacheds/trunk/avl-partition/src/main/java/org/apache/directory/server/core/partition/avl/AvlPartition.java (original)
+++ directory/apacheds/trunk/avl-partition/src/main/java/org/apache/directory/server/core/partition/avl/AvlPartition.java Sat May  1 16:25:19 2010
@@ -33,6 +33,7 @@ import org.apache.directory.server.xdbm.
 import org.apache.directory.server.xdbm.search.impl.NoOpOptimizer;
 import org.apache.directory.shared.ldap.entry.Modification;
 import org.apache.directory.shared.ldap.entry.Entry;
+import org.apache.directory.shared.ldap.name.DN;
 
 
 /**
@@ -104,12 +105,9 @@ public class AvlPartition extends Abstra
     }
 
 
-    /**
-     * {@inheritDoc}
-     */
-    public final void modify( long entryId, List<Modification> modifications ) throws Exception
+    public final void modify( DN dn, List<Modification> modifications ) throws Exception
     {
-        ( ( AvlStore<Entry> ) store ).modify( entryId, modifications );
+        store.modify( dn, modifications );
     }
 
 

Modified: directory/apacheds/trunk/avl-partition/src/main/java/org/apache/directory/server/core/partition/avl/AvlStore.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/avl-partition/src/main/java/org/apache/directory/server/core/partition/avl/AvlStore.java?rev=940073&r1=940072&r2=940073&view=diff
==============================================================================
--- directory/apacheds/trunk/avl-partition/src/main/java/org/apache/directory/server/core/partition/avl/AvlStore.java (original)
+++ directory/apacheds/trunk/avl-partition/src/main/java/org/apache/directory/server/core/partition/avl/AvlStore.java Sat May  1 16:25:19 2010
@@ -21,30 +21,13 @@ package org.apache.directory.server.core
 
 
 import java.io.File;
-import java.util.ArrayList;
-import java.util.List;
 
-import org.apache.directory.server.core.entry.ClonedServerEntry;
+import org.apache.directory.server.constants.ApacheSchemaConstants;
 import org.apache.directory.server.core.partition.impl.btree.LongComparator;
-import org.apache.directory.server.i18n.I18n;
 import org.apache.directory.server.xdbm.AbstractStore;
 import org.apache.directory.server.xdbm.Index;
-import org.apache.directory.server.xdbm.IndexCursor;
-import org.apache.directory.server.xdbm.IndexEntry;
 import org.apache.directory.shared.ldap.constants.SchemaConstants;
-import org.apache.directory.shared.ldap.cursor.Cursor;
 import org.apache.directory.shared.ldap.entry.Entry;
-import org.apache.directory.shared.ldap.entry.EntryAttribute;
-import org.apache.directory.shared.ldap.entry.Modification;
-import org.apache.directory.shared.ldap.entry.ModificationOperation;
-import org.apache.directory.shared.ldap.entry.Value;
-import org.apache.directory.shared.ldap.exception.LdapNoSuchObjectException;
-import org.apache.directory.shared.ldap.exception.LdapSchemaViolationException;
-import org.apache.directory.shared.ldap.message.ResultCodeEnum;
-import org.apache.directory.shared.ldap.name.AVA;
-import org.apache.directory.shared.ldap.name.DN;
-import org.apache.directory.shared.ldap.name.RDN;
-import org.apache.directory.shared.ldap.schema.AttributeType;
 import org.apache.directory.shared.ldap.schema.SchemaManager;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -65,212 +48,6 @@ public class AvlStore<E> extends Abstrac
     /** static logger */
     private static final Logger LOG = LoggerFactory.getLogger( AvlStore.class );
 
-    /** Two static declaration to avoid lookup all over the code */
-    private static AttributeType OBJECT_CLASS_AT;
-    private static AttributeType ALIASED_OBJECT_NAME_AT;
-
-    /** the master table storing entries by primary key */
-    private AvlMasterTable<Entry> master;
-
-
-    /**
-     * {@inheritDoc}
-     */
-    public void add( Entry entry ) throws Exception
-    {
-        if ( entry instanceof ClonedServerEntry )
-        {
-            throw new Exception( I18n.err( I18n.ERR_215 ) );
-        }
-
-        DN normName = entry.getDn();
-
-        Long id;
-        Long parentId;
-
-        id = master.getNextId();
-
-        //
-        // Suffix entry cannot have a parent since it is the root so it is 
-        // capped off using the zero value which no entry can have since 
-        // entry sequences start at 1.
-        //
-
-        DN parentDn = null;
-
-        if ( normName.getNormName().equals( suffixDn.getNormName() ) )
-        {
-            parentId = 0L;
-        }
-        else
-        {
-            parentDn = ( DN ) normName.clone();
-            parentDn.remove( parentDn.size() - 1 );
-            parentId = getEntryId( parentDn );
-        }
-
-        // don't keep going if we cannot find the parent Id
-        if ( parentId == null )
-        {
-            throw new LdapNoSuchObjectException( I18n.err( I18n.ERR_216, parentDn ) );
-        }
-
-        EntryAttribute objectClass = entry.get( OBJECT_CLASS_AT );
-
-        if ( objectClass == null )
-        {
-            String msg = I18n.err( I18n.ERR_217, normName.getName(), entry );
-            throw new LdapSchemaViolationException( ResultCodeEnum.OBJECT_CLASS_VIOLATION, msg );
-        }
-
-        // Start adding the system userIndices
-        // Why bother doing a lookup if this is not an alias.
-        // First, the ObjectClass index
-        for ( Value<?> value : objectClass )
-        {
-            objectClassIdx.add( value.getString(), id );
-        }
-
-        if ( objectClass.contains( SchemaConstants.ALIAS_OC ) )
-        {
-            EntryAttribute aliasAttr = entry.get( ALIASED_OBJECT_NAME_AT );
-            addAliasIndices( id, normName, aliasAttr.getString() );
-        }
-
-        if ( !Character.isDigit( normName.getNormName().charAt( 0 ) ) )
-        {
-            throw new IllegalStateException( I18n.err( I18n.ERR_218, normName.getNormName() ) );
-        }
-
-        ndnIdx.add( normName.getNormName(), id );
-        oneLevelIdx.add( parentId, id );
-
-        // Update the EntryCsn index
-        EntryAttribute entryCsn = entry.get( SchemaConstants.ENTRY_CSN_AT );
-
-        if ( entryCsn == null )
-        {
-            String msg = I18n.err( I18n.ERR_219, normName.getName(), entry );
-            throw new LdapSchemaViolationException( ResultCodeEnum.OBJECT_CLASS_VIOLATION, msg );
-        }
-
-        entryCsnIdx.add( entryCsn.getString(), id );
-
-        // Update the EntryUuid index
-        EntryAttribute entryUuid = entry.get( SchemaConstants.ENTRY_UUID_AT );
-
-        if ( entryUuid == null )
-        {
-            String msg = I18n.err( I18n.ERR_220, normName.getName(), entry );
-            throw new LdapSchemaViolationException( ResultCodeEnum.OBJECT_CLASS_VIOLATION, msg );
-        }
-
-        entryUuidIdx.add( entryUuid.getString(), id );
-
-        Long tempId = parentId;
-        while ( tempId != null && tempId != 0 && tempId != 1 )
-        {
-            subLevelIdx.add( tempId, id );
-            tempId = getParentId( tempId );
-        }
-
-        // making entry an ancestor/descendent of itself in sublevel index
-        subLevelIdx.add( id, id );
-
-        // Now work on the user defined userIndices
-        for ( EntryAttribute attribute : entry )
-        {
-            String attributeOid = attribute.getAttributeType().getOid();
-
-            if ( hasUserIndexOn( attributeOid ) )
-            {
-                Index<Object, E, Long> idx = ( Index<Object, E, Long> ) getUserIndex( attributeOid );
-
-                // here lookup by attributeId is OK since we got attributeId from 
-                // the entry via the enumeration - it's in there as is for sure
-
-                for ( Value<?> value : attribute )
-                {
-                    idx.add( value.get(), id );
-                }
-
-                // Adds only those attributes that are indexed
-                presenceIdx.add( attributeOid, id );
-            }
-        }
-
-        master.put( id, entry );
-    }
-
-
-    /**
-     * {@inheritDoc}
-     */
-    public int count() throws Exception
-    {
-        return master.count();
-    }
-
-
-    /**
-     * {@inheritDoc}
-     */
-    @SuppressWarnings("unchecked")
-    public void delete( Long id ) throws Exception
-    {
-        Entry entry = lookup( id );
-        Long parentId = getParentId( id );
-
-        EntryAttribute objectClass = entry.get( OBJECT_CLASS_AT );
-
-        if ( objectClass.contains( SchemaConstants.ALIAS_OC ) )
-        {
-            dropAliasIndices( id );
-        }
-
-        for ( Value<?> value : objectClass )
-        {
-            objectClassIdx.drop( value.getString(), id );
-        }
-
-        ndnIdx.drop( id );
-        oneLevelIdx.drop( id );
-        entryCsnIdx.drop( id );
-        entryUuidIdx.drop( id );
-
-        if ( id != 1 )
-        {
-            subLevelIdx.drop( id );
-        }
-
-        // Remove parent's reference to entry only if entry is not the upSuffix
-        if ( !parentId.equals( 0L ) )
-        {
-            oneLevelIdx.drop( parentId, id );
-        }
-
-        for ( EntryAttribute attribute : entry )
-        {
-            String attributeOid = attribute.getAttributeType().getOid();
-
-            if ( hasUserIndexOn( attributeOid ) )
-            {
-                Index<?, E, Long> index = getUserIndex( attributeOid );
-
-                // here lookup by attributeId is ok since we got attributeId from 
-                // the entry via the enumeration - it's in there as is for sure
-                for ( Value<?> value : attribute )
-                {
-                    ( ( AvlIndex ) index ).drop( value.get(), id );
-                }
-
-                presenceIdx.drop( attributeOid, id );
-            }
-        }
-
-        master.delete( id );
-    }
-
 
     /**
      * {@inheritDoc}
@@ -284,54 +61,6 @@ public class AvlStore<E> extends Abstrac
 
     /**
      * {@inheritDoc}
-     */
-    public int getChildCount( Long id ) throws Exception
-    {
-        return oneLevelIdx.count( id );
-    }
-
-
-    /**
-     * {@inheritDoc}
-     */
-    public DN getEntryDn( Long id ) throws Exception
-    {
-        DN dn = new DN( ndnIdx.reverseLookup( id ) );
-        dn.normalize( schemaManager.getNormalizerMapping() );
-        return dn;
-//        return ((DN)lookup( id ).getDn().clone()).normalize( schemaManager.getNormalizerMapping() );
-    }
-
-
-    /**
-     * {@inheritDoc}
-     */
-    public Long getEntryId( DN dn ) throws Exception
-    {
-        return ndnIdx.forwardLookup( dn.getNormName() );
-    }
-
-
-    /**
-     * {@inheritDoc}
-     */
-    public Long getParentId( Long childId ) throws Exception
-    {
-        return oneLevelIdx.reverseLookup( childId );
-    }
-
-
-    /**
-     * {@inheritDoc}
-     */
-    public String getProperty( String propertyName ) throws Exception
-    {
-        return master.getProperty( propertyName );
-    }
-
-
-    /**
-     * {@inheritDoc}
      * TODO why this and initRegistries on Store interface ???
      */
     public void init( SchemaManager schemaManager ) throws Exception
@@ -340,6 +69,8 @@ public class AvlStore<E> extends Abstrac
 
         OBJECT_CLASS_AT = schemaManager.lookupAttributeTypeRegistry( SchemaConstants.OBJECT_CLASS_AT );
         ALIASED_OBJECT_NAME_AT = schemaManager.lookupAttributeTypeRegistry( SchemaConstants.ALIASED_OBJECT_NAME_AT );
+        ENTRY_CSN_AT = schemaManager.lookupAttributeTypeRegistry( SchemaConstants.ENTRY_CSN_AT );
+        ENTRY_UUID_AT = schemaManager.lookupAttributeTypeRegistry( SchemaConstants.ENTRY_UUID_AT );
 
         // Create the master table (the table containing all the entries)
         master = new AvlMasterTable<Entry>( id, new LongComparator(), null, false );
@@ -355,416 +86,15 @@ public class AvlStore<E> extends Abstrac
     }
 
 
-    /**
-     * {@inheritDoc}
-     */
-    public IndexCursor<Long, E, Long> list( Long id ) throws Exception
-    {
-        IndexCursor<Long, E, Long> cursor = oneLevelIdx.forwardCursor( id );
-        cursor.beforeValue( id, null );
-        return cursor;
-    }
-
-
-    /**
-     * {@inheritDoc}
-     */
-    public Entry lookup( Long id ) throws Exception
-    {
-        return master.get( id );
-    }
-
-
-    /**
-     * Recursively modifies the distinguished name of an entry and the names of
-     * its descendants calling itself in the recursion.
-     *
-     * @param id the primary key of the entry
-     * @param updn User provided distinguished name to set as the new DN
-     * @param isMove whether or not the name change is due to a move operation
-     * which affects alias userIndices.
-     * @throws Exception if something goes wrong
-     */
-    private void modifyDn( Long id, DN updn, boolean isMove ) throws Exception
-    {
-        String aliasTarget;
-
-        // update normalized DN index
-        ndnIdx.drop( id );
-
-        if ( !updn.isNormalized() )
-        {
-            updn.normalize( schemaManager.getNormalizerMapping() );
-        }
-
-        ndnIdx.add( updn.getNormName(), id );
-
-        /* 
-         * Read Alias Index Tuples
-         * 
-         * If this is a name change due to a move operation then the one and
-         * subtree userIndices for aliases were purged before the aliases were
-         * moved.  Now we must add them for each alias entry we have moved.  
-         * 
-         * aliasTarget is used as a marker to tell us if we're moving an 
-         * alias.  If it is null then the moved entry is not an alias.
-         */
-        if ( isMove )
-        {
-            aliasTarget = aliasIdx.reverseLookup( id );
-
-            if ( null != aliasTarget )
-            {
-                addAliasIndices( id, getEntryDn( id ), aliasTarget );
-            }
-        }
-
-        Cursor<IndexEntry<Long, E, Long>> children = list( id );
-
-        while ( children.next() )
-        {
-            // Get the child and its id
-            IndexEntry<Long, E, Long> rec = children.get();
-            Long childId = rec.getId();
-
-            /* 
-             * Calculate the DN for the child's new name by copying the parents
-             * new name and adding the child's old upRdn to new name as its RDN
-             */
-            DN childUpdn = ( DN ) updn.clone();
-//            DN oldUpdn = new DN( getEntryUpdn( childId ) );
-            DN oldUpdn = getEntryDn( childId );
-
-            String rdn = oldUpdn.get( oldUpdn.size() - 1 );
-            DN rdnDN = new DN( rdn );
-            rdnDN.normalize( schemaManager.getNormalizerMapping() );
-            childUpdn.add( rdnDN.getRdn() );
-
-            // Modify the child
-            Entry entry = lookup( childId );
-            entry.setDn( childUpdn );
-            master.put( childId, entry );
-
-            // Recursively change the names of the children below
-            modifyDn( childId, childUpdn, isMove );
-        }
-
-        children.close();
-    }
-
-
-    public void modify( DN dn, ModificationOperation modOp, Entry mods ) throws Exception
-    {
-        if ( mods instanceof ClonedServerEntry )
-        {
-            throw new Exception( I18n.err( I18n.ERR_215 ) );
-        }
-
-        Long id = getEntryId( dn );
-        Entry entry = ( Entry ) master.get( id );
-
-        for ( AttributeType attributeType : mods.getAttributeTypes() )
-        {
-            EntryAttribute attr = mods.get( attributeType );
-
-            switch ( modOp )
-            {
-                case ADD_ATTRIBUTE:
-                    add( id, entry, attr );
-                    break;
-
-                case REMOVE_ATTRIBUTE:
-                    remove( id, entry, attr );
-                    break;
-
-                case REPLACE_ATTRIBUTE:
-                    replace( id, entry, attr );
-
-                    break;
-
-                default:
-                    throw new Exception( I18n.err( I18n.ERR_221 ) );
-            }
-        }
-
-        master.put( id, entry );
-    }
-
-
-    public void modify( DN dn, List<Modification> mods ) throws Exception
-    {
-        Long id = getEntryId( dn );
-        modify( id, mods );
-    }
-
-
-    public void modify( long entryId, List<Modification> mods ) throws Exception
-    {
-        Entry entry = ( Entry ) master.get( entryId );
-
-        for ( Modification mod : mods )
-        {
-            EntryAttribute attrMods = mod.getAttribute();
-
-            switch ( mod.getOperation() )
-            {
-                case ADD_ATTRIBUTE:
-                    add( entryId, entry, attrMods );
-                    break;
-
-                case REMOVE_ATTRIBUTE:
-                    remove( entryId, entry, attrMods );
-                    break;
-
-                case REPLACE_ATTRIBUTE:
-                    replace( entryId, entry, attrMods );
-                    break;
-
-                default:
-                    throw new Exception( I18n.err( I18n.ERR_221 ) );
-            }
-        }
-
-        master.put( entryId, entry );
-    }
-
-
-    public void move( DN oldChildDn, DN newParentDn, RDN newRdn, boolean deleteOldRdn ) throws Exception
-    {
-        Long childId = getEntryId( oldChildDn );
-        rename( oldChildDn, newRdn, deleteOldRdn );
-        DN newUpdn = move( oldChildDn, childId, newParentDn );
-
-        // Update the current entry
-        Entry entry = lookup( childId );
-        entry.setDn( newUpdn );
-        master.put( childId, entry );
-    }
-
-
-    public void move( DN oldChildDn, DN newParentDn ) throws Exception
-    {
-        Long childId = getEntryId( oldChildDn );
-        DN newUpdn = move( oldChildDn, childId, newParentDn );
-
-        // Update the current entry
-        Entry entry = lookup( childId );
-        entry.setDn( newUpdn );
-        master.put( childId, entry );
-    }
-
-
-    /**
-     * Moves an entry under a new parent.  The operation causes a shift in the
-     * parent child relationships between the old parent, new parent and the 
-     * child moved.  All other descendant entries under the child never change
-     * their direct parent child relationships.  Hence after the parent child
-     * relationship changes are broken at the old parent and set at the new
-     * parent a modifyDn operation is conducted to handle name changes 
-     * propagating down through the moved child and its descendants.
-     * 
-     * @param oldChildDn the normalized dn of the child to be moved
-     * @param childId the id of the child being moved
-     * @param newParentDn the normalized dn of the new parent for the child
-     * @throws Exception if something goes wrong
-     */
-    private DN move( DN oldChildDn, Long childId, DN newParentDn ) throws Exception
-    {
-        // Get the child and the new parent to be entries and Ids
-        Long newParentId = getEntryId( newParentDn );
-        Long oldParentId = getParentId( childId );
-
-        /*
-         * All aliases including and below oldChildDn, will be affected by
-         * the move operation with respect to one and subtree userIndices since
-         * their relationship to ancestors above oldChildDn will be 
-         * destroyed.  For each alias below and including oldChildDn we will
-         * drop the index tuples mapping ancestor ids above oldChildDn to the
-         * respective target ids of the aliases.
-         */
-        dropMovedAliasIndices( oldChildDn );
-
-        /*
-         * Drop the old parent child relationship and add the new one
-         * Set the new parent id for the child replacing the old parent id
-         */
-        oneLevelIdx.drop( oldParentId, childId );
-        oneLevelIdx.add( newParentId, childId );
-
-        updateSubLevelIndex( childId, oldParentId, newParentId );
-
-        /*
-         * Build the new user provided DN (updn) for the child using the child's
-         * user provided RDN & the new parent's UPDN.  Basically add the child's
-         * UpRdn String to the tail of the new parent's Updn Name.
-         */
-//        DN childUpdn = new DN( getEntryUpdn( childId ) );
-//        String childRdn = childUpdn.get( childUpdn.size() - 1 );
-//        DN newUpdn = new DN( getEntryUpdn( newParentId ) );         
-        DN childUpdn = getEntryDn( childId );
-        String childRdn = childUpdn.get( childUpdn.size() - 1 );
-        DN newUpdn = getEntryDn( newParentId );
-        newUpdn.add( newUpdn.size(), childRdn );
-
-        // Call the modifyDn operation with the new updn
-        modifyDn( childId, newUpdn, true );
-
-        return newUpdn;
-    }
-
-
-    /**
-     * Changes the relative distinguished name of an entry specified by a 
-     * distinguished name with the optional removal of the old RDN attribute
-     * value from the entry.  Name changes propagate down as dn changes to the 
-     * descendants of the entry where the RDN changed. 
-     * 
-     * An RDN change operation does not change parent child relationships.  It 
-     * merely propagates a name change at a point in the DIT where the RDN is 
-     * changed. The change propagates down the subtree rooted at the 
-     * distinguished name specified.
-     *
-     * @param dn the normalized distinguished name of the entry to alter
-     * @param newRdn the new RDN to set
-     * @param deleteOldRdn whether or not to remove the old RDN attr/val
-     * @throws Exception if there are any errors propagating the name changes
-     */
-    @SuppressWarnings("unchecked")
-    public void rename( DN dn, RDN newRdn, boolean deleteOldRdn ) throws Exception
-    {
-        Long id = getEntryId( dn );
-        Entry entry = lookup( id );
-        DN updn = entry.getDn();
-
-        /* 
-         * H A N D L E   N E W   R D N
-         * ====================================================================
-         * Add the new RDN attribute to the entry.  If an index exists on the 
-         * new RDN attribute we add the index for this attribute value pair.
-         * Also we make sure that the existance index shows the existance of the
-         * new RDN attribute within this entry.
-         */
-
-        for ( AVA newAtav : newRdn )
-        {
-            String newNormType = newAtav.getNormType();
-            Object newNormValue = newAtav.getNormValue().get();
-            AttributeType newRdnAttrType = schemaManager.lookupAttributeTypeRegistry( newNormType );
-
-            entry.add( newRdnAttrType, newAtav.getUpValue() );
-
-            if ( hasUserIndexOn( newNormType ) )
-            {
-                Index<?, E, Long> index = getUserIndex( newNormType );
-                ( ( Index ) index ).add( newNormValue, id );
-
-                // Make sure the altered entry shows the existence of the new attrib
-                if ( !presenceIdx.forward( newNormType, id ) )
-                {
-                    presenceIdx.add( newNormType, id );
-                }
-            }
-        }
-
-        /*
-         * H A N D L E   O L D   R D N
-         * ====================================================================
-         * If the old RDN is to be removed we need to get the attribute and 
-         * value for it.  Keep in mind the old RDN need not be based on the 
-         * same attr as the new one.  We remove the RDN value from the entry
-         * and remove the value/id tuple from the index on the old RDN attr
-         * if any.  We also test if the delete of the old RDN index tuple 
-         * removed all the attribute values of the old RDN using a reverse
-         * lookup.  If so that means we blew away the last value of the old 
-         * RDN attribute.  In this case we need to remove the attrName/id 
-         * tuple from the existance index.
-         * 
-         * We only remove an ATAV of the old RDN if it is not included in the
-         * new RDN.
-         */
-
-        if ( deleteOldRdn )
-        {
-            RDN oldRdn = updn.getRdn();
-            for ( AVA oldAtav : oldRdn )
-            {
-                // check if the new ATAV is part of the old RDN
-                // if that is the case we do not remove the ATAV
-                boolean mustRemove = true;
-                for ( AVA newAtav : newRdn )
-                {
-                    if ( oldAtav.equals( newAtav ) )
-                    {
-                        mustRemove = false;
-                        break;
-                    }
-                }
-
-                if ( mustRemove )
-                {
-                    String oldNormType = oldAtav.getNormType();
-                    String oldNormValue = oldAtav.getNormValue().getString();
-                    AttributeType oldRdnAttrType = schemaManager.lookupAttributeTypeRegistry( oldNormType );
-                    entry.remove( oldRdnAttrType, oldNormValue );
-
-                    if ( hasUserIndexOn( oldNormType ) )
-                    {
-                        Index<?, E, Long> index = getUserIndex( oldNormType );
-                        ( ( AvlIndex ) index ).drop( oldNormValue, id );
-
-                        /*
-                         * If there is no value for id in this index due to our
-                         * drop above we remove the oldRdnAttr from the existance idx
-                         */
-                        if ( null == index.reverseLookup( id ) )
-                        {
-                            presenceIdx.drop( oldNormType, id );
-                        }
-                    }
-                }
-            }
-        }
-
-        /*
-         * H A N D L E   D N   C H A N G E
-         * ====================================================================
-         * 1) Build the new user defined distinguished name
-         *      - clone / copy old updn
-         *      - remove old upRdn from copy
-         *      - add the new upRdn to the copy
-         * 2) Make call to recursive modifyDn method to change the names of the
-         *    entry and its descendants
-         */
-
-        DN newUpdn = ( DN ) updn.clone(); // copy da old updn
-        newUpdn.remove( newUpdn.size() - 1 ); // remove old upRdn
-        newUpdn.add( newRdn.getName() ); // add da new upRdn
-
-        // gotta normalize cuz this thang is cloned and not normalized by default
-        newUpdn.normalize( schemaManager.getNormalizerMapping() );
-
-        modifyDn( id, newUpdn, false ); // propagate dn changes
-
-        // Update the current entry
-        entry.setDn( newUpdn );
-        master.put( id, entry );
-    }
-
-
-    /**
-     * {@inheritDoc}
-     */
-    public void setProperty( String propertyName, String propertyValue ) throws Exception
-    {
-        master.setProperty( propertyName, propertyValue );
-    }
-
-
     @Override
     protected Index<?, E, Long> convertAndInit( Index<?, E, Long> index ) throws Exception
     {
         AvlIndex<?, E> avlIndex;
-        if ( index instanceof AvlIndex<?, ?> )
+        if ( index.getAttributeId().equals( ApacheSchemaConstants.APACHE_RDN_AT_OID ) )
+        {
+            avlIndex = new AvlRdnIndex<E>( index.getAttributeId() );
+        }
+        else if ( index instanceof AvlIndex<?, ?> )
         {
             avlIndex = ( AvlIndex<?, E> ) index;
         }
@@ -775,75 +105,13 @@ public class AvlStore<E> extends Abstrac
             avlIndex = new AvlIndex( index.getAttributeId() );
         }
 
-        avlIndex.initialize( schemaManager.lookupAttributeTypeRegistry( index.getAttributeId() ) );
+        avlIndex.init( schemaManager, schemaManager.lookupAttributeTypeRegistry( index.getAttributeId() ) );
 
         return avlIndex;
     }
 
 
     /**
-     * 
-     * updates the SubLevel Index as part of a move operation.
-     *
-     * @param childId child id to be moved
-     * @param oldParentId old parent's id
-     * @param newParentId new parent's id
-     * @throws Exception
-     */
-    private void updateSubLevelIndex( Long childId, Long oldParentId, Long newParentId ) throws Exception
-    {
-        Long tempId = oldParentId;
-        List<Long> parentIds = new ArrayList<Long>();
-
-        // find all the parents of the oldParentId
-        while ( tempId != 0 && tempId != 1 && tempId != null )
-        {
-            parentIds.add( tempId );
-            tempId = getParentId( tempId );
-        }
-
-        // find all the children of the childId
-        Cursor<IndexEntry<Long, E, Long>> cursor = subLevelIdx.forwardCursor( childId );
-
-        List<Long> childIds = new ArrayList<Long>();
-        childIds.add( childId );
-
-        while ( cursor.next() )
-        {
-            childIds.add( cursor.get().getId() );
-        }
-
-        // detach the childId and all its children from oldParentId and all it parents excluding the root
-        for ( Long pid : parentIds )
-        {
-            for ( Long cid : childIds )
-            {
-                subLevelIdx.drop( pid, cid );
-            }
-        }
-
-        parentIds.clear();
-        tempId = newParentId;
-
-        // find all the parents of the newParentId
-        while ( tempId != 0 && tempId != 1 && tempId != null )
-        {
-            parentIds.add( tempId );
-            tempId = getParentId( tempId );
-        }
-
-        // attach the childId and all its children to newParentId and all it parents excluding the root
-        for ( Long id : parentIds )
-        {
-            for ( Long cid : childIds )
-            {
-                subLevelIdx.add( id, cid );
-            }
-        }
-    }
-
-
-    /**
      * Always returns 0 (zero), cause this is a in-memory store
      */
     @Override
@@ -890,4 +158,20 @@ public class AvlStore<E> extends Abstrac
         return 1L;
     }
 
+
+    @Override
+    protected Long getRootId()
+    {
+        return 0L;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Index<String, E, Long> getNdnIndex()
+    {
+        // FIXME should this be entryUuidIdx?
+        return getEntryCsnIndex();
+    }
+    
 }

Added: directory/apacheds/trunk/avl-partition/src/test/java/org/apache/directory/server/core/partition/avl/AvlRdnIndexTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/avl-partition/src/test/java/org/apache/directory/server/core/partition/avl/AvlRdnIndexTest.java?rev=940073&view=auto
==============================================================================
--- directory/apacheds/trunk/avl-partition/src/test/java/org/apache/directory/server/core/partition/avl/AvlRdnIndexTest.java (added)
+++ directory/apacheds/trunk/avl-partition/src/test/java/org/apache/directory/server/core/partition/avl/AvlRdnIndexTest.java Sat May  1 16:25:19 2010
@@ -0,0 +1,335 @@
+/*
+ *  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.core.partition.avl;
+
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.fail;
+
+import java.io.File;
+import java.io.IOException;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.directory.server.constants.ApacheSchemaConstants;
+import org.apache.directory.server.xdbm.Index;
+import org.apache.directory.server.xdbm.IndexEntry;
+import org.apache.directory.server.xdbm.ParentIdAndRdn;
+import org.apache.directory.shared.ldap.cursor.Cursor;
+import org.apache.directory.shared.ldap.name.RDN;
+import org.apache.directory.shared.ldap.schema.SchemaManager;
+import org.apache.directory.shared.ldap.schema.ldif.extractor.SchemaLdifExtractor;
+import org.apache.directory.shared.ldap.schema.ldif.extractor.impl.DefaultSchemaLdifExtractor;
+import org.apache.directory.shared.ldap.schema.loader.ldif.LdifSchemaLoader;
+import org.apache.directory.shared.ldap.schema.manager.impl.DefaultSchemaManager;
+import org.apache.directory.shared.ldap.util.ExceptionUtils;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+
+/**
+ * Tests the AvlRdnIndex.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class AvlRdnIndexTest
+{
+    private static File dbFileDir;
+    Index<ParentIdAndRdn<Long>, Long, Long> idx;
+    private static SchemaManager schemaManager;
+
+
+    @BeforeClass
+    public static void init() throws Exception
+    {
+        String workingDirectory = System.getProperty( "workingDirectory" );
+
+        if ( workingDirectory == null )
+        {
+            String path = AvlRdnIndexTest.class.getResource( "" ).getPath();
+            int targetPos = path.indexOf( "target" );
+            workingDirectory = path.substring( 0, targetPos + 6 );
+        }
+
+        File schemaRepository = new File( workingDirectory, "schema" );
+        SchemaLdifExtractor extractor = new DefaultSchemaLdifExtractor( new File( workingDirectory ) );
+        extractor.extractOrCopy( true );
+        LdifSchemaLoader loader = new LdifSchemaLoader( schemaRepository );
+        schemaManager = new DefaultSchemaManager( loader );
+
+        boolean loaded = schemaManager.loadAllEnabled();
+
+        if ( !loaded )
+        {
+            fail( "Schema load failed : " + ExceptionUtils.printErrors( schemaManager.getErrors() ) );
+        }
+    }
+
+
+    @Before
+    public void setup() throws IOException
+    {
+
+        File tmpIndexFile = File.createTempFile( AvlRdnIndexTest.class.getSimpleName(), "db" );
+        tmpIndexFile.deleteOnExit();
+        dbFileDir = new File( tmpIndexFile.getParentFile(), AvlRdnIndexTest.class.getSimpleName() );
+
+        dbFileDir.mkdirs();
+    }
+
+
+    @After
+    public void teardown() throws Exception
+    {
+        destroyIndex();
+
+        if ( ( dbFileDir != null ) && dbFileDir.exists() )
+        {
+            FileUtils.deleteDirectory( dbFileDir );
+        }
+    }
+
+
+    void destroyIndex() throws Exception
+    {
+        if ( idx != null )
+        {
+            idx.sync();
+            idx.close();
+        }
+
+        idx = null;
+    }
+
+
+    void initIndex() throws Exception
+    {
+        initIndex( new AvlRdnIndex() );
+    }
+
+
+    void initIndex( AvlRdnIndex avlIdx ) throws Exception
+    {
+        if ( avlIdx == null )
+        {
+            avlIdx = new AvlRdnIndex();
+        }
+
+        avlIdx.init( schemaManager, schemaManager
+            .lookupAttributeTypeRegistry( ApacheSchemaConstants.APACHE_RDN_AT_OID ) );
+        this.idx = avlIdx;
+    }
+
+
+    // -----------------------------------------------------------------------
+    // Property Test Methods
+    // -----------------------------------------------------------------------
+
+    @Test(expected = UnsupportedOperationException.class)
+    public void testCacheSize() throws Exception
+    {
+        // uninitialized index
+        AvlRdnIndex AvlRdnIndex = new AvlRdnIndex();
+        AvlRdnIndex.setCacheSize( 337 );
+    }
+
+
+    @Test(expected = UnsupportedOperationException.class)
+    public void testWkDirPath() throws Exception
+    {
+        // uninitialized index
+        AvlRdnIndex AvlRdnIndex = new AvlRdnIndex();
+        AvlRdnIndex.setWkDirPath( new File( dbFileDir, "foo" ) );
+    }
+
+
+    @Test
+    public void testGetAttribute() throws Exception
+    {
+        // uninitialized index
+        AvlRdnIndex rdnIndex = new AvlRdnIndex();
+        assertNull( rdnIndex.getAttribute() );
+
+        initIndex();
+        assertEquals( schemaManager.lookupAttributeTypeRegistry( ApacheSchemaConstants.APACHE_RDN_AT ), idx
+            .getAttribute() );
+    }
+
+
+    @Test
+    public void testIsCountExact() throws Exception
+    {
+        assertFalse( new AvlRdnIndex().isCountExact() );
+    }
+
+
+    // -----------------------------------------------------------------------
+    // Count Test Methods
+    // -----------------------------------------------------------------------
+
+    @Test
+    public void testCount() throws Exception
+    {
+        initIndex();
+        assertEquals( 0, idx.count() );
+
+        ParentIdAndRdn<Long> key = new ParentIdAndRdn<Long>( 0L, new RDN( "cn=key" ) );
+
+        idx.add( key, 0l );
+        assertEquals( 1, idx.count() );
+
+        // setting a different parentId should make this key a different key
+        key = new ParentIdAndRdn<Long>( 1L, new RDN( "cn=key" ) );
+
+        idx.add( key, 1l );
+        assertEquals( 2, idx.count() );
+
+        //count shouldn't get affected cause of inserting the same key
+        idx.add( key, 2l );
+        assertEquals( 2, idx.count() );
+
+        key = new ParentIdAndRdn<Long>( 2L, new RDN( "cn=key" ) );
+        idx.add( key, 3l );
+        assertEquals( 3, idx.count() );
+    }
+
+
+    @Test
+    public void testCountOneArg() throws Exception
+    {
+        initIndex();
+
+        ParentIdAndRdn<Long> key = new ParentIdAndRdn<Long>( 0L, new RDN( "cn=key" ) );
+
+        assertEquals( 0, idx.count( key ) );
+
+        idx.add( key, 0l );
+        assertEquals( 1, idx.count( key ) );
+    }
+
+
+    // -----------------------------------------------------------------------
+    // Add, Drop and Lookup Test Methods
+    // -----------------------------------------------------------------------
+
+    @Test
+    public void testLookups() throws Exception
+    {
+        initIndex();
+
+        ParentIdAndRdn<Long> key = new ParentIdAndRdn<Long>( 0L, new RDN( "cn=key" ) );
+
+        assertNull( idx.forwardLookup( key ) );
+
+        idx.add( key, 0l );
+        assertEquals( 0, ( long ) idx.forwardLookup( key ) );
+        assertEquals( key, idx.reverseLookup( 0l ) );
+    }
+
+
+    @Test
+    public void testAddDropById() throws Exception
+    {
+        initIndex();
+
+        ParentIdAndRdn<Long> key = new ParentIdAndRdn<Long>( 0L, new RDN( "cn=key" ) );
+
+        assertNull( idx.forwardLookup( key ) );
+
+        // test add/drop without adding any duplicates
+        idx.add( key, 0l );
+        assertEquals( 0, ( long ) idx.forwardLookup( key ) );
+
+        idx.drop( key, 0l );
+        assertNull( idx.forwardLookup( key ) );
+        assertNull( idx.reverseLookup( 0l ) );
+    }
+
+
+    // -----------------------------------------------------------------------
+    // Miscellaneous Test Methods
+    // -----------------------------------------------------------------------
+
+    @Test
+    public void testCursors() throws Exception
+    {
+        initIndex();
+
+        ParentIdAndRdn<Long> key = new ParentIdAndRdn<Long>( 0L, new RDN( "cn=key" ) );
+
+        assertEquals( 0, idx.count() );
+
+        idx.add( key, 0l );
+        assertEquals( 1, idx.count() );
+
+        for ( long i = 1; i < 5; i++ )
+        {
+            key = new ParentIdAndRdn<Long>( i, new RDN( "cn=key" + i ) );
+
+            idx.add( key, ( long ) i );
+        }
+
+        assertEquals( 5, idx.count() );
+
+        // use forward index's cursor
+        Cursor<IndexEntry<ParentIdAndRdn<Long>, Long, Long>> cursor = idx.forwardCursor();
+        cursor.beforeFirst();
+
+        cursor.next();
+        IndexEntry<ParentIdAndRdn<Long>, Long, Long> e1 = cursor.get();
+        assertEquals( 0, ( long ) e1.getId() );
+        assertEquals( "cn=key", e1.getValue().getRdns()[0].getName() );
+        assertEquals( 0, e1.getValue().getParentId().longValue() );
+
+        cursor.next();
+        IndexEntry<ParentIdAndRdn<Long>, Long, Long> e2 = cursor.get();
+        assertEquals( 1, ( long ) e2.getId() );
+        assertEquals( "cn=key1", e2.getValue().getRdns()[0].getName() );
+        assertEquals( 1, e2.getValue().getParentId().longValue() );
+
+        cursor.next();
+        IndexEntry<ParentIdAndRdn<Long>, Long, Long> e3 = cursor.get();
+        assertEquals( 2, ( long ) e3.getId() );
+        assertEquals( "cn=key2", e3.getValue().getRdns()[0].getName() );
+        assertEquals( 2, e3.getValue().getParentId().longValue() );
+    }
+
+    //    @Test
+    //    public void testStoreRdnWithTwoATAVs() throws Exception
+    //    {
+    //        initIndex();
+    //        
+    //        DN dn = new DN( "dc=example,dc=com" );
+    //        dn.normalize( schemaManager.getNormalizerMapping() );
+    //        
+    //        RDN rdn = new RDN( dn.getName() );
+    //        rdn._setParentId( 1 );
+    //        idx.add( rdn, 0l );
+    //        
+    //        RDN rdn2 = idx.reverseLookup( 0l );
+    //        System.out.println( rdn2 );
+    //        InternalRdnComparator rdnCom = new InternalRdnComparator( "" );
+    //        assertEquals( 0, rdnCom.compare( rdn, rdn2 ) );
+    //    }
+}

Modified: directory/apacheds/trunk/avl-partition/src/test/java/org/apache/directory/server/core/partition/avl/AvlStoreTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/avl-partition/src/test/java/org/apache/directory/server/core/partition/avl/AvlStoreTest.java?rev=940073&r1=940072&r2=940073&view=diff
==============================================================================
--- directory/apacheds/trunk/avl-partition/src/test/java/org/apache/directory/server/core/partition/avl/AvlStoreTest.java (original)
+++ directory/apacheds/trunk/avl-partition/src/test/java/org/apache/directory/server/core/partition/avl/AvlStoreTest.java Sat May  1 16:25:19 2010
@@ -48,10 +48,10 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.entry.DefaultEntry;
 import org.apache.directory.shared.ldap.entry.DefaultEntryAttribute;
 import org.apache.directory.shared.ldap.entry.DefaultModification;
+import org.apache.directory.shared.ldap.entry.Entry;
 import org.apache.directory.shared.ldap.entry.EntryAttribute;
 import org.apache.directory.shared.ldap.entry.Modification;
 import org.apache.directory.shared.ldap.entry.ModificationOperation;
-import org.apache.directory.shared.ldap.entry.Entry;
 import org.apache.directory.shared.ldap.exception.LdapNoSuchObjectException;
 import org.apache.directory.shared.ldap.exception.LdapSchemaViolationException;
 import org.apache.directory.shared.ldap.name.DN;
@@ -175,13 +175,13 @@ public class AvlStoreTest
         store.setId( "foo" );
         assertEquals( "foo", store.getId() );
 
-        assertNull( store.getNdnIndex() );
-        store.addIndex( new AvlIndex<String, Attributes>( ApacheSchemaConstants.APACHE_N_DN_AT_OID ) );
-        assertNotNull( store.getNdnIndex() );
+        assertNull( store.getRdnIndex() );
+        store.addIndex( new AvlRdnIndex( ApacheSchemaConstants.APACHE_RDN_AT_OID ) );
+        assertNotNull( store.getRdnIndex() );
 
         assertNull( store.getOneAliasIndex() );
         store.addIndex( new AvlIndex<Long, Attributes>( ApacheSchemaConstants.APACHE_ONE_ALIAS_AT_OID ) );
-        assertNotNull( store.getNdnIndex() );
+        assertNotNull( store.getOneAliasIndex() );
 
         assertNull( store.getSubAliasIndex() );
         store.addIndex( new AvlIndex<Long, Attributes>( ApacheSchemaConstants.APACHE_SUB_ALIAS_AT_OID ) );
@@ -267,9 +267,11 @@ public class AvlStoreTest
         }
 
         assertNotNull( store.getNdnIndex() );
+
+        assertNotNull( store.getRdnIndex() );
         try
         {
-            store.addIndex( new AvlIndex<String, Entry>( ApacheSchemaConstants.APACHE_N_DN_AT_OID ) );
+            store.addIndex( new AvlRdnIndex( ApacheSchemaConstants.APACHE_RDN_AT_OID ) );
             fail();
         }
         catch ( IllegalStateException e )
@@ -388,9 +390,9 @@ public class AvlStoreTest
         dn.normalize( schemaManager.getNormalizerMapping() );
         assertEquals( 1L, ( long ) store.getEntryId( dn ) );
         assertEquals( 11, store.count() );
-//        assertEquals( "o=Good Times Co.", store.getEntryDn( 1L ).getName() );
-//        assertEquals( dn.getNormName(), store.getEntryDn( 1L ).getNormName() );
-//        assertEquals( dn.getName(), store.getEntryDn( 1L ).getName() );
+        //        assertEquals( "o=Good Times Co.", store.getEntryDn( 1L ).getName() );
+        //        assertEquals( dn.getNormName(), store.getEntryDn( 1L ).getNormName() );
+        //        assertEquals( dn.getName(), store.getEntryDn( 1L ).getName() );
 
         // note that the suffix entry returns 0 for it's parent which does not exist
         assertEquals( 0L, ( long ) store.getParentId( store.getEntryId( dn ) ) );

Modified: directory/apacheds/trunk/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmStore.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmStore.java?rev=940073&r1=940072&r2=940073&view=diff
==============================================================================
--- directory/apacheds/trunk/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmStore.java (original)
+++ directory/apacheds/trunk/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmStore.java Sat May  1 16:25:19 2010
@@ -30,29 +30,12 @@ import jdbm.recman.BaseRecordManager;
 import jdbm.recman.CacheRecordManager;
 
 import org.apache.directory.server.constants.ApacheSchemaConstants;
-import org.apache.directory.server.core.entry.ClonedServerEntry;
 import org.apache.directory.server.i18n.I18n;
 import org.apache.directory.server.xdbm.AbstractStore;
 import org.apache.directory.server.xdbm.Index;
-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.shared.ldap.MultiException;
 import org.apache.directory.shared.ldap.constants.SchemaConstants;
-import org.apache.directory.shared.ldap.cursor.Cursor;
 import org.apache.directory.shared.ldap.entry.Entry;
-import org.apache.directory.shared.ldap.entry.EntryAttribute;
-import org.apache.directory.shared.ldap.entry.Modification;
-import org.apache.directory.shared.ldap.entry.ModificationOperation;
-import org.apache.directory.shared.ldap.entry.Value;
-import org.apache.directory.shared.ldap.exception.LdapException;
-import org.apache.directory.shared.ldap.exception.LdapNoSuchObjectException;
-import org.apache.directory.shared.ldap.exception.LdapSchemaViolationException;
-import org.apache.directory.shared.ldap.message.ResultCodeEnum;
-import org.apache.directory.shared.ldap.name.AVA;
-import org.apache.directory.shared.ldap.name.DN;
-import org.apache.directory.shared.ldap.name.RDN;
-import org.apache.directory.shared.ldap.schema.AttributeType;
 import org.apache.directory.shared.ldap.schema.SchemaManager;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -66,15 +49,6 @@ public class JdbmStore<E> extends Abstra
     /** the JDBM record manager used by this database */
     private RecordManager recMan;
 
-    /** the master table storing entries by primary key */
-    private JdbmMasterTable<Entry> master;
-
-    /** Static declarations to avoid lookup all over the code */
-    private static AttributeType OBJECT_CLASS_AT;
-    private static AttributeType ENTRY_CSN_AT;
-    private static AttributeType ENTRY_UUID_AT;
-    private static AttributeType ALIASED_OBJECT_NAME_AT;
-
 
     // ------------------------------------------------------------------------
     // C O N S T R U C T O R S
@@ -94,6 +68,12 @@ public class JdbmStore<E> extends Abstra
     {
         return 1L;
     };
+    
+    @Override
+    protected Long getRootId()
+    {
+        return 0L;
+    }
 
 
     /**
@@ -244,7 +224,7 @@ public class JdbmStore<E> extends Abstra
 
         rdnIdx.sync();
 
-        master.sync();
+        ( ( JdbmMasterTable<Entry> ) master ).sync();
         recMan.commit();
     }
 
@@ -295,805 +275,26 @@ public class JdbmStore<E> extends Abstra
     }
 
 
-    /**
-     * @see #getEntryId(DN)
-     */
-    public Long getEntryId( DN dn ) throws Exception
-    {
-        if ( !dn.isNormalized() )
-        {
-            dn.normalize( schemaManager.getNormalizerMapping() );
-        }
-
-        int dnSize = dn.size();
-        int i = suffixDn.size();
-
-        ParentIdAndRdn<Long> key = new ParentIdAndRdn<Long>( 0L, suffixDn.getRdns() );
-
-        Long curEntryId = rdnIdx.forwardLookup( key );
-
-        for ( ; i < dnSize; i++ )
-        {
-            key = new ParentIdAndRdn<Long>( curEntryId, dn.getRdn( i ) );
-            curEntryId = rdnIdx.forwardLookup( key );
-            if ( curEntryId == null )
-            {
-                break;
-            }
-        }
-
-        return curEntryId;
-    }
-
-
-    /**
-     * gives the normalized name of the DN of the entry identified by the given id
-     * @param id the entry's id 
-     */
-    public DN getEntryDn( Long id ) throws Exception
-    {
-        return buildEntryDn( id );
-    }
-
-
-    /**
-     * builds the DN of the entry identified by the given id
-     *
-     * @param id the entry's id
-     * @return the normalized DN of the entry
-     * @throws Exception
-     */
-    private DN buildEntryDn( Long id ) throws Exception
-    {
-        DN dn = new DN();
-
-        long parentId = id.longValue();
-
-        do
-        {
-            ParentIdAndRdn<Long> cur = rdnIdx.reverseLookup( parentId );
-            RDN[] rdns = cur.getRdns();
-            for ( RDN rdn : rdns )
-            {
-                dn.addNormalizedInOrder( rdn );
-            }
-            parentId = cur.getParentId();
-        }
-        while ( parentId != 0 );
-
-        return dn;
-    }
-
-
-    /**
-     * 
-     * contructs a normalized DN using the RDN index. This is useful
-     * to identify in cases like finding the parent entry's id
-     * (cause that will be stored in the RDN of the entry identified by the given DN in string form)
-     *
-     * @param dn the DN of the entry in string form
-     * @return DN object build after fetching all the RDNs from RDN index
-     * @throws Exception
-     */
-    private DN buildEntryDn( String dn ) throws Exception
-    {
-        // TODO: what is this for???
-        DN normDN = new DN( dn );
-        normDN.normalize( schemaManager.getNormalizerMapping() );
-
-        int dnSize = normDN.size();
-        int i = suffixDn.size();
-
-        ParentIdAndRdn<Long> key = new ParentIdAndRdn<Long>( 0L, suffixDn.getRdns() );
-
-        Long curEntryId = rdnIdx.forwardLookup( key );
-
-        for ( ; i < dnSize; i++ )
-        {
-            key = new ParentIdAndRdn<Long>( curEntryId, normDN.getRdn( i ) );
-            curEntryId = rdnIdx.forwardLookup( key );
-        }
-
-        return normDN;
-    }
-
-
-    public Long getParentId( Long childId ) throws Exception
-    {
-        ParentIdAndRdn<Long> key = rdnIdx.reverseLookup( childId );
-        if ( key == null )
-        {
-            return null;
-        }
-
-        return key.getParentId();
-    }
-
-
-    public int count() throws Exception
-    {
-        return master.count();
-    }
-
-
-    /**
-     * {@inheritDoc}
-     * TODO : We should be able to revert all the changes made to index 
-     * if something went wrong. Also the index should auto-repair : if
-     * an entry does not exist in the Master table, then the index must be updated to reflect this.
-     */
-    @SuppressWarnings("unchecked")
-    public synchronized void add( Entry entry ) throws Exception
-    {
-        if ( entry instanceof ClonedServerEntry )
-        {
-            throw new Exception( I18n.err( I18n.ERR_215 ) );
-        }
-
-        Long parentId;
-        Long id = master.getNextId();
-
-        //
-        // Suffix entry cannot have a parent since it is the root so it is 
-        // capped off using the zero value which no entry can have since 
-        // entry sequences start at 1.
-        //
-        DN entryDn = entry.getDn();
-        DN parentDn = null;
-        ParentIdAndRdn<Long> key = null;
-
-        if ( entryDn.equals( suffixDn ) )
-        {
-            parentId = 0L;
-            key = new ParentIdAndRdn<Long>( parentId, suffixDn.getRdns() );
-        }
-        else
-        {
-            parentDn = entryDn.getParent();
-            parentId = getEntryId( parentDn );
-            key = new ParentIdAndRdn<Long>( parentId, entryDn.getRdn() );
-        }
-
-        // don't keep going if we cannot find the parent Id
-        if ( parentId == null )
-        {
-            throw new LdapNoSuchObjectException( I18n.err( I18n.ERR_216, parentDn ) );
-        }
-
-        rdnIdx.add( key, id );
-
-        EntryAttribute objectClass = entry.get( OBJECT_CLASS_AT );
-
-        if ( objectClass == null )
-        {
-            String msg = I18n.err( I18n.ERR_217, entryDn.getName(), entry );
-            ResultCodeEnum rc = ResultCodeEnum.OBJECT_CLASS_VIOLATION;
-            LdapSchemaViolationException e = new LdapSchemaViolationException( rc, msg );
-            //e.setResolvedName( entryDn );
-            throw e;
-        }
-
-        // Start adding the system userIndices
-        // Why bother doing a lookup if this is not an alias.
-        // First, the ObjectClass index
-        for ( Value<?> value : objectClass )
-        {
-            objectClassIdx.add( value.getString(), id );
-        }
-
-        if ( objectClass.contains( SchemaConstants.ALIAS_OC ) )
-        {
-            EntryAttribute aliasAttr = entry.get( ALIASED_OBJECT_NAME_AT );
-            addAliasIndices( id, entryDn, aliasAttr.getString() );
-        }
-
-        if ( !Character.isDigit( entryDn.getNormName().charAt( 0 ) ) )
-        {
-            throw new IllegalStateException( I18n.err( I18n.ERR_218, entryDn.getNormName() ) );
-        }
-
-        oneLevelIdx.add( parentId, id );
-
-        // Update the EntryCsn index
-        EntryAttribute entryCsn = entry.get( ENTRY_CSN_AT );
-
-        if ( entryCsn == null )
-        {
-            String msg = I18n.err( I18n.ERR_219, entryDn.getName(), entry );
-            throw new LdapSchemaViolationException( ResultCodeEnum.OBJECT_CLASS_VIOLATION, msg );
-        }
-
-        entryCsnIdx.add( entryCsn.getString(), id );
-
-        // Update the EntryUuid index
-        EntryAttribute entryUuid = entry.get( ENTRY_UUID_AT );
-
-        if ( entryUuid == null )
-        {
-            String msg = I18n.err( I18n.ERR_220, entryDn.getName(), entry );
-            throw new LdapSchemaViolationException( ResultCodeEnum.OBJECT_CLASS_VIOLATION, msg );
-        }
-
-        entryUuidIdx.add( entryUuid.getString(), id );
-
-        Long tempId = parentId;
-
-        while ( ( tempId != null ) && ( tempId != 0 ) && ( tempId != 1 ) )
-        {
-            subLevelIdx.add( tempId, id );
-            tempId = getParentId( tempId );
-        }
-
-        // making entry an ancestor/descendent of itself in sublevel index
-        subLevelIdx.add( id, id );
-
-        // Now work on the user defined userIndices
-        for ( EntryAttribute attribute : entry )
-        {
-            String attributeOid = attribute.getAttributeType().getOid();
-
-            if ( hasUserIndexOn( attributeOid ) )
-            {
-                Index<Object, E, Long> idx = ( Index<Object, E, Long> ) getUserIndex( attributeOid );
-
-                // here lookup by attributeId is OK since we got attributeId from 
-                // the entry via the enumeration - it's in there as is for sure
-
-                for ( Value<?> value : attribute )
-                {
-                    idx.add( value.get(), id );
-                }
-
-                // Adds only those attributes that are indexed
-                presenceIdx.add( attributeOid, id );
-            }
-        }
-
-        master.put( id, entry );
-
-        if ( isSyncOnWrite )
-        {
-            sync();
-        }
-    }
-
-
-    /**
-     * {@inheritDoc}
-     */
-    public Entry lookup( Long id ) throws Exception
-    {
-        Entry entry = ( Entry ) master.get( id );
-
-        if ( entry != null )
-        {
-            DN dn = buildEntryDn( id );
-            entry.setDn( dn );
-            
-            return entry;
-        }
-
-        return null;
-    }
-
-
-    /**
-     * {@inheritDoc}
-     */
-    public synchronized void delete( Long id ) throws Exception
-    {
-        Entry entry = master.get( id );
-        Long parentId = getParentId( id );
-
-        EntryAttribute objectClass = entry.get( OBJECT_CLASS_AT );
-
-        if ( objectClass.contains( SchemaConstants.ALIAS_OC ) )
-        {
-            dropAliasIndices( id );
-        }
-
-        for ( Value<?> value : objectClass )
-        {
-            objectClassIdx.drop( value.getString(), id );
-        }
-
-        rdnIdx.drop( id );
-        oneLevelIdx.drop( id );
-        entryCsnIdx.drop( id );
-        entryUuidIdx.drop( id );
-
-        if ( id != 1 )
-        {
-            subLevelIdx.drop( id );
-        }
-
-        // Remove parent's reference to entry only if entry is not the upSuffix
-        if ( !parentId.equals( 0L ) )
-        {
-            oneLevelIdx.drop( parentId, id );
-        }
-
-        for ( EntryAttribute attribute : entry )
-        {
-            String attributeOid = attribute.getAttributeType().getOid();
-
-            if ( hasUserIndexOn( attributeOid ) )
-            {
-                Index<?, E, Long> index = getUserIndex( attributeOid );
-
-                // here lookup by attributeId is ok since we got attributeId from 
-                // the entry via the enumeration - it's in there as is for sure
-                for ( Value<?> value : attribute )
-                {
-                    ( ( JdbmIndex ) index ).drop( value.get(), id );
-                }
-
-                presenceIdx.drop( attributeOid, id );
-            }
-        }
-
-        master.delete( id );
-
-        if ( isSyncOnWrite )
-        {
-            sync();
-        }
-    }
-
-
-    /**
-     * Gets an IndexEntry Cursor over the child nodes of an entry.
-     *
-     * @param id the id of the parent entry
-     * @return an IndexEntry Cursor over the child entries
-     * @throws Exception on failures to access the underlying store
-     */
-    public IndexCursor<Long, E, Long> list( Long id ) throws Exception
-    {
-        IndexCursor<Long, E, Long> cursor = oneLevelIdx.forwardCursor( id );
-        cursor.beforeValue( id, null );
-        return cursor;
-    }
 
 
-    public int getChildCount( Long id ) throws Exception
-    {
-        return oneLevelIdx.count( id );
-    }
 
 
-    public void setProperty( String propertyName, String propertyValue ) throws Exception
-    {
-        master.setProperty( propertyName, propertyValue );
-    }
 
 
-    public String getProperty( String propertyName ) throws Exception
-    {
-        return master.getProperty( propertyName );
-    }
 
 
-    public void modify( DN dn, ModificationOperation modOp, Entry mods ) throws Exception
-    {
-        if ( mods instanceof ClonedServerEntry )
-        {
-            throw new Exception( I18n.err( I18n.ERR_215 ) );
-        }
 
-        Long id = getEntryId( dn );
-        Entry entry = ( Entry ) master.get( id );
 
-        for ( AttributeType attributeType : mods.getAttributeTypes() )
-        {
-            EntryAttribute attr = mods.get( attributeType );
 
-            switch ( modOp )
-            {
-                case ADD_ATTRIBUTE:
-                    add( id, entry, attr );
-                    break;
 
-                case REMOVE_ATTRIBUTE:
-                    remove( id, entry, attr );
-                    break;
 
-                case REPLACE_ATTRIBUTE:
-                    replace( id, entry, attr );
 
-                    break;
 
-                default:
-                    throw new LdapException( I18n.err( I18n.ERR_221 ) );
-            }
-        }
 
-        master.put( id, entry );
-
-        if ( isSyncOnWrite )
-        {
-            sync();
-        }
-    }
-
-
-    public void modify( DN dn, List<Modification> mods ) throws Exception
-    {
-        Long id = getEntryId( dn );
-        Entry entry = ( Entry ) master.get( id );
-
-        for ( Modification mod : mods )
-        {
-            EntryAttribute attrMods = mod.getAttribute();
-
-            switch ( mod.getOperation() )
-            {
-                case ADD_ATTRIBUTE:
-                    add( id, entry, attrMods );
-                    break;
-
-                case REMOVE_ATTRIBUTE:
-                    remove( id, entry, attrMods );
-                    break;
-
-                case REPLACE_ATTRIBUTE:
-                    replace( id, entry, attrMods );
-                    break;
-
-                default:
-                    throw new LdapException( I18n.err( I18n.ERR_221 ) );
-            }
-        }
-
-        master.put( id, entry );
-
-        if ( isSyncOnWrite )
-        {
-            sync();
-        }
-    }
 
 
-    /**
-     * Changes the relative distinguished name of an entry specified by a 
-     * distinguished name with the optional removal of the old RDN attribute
-     * value from the entry.  Name changes propagate down as dn changes to the 
-     * descendants of the entry where the RDN changed. 
-     * 
-     * An RDN change operation does not change parent child relationships.  It 
-     * merely propagates a name change at a point in the DIT where the RDN is 
-     * changed. The change propagates down the subtree rooted at the 
-     * distinguished name specified.
-     *
-     * @param dn the normalized distinguished name of the entry to alter
-     * @param newRdn the new RDN to set
-     * @param deleteOldRdn whether or not to remove the old RDN attr/val
-     * @throws Exception if there are any errors propagating the name changes
-     */
-    @SuppressWarnings("unchecked")
-    public void rename( DN dn, RDN newRdn, boolean deleteOldRdn ) throws Exception
-    {
-        Long id = getEntryId( dn );
-        Entry entry = lookup( id );
-        DN updn = entry.getDn();
-        
-        newRdn.normalize( schemaManager.getNormalizerMapping() );
-
-        /* 
-         * H A N D L E   N E W   R D N
-         * ====================================================================
-         * Add the new RDN attribute to the entry.  If an index exists on the 
-         * new RDN attribute we add the index for this attribute value pair.
-         * Also we make sure that the presence index shows the existence of the
-         * new RDN attribute within this entry.
-         */
-
-        for ( AVA newAtav : newRdn )
-        {
-            String newNormType = newAtav.getNormType();
-            Object newNormValue = newAtav.getNormValue().get();
-            AttributeType newRdnAttrType = schemaManager.lookupAttributeTypeRegistry( newNormType );
-
-            entry.add( newRdnAttrType, newAtav.getUpValue() );
-
-            if ( hasUserIndexOn( newNormType ) )
-            {
-                Index<?, E, Long> index = getUserIndex( newNormType );
-                ( ( JdbmIndex ) index ).add( newNormValue, id );
-
-                // Make sure the altered entry shows the existence of the new attrib
-                if ( !presenceIdx.forward( newNormType, id ) )
-                {
-                    presenceIdx.add( newNormType, id );
-                }
-            }
-        }
-
-        /*
-         * H A N D L E   O L D   R D N
-         * ====================================================================
-         * If the old RDN is to be removed we need to get the attribute and 
-         * value for it.  Keep in mind the old RDN need not be based on the 
-         * same attr as the new one.  We remove the RDN value from the entry
-         * and remove the value/id tuple from the index on the old RDN attr
-         * if any.  We also test if the delete of the old RDN index tuple 
-         * removed all the attribute values of the old RDN using a reverse
-         * lookup.  If so that means we blew away the last value of the old 
-         * RDN attribute.  In this case we need to remove the attrName/id 
-         * tuple from the presence index.
-         * 
-         * We only remove an ATAV of the old RDN if it is not included in the
-         * new RDN.
-         */
-
-        if ( deleteOldRdn )
-        {
-            RDN oldRdn = updn.getRdn();
-            for ( AVA oldAtav : oldRdn )
-            {
-                // check if the new ATAV is part of the old RDN
-                // if that is the case we do not remove the ATAV
-                boolean mustRemove = true;
-                for ( AVA newAtav : newRdn )
-                {
-                    if ( oldAtav.equals( newAtav ) )
-                    {
-                        mustRemove = false;
-                        break;
-                    }
-                }
-
-                if ( mustRemove )
-                {
-                    String oldNormType = oldAtav.getNormType();
-                    String oldNormValue = oldAtav.getNormValue().getString();
-                    AttributeType oldRdnAttrType = schemaManager.lookupAttributeTypeRegistry( oldNormType );
-                    entry.remove( oldRdnAttrType, oldNormValue );
-
-                    if ( hasUserIndexOn( oldNormType ) )
-                    {
-                        Index<?, E, Long> index = getUserIndex( oldNormType );
-                        ( ( JdbmIndex ) index ).drop( oldNormValue, id );
-
-                        /*
-                         * If there is no value for id in this index due to our
-                         * drop above we remove the oldRdnAttr from the presence idx
-                         */
-                        if ( null == index.reverseLookup( id ) )
-                        {
-                            presenceIdx.drop( oldNormType, id );
-                        }
-                    }
-                }
-            }
-        }
 
-        /*
-         * H A N D L E   D N   C H A N G E
-         * ====================================================================
-         * We only need to update the RDN index.
-         * No need to calculate the new DN.
-         */
-
-        Long parentId = getParentId( id );
-        rdnIdx.drop( id );
-        ParentIdAndRdn<Long> key = new ParentIdAndRdn<Long>( parentId, newRdn );
-        rdnIdx.add( key, id );
+    
 
-        master.put( id, entry );
-
-        if ( isSyncOnWrite )
-        {
-            sync();
-        }
-    }
-
-
-    /*
-     * The move operation severs a child from a parent creating a new parent
-     * child relationship.  As a consequence the relationships between the 
-     * old ancestors of the child and its descendants change.  A descendant is
-     *   
-     */
-
-    /**
-     * Recursively modifies the distinguished name of an entry and the names of
-     * its descendants calling itself in the recursion.
-     *
-     * @param id the primary key of the entry
-     * @param updn User provided distinguished name to set as the new DN
-     * @param isMove whether or not the name change is due to a move operation
-     * which affects alias userIndices.
-     * @throws Exception if something goes wrong
-     */
-    private void modifyDn( Long id, DN updn, boolean isMove ) throws Exception
-    {
-        String aliasTarget;
-
-        //updated the RDN index
-        rdnIdx.drop( id );
-        if ( !updn.isNormalized() )
-        {
-            // just normalize the RDN alone
-            updn.getRdn().normalize( schemaManager.getNormalizerMapping() );
-        }
-
-        Long parentId = getEntryId( updn.getParent() );
-        ParentIdAndRdn<Long> key = new ParentIdAndRdn<Long>( parentId, updn.getRdn() );
-        rdnIdx.add( key, id );
-
-        /* 
-         * Read Alias Index Tuples
-         * 
-         * If this is a name change due to a move operation then the one and
-         * subtree userIndices for aliases were purged before the aliases were
-         * moved.  Now we must add them for each alias entry we have moved.  
-         * 
-         * aliasTarget is used as a marker to tell us if we're moving an 
-         * alias.  If it is null then the moved entry is not an alias.
-         */
-        if ( isMove )
-        {
-            aliasTarget = aliasIdx.reverseLookup( id );
-
-            if ( null != aliasTarget )
-            {
-                addAliasIndices( id, buildEntryDn( id ), aliasTarget );
-            }
-        }
-    }
-
-
-    public void move( DN oldChildDn, DN newParentDn, RDN newRdn, boolean deleteOldRdn ) throws Exception
-    {
-        Long childId = getEntryId( oldChildDn );
-        rename( oldChildDn, newRdn, deleteOldRdn );
-        DN newUpdn = move( oldChildDn, childId, newParentDn );
-
-        // Update the current entry
-        Entry entry = master.get( childId );
-        entry.setDn( newUpdn );
-        master.put( childId, entry );
-
-        if ( isSyncOnWrite )
-        {
-            sync();
-        }
-    }
-
-
-    public void move( DN oldChildDn, DN newParentDn ) throws Exception
-    {
-        Long childId = getEntryId( oldChildDn );
-        DN newUpdn = move( oldChildDn, childId, newParentDn );
-
-        // Update the current entry
-        Entry entry = master.get( childId );
-        entry.setDn( newUpdn );
-        master.put( childId, entry );
-
-        if ( isSyncOnWrite )
-        {
-            sync();
-        }
-    }
-
-
-    /**
-     * Moves an entry under a new parent.  The operation causes a shift in the
-     * parent child relationships between the old parent, new parent and the 
-     * child moved.  All other descendant entries under the child never change
-     * their direct parent child relationships.  Hence after the parent child
-     * relationship changes are broken at the old parent and set at the new
-     * parent a modifyDn operation is conducted to handle name changes 
-     * propagating down through the moved child and its descendants.
-     * 
-     * @param oldChildDn the normalized dn of the child to be moved
-     * @param childId the id of the child being moved
-     * @param newParentDn the normalized dn of the new parent for the child
-     * @throws Exception if something goes wrong
-     */
-    private DN move( DN oldChildDn, Long childId, DN newParentDn ) throws Exception
-    {
-        // Get the child and the new parent to be entries and Ids
-        Long newParentId = getEntryId( newParentDn );
-        Long oldParentId = getParentId( childId );
-
-        /*
-         * All aliases including and below oldChildDn, will be affected by
-         * the move operation with respect to one and subtree userIndices since
-         * their relationship to ancestors above oldChildDn will be 
-         * destroyed.  For each alias below and including oldChildDn we will
-         * drop the index tuples mapping ancestor ids above oldChildDn to the
-         * respective target ids of the aliases.
-         */
-        dropMovedAliasIndices( oldChildDn );
-
-        /*
-         * Drop the old parent child relationship and add the new one
-         * Set the new parent id for the child replacing the old parent id
-         */
-        oneLevelIdx.drop( oldParentId, childId );
-        oneLevelIdx.add( newParentId, childId );
-
-        updateSubLevelIndex( childId, oldParentId, newParentId );
-
-        /*
-         * Build the new user provided DN (updn) for the child using the child's
-         * user provided RDN & the new parent's UPDN.  Basically add the child's
-         * UpRdn String to the tail of the new parent's Updn Name.
-         */
-        DN childUpdn = buildEntryDn( childId );
-        RDN childRdn = childUpdn.getRdn( childUpdn.size() - 1 );
-        DN newUpdn = buildEntryDn( newParentId );
-        newUpdn.add( childRdn );
-
-        // Call the modifyDn operation with the new updn
-        modifyDn( childId, newUpdn, true );
-
-        return newUpdn;
-    }
-
-
-    /**
-     * 
-     * updates the SubLevel Index as part of a move operation.
-     *
-     * @param childId child id to be moved
-     * @param oldParentId old parent's id
-     * @param newParentId new parent's id
-     * @throws Exception
-     */
-    private void updateSubLevelIndex( Long childId, Long oldParentId, Long newParentId ) throws Exception
-    {
-        Long tempId = oldParentId;
-        List<Long> parentIds = new ArrayList<Long>();
-
-        // find all the parents of the oldParentId
-        while ( tempId != 0 && tempId != 1 && tempId != null )
-        {
-            parentIds.add( tempId );
-            tempId = getParentId( tempId );
-        }
-
-        // find all the children of the childId
-        Cursor<IndexEntry<Long, E, Long>> cursor = subLevelIdx.forwardCursor( childId );
-
-        List<Long> childIds = new ArrayList<Long>();
-        childIds.add( childId );
-
-        while ( cursor.next() )
-        {
-            childIds.add( cursor.get().getId() );
-        }
-
-        // detach the childId and all its children from oldParentId and all it parents excluding the root
-        for ( Long pid : parentIds )
-        {
-            for ( Long cid : childIds )
-            {
-                subLevelIdx.drop( pid, cid );
-            }
-        }
-
-        parentIds.clear();
-        tempId = newParentId;
-
-        // find all the parents of the newParentId
-        while ( tempId != 0 && tempId != 1 && tempId != null )
-        {
-            parentIds.add( tempId );
-            tempId = getParentId( tempId );
-        }
-
-        // attach the childId and all its children to newParentId and all it parents excluding the root
-        for ( Long id : parentIds )
-        {
-            for ( Long cid : childIds )
-            {
-                subLevelIdx.add( id, cid );
-            }
-        }
-    }
 
 }

Modified: directory/apacheds/trunk/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmStoreTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmStoreTest.java?rev=940073&r1=940072&r2=940073&view=diff
==============================================================================
--- directory/apacheds/trunk/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmStoreTest.java (original)
+++ directory/apacheds/trunk/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmStoreTest.java Sat May  1 16:25:19 2010
@@ -49,10 +49,10 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.entry.DefaultEntry;
 import org.apache.directory.shared.ldap.entry.DefaultEntryAttribute;
 import org.apache.directory.shared.ldap.entry.DefaultModification;
+import org.apache.directory.shared.ldap.entry.Entry;
 import org.apache.directory.shared.ldap.entry.EntryAttribute;
 import org.apache.directory.shared.ldap.entry.Modification;
 import org.apache.directory.shared.ldap.entry.ModificationOperation;
-import org.apache.directory.shared.ldap.entry.Entry;
 import org.apache.directory.shared.ldap.exception.LdapNoSuchObjectException;
 import org.apache.directory.shared.ldap.exception.LdapSchemaViolationException;
 import org.apache.directory.shared.ldap.name.DN;
@@ -138,7 +138,7 @@ public class JdbmStoreTest
         store.setSyncOnWrite( false );
         store.addIndex( new JdbmIndex( SchemaConstants.OU_AT_OID ) );
         store.addIndex( new JdbmIndex( SchemaConstants.UID_AT_OID ) );
-        
+
         StoreUtils.loadExampleData( store, schemaManager );
         LOG.debug( "Created new store" );
     }
@@ -235,9 +235,9 @@ public class JdbmStoreTest
         store.setId( "foo" );
         assertEquals( "foo", store.getId() );
 
-//        assertNull( store.getNdnIndex() );
-//        store.setNdnIndex( new JdbmIndex<String, Attributes>( "ndn" ) );
-//        assertNotNull( store.getNdnIndex() );
+        assertNull( store.getRdnIndex() );
+        store.addIndex( new JdbmRdnIndex( ApacheSchemaConstants.APACHE_RDN_AT_OID ) );
+        assertNotNull( store.getRdnIndex() );
 
         assertNull( store.getOneAliasIndex() );
         store.addIndex( new JdbmIndex<Long, Attributes>( ApacheSchemaConstants.APACHE_ONE_ALIAS_AT_OID ) );
@@ -335,6 +335,16 @@ public class JdbmStoreTest
 
         assertNotNull( store.getNdnIndex() );
 
+        assertNotNull( store.getRdnIndex() );
+        try
+        {
+            store.addIndex( new JdbmRdnIndex( ApacheSchemaConstants.APACHE_RDN_AT_OID ) );
+            fail();
+        }
+        catch ( IllegalStateException e )
+        {
+        }
+
         assertNotNull( store.getOneAliasIndex() );
         try
         {
@@ -365,7 +375,6 @@ public class JdbmStoreTest
         {
         }
 
-        
         Iterator<String> systemIndices = store.systemIndices();
 
         for ( int ii = 0; ii < 11; ii++ )

Modified: directory/apacheds/trunk/ldif-partition/src/main/java/org/apache/directory/server/core/partition/ldif/LdifPartition.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/ldif-partition/src/main/java/org/apache/directory/server/core/partition/ldif/LdifPartition.java?rev=940073&r1=940072&r2=940073&view=diff
==============================================================================
--- directory/apacheds/trunk/ldif-partition/src/main/java/org/apache/directory/server/core/partition/ldif/LdifPartition.java (original)
+++ directory/apacheds/trunk/ldif-partition/src/main/java/org/apache/directory/server/core/partition/ldif/LdifPartition.java Sat May  1 16:25:19 2010
@@ -312,7 +312,7 @@ public class LdifPartition extends BTree
     {
         Long id = getEntryId( modifyContext.getDn() );
 
-        wrappedPartition.modify( id, modifyContext.getModItems() );
+        wrappedPartition.modify( modifyContext.getDn(), modifyContext.getModItems() );
 
         // Get the modified entry and store it in the context for post usage
         ClonedServerEntry modifiedEntry = lookup( id );



Mime
View raw message