directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1748572 [21/23] - in /directory/apacheds/branches/apacheds-value: ./ benchmarks/installers-maven-plugin/ benchmarks/installers-maven-plugin/.settings/ benchmarks/installers-maven-plugin/target/ benchmarks/installers-maven-plugin/target/cla...
Date Wed, 15 Jun 2016 12:30:01 GMT
Modified: directory/apacheds/branches/apacheds-value/xdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/AbstractBTreePartition.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-value/xdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/AbstractBTreePartition.java?rev=1748572&r1=1748571&r2=1748572&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-value/xdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/AbstractBTreePartition.java (original)
+++ directory/apacheds/branches/apacheds-value/xdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/AbstractBTreePartition.java Wed Jun 15 12:29:57 2016
@@ -27,6 +27,7 @@ import java.util.Arrays;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
+import java.util.List;
 import java.util.Map;
 import java.util.Set;
 import java.util.concurrent.Semaphore;
@@ -41,10 +42,8 @@ import net.sf.ehcache.store.LruPolicy;
 import org.apache.directory.api.ldap.model.constants.SchemaConstants;
 import org.apache.directory.api.ldap.model.cursor.Cursor;
 import org.apache.directory.api.ldap.model.entry.Attribute;
-import org.apache.directory.api.ldap.model.entry.BinaryValue;
 import org.apache.directory.api.ldap.model.entry.Entry;
 import org.apache.directory.api.ldap.model.entry.Modification;
-import org.apache.directory.api.ldap.model.entry.StringValue;
 import org.apache.directory.api.ldap.model.entry.Value;
 import org.apache.directory.api.ldap.model.exception.LdapAliasDereferencingException;
 import org.apache.directory.api.ldap.model.exception.LdapAliasException;
@@ -62,6 +61,7 @@ import org.apache.directory.api.ldap.mod
 import org.apache.directory.api.ldap.model.name.Rdn;
 import org.apache.directory.api.ldap.model.schema.AttributeType;
 import org.apache.directory.api.ldap.model.schema.MatchingRule;
+import org.apache.directory.api.ldap.model.schema.Normalizer;
 import org.apache.directory.api.ldap.model.schema.SchemaManager;
 import org.apache.directory.api.util.Strings;
 import org.apache.directory.api.util.exception.MultiException;
@@ -74,6 +74,7 @@ import org.apache.directory.server.core.
 import org.apache.directory.server.core.api.interceptor.context.DeleteOperationContext;
 import org.apache.directory.server.core.api.interceptor.context.HasEntryOperationContext;
 import org.apache.directory.server.core.api.interceptor.context.LookupOperationContext;
+import org.apache.directory.server.core.api.interceptor.context.ModDnAva;
 import org.apache.directory.server.core.api.interceptor.context.ModifyOperationContext;
 import org.apache.directory.server.core.api.interceptor.context.MoveAndRenameOperationContext;
 import org.apache.directory.server.core.api.interceptor.context.MoveOperationContext;
@@ -145,10 +146,10 @@ public abstract class AbstractBTreeParti
     protected MasterTable master;
 
     /** a map of attributeType numeric UUID to user userIndices */
-    protected Map<String, Index<?, String>> userIndices = new HashMap<String, Index<?, String>>();
+    protected Map<String, Index<?, String>> userIndices = new HashMap<>();
 
     /** a map of attributeType numeric UUID to system userIndices */
-    protected Map<String, Index<?, String>> systemIndices = new HashMap<String, Index<?, String>>();
+    protected Map<String, Index<?, String>> systemIndices = new HashMap<>();
 
     /** the relative distinguished name index */
     protected Index<ParentIdAndRdn, String> rdnIdx;
@@ -176,6 +177,9 @@ public abstract class AbstractBTreeParti
 
     /** Cached attributes types to avoid lookup all over the code */
     protected AttributeType objectClassAT;
+    private Normalizer objectClassNormalizer;
+    protected AttributeType presenceAT;
+    private Normalizer presenceNormalizer;
     protected AttributeType entryCsnAT;
     protected AttributeType entryDnAT;
     protected AttributeType entryUuidAT;
@@ -235,16 +239,22 @@ public abstract class AbstractBTreeParti
      */
     private void initInstance()
     {
-        indexedAttributes = new HashSet<Index<?, String>>();
+        indexedAttributes = new HashSet<>();
 
         // Initialize Attribute types used all over this method
         objectClassAT = schemaManager.getAttributeType( SchemaConstants.OBJECT_CLASS_AT );
+        objectClassNormalizer = objectClassAT.getEquality().getNormalizer();
+        presenceAT = schemaManager.getAttributeType( ApacheSchemaConstants.APACHE_PRESENCE_AT );
+        presenceNormalizer = presenceAT.getEquality().getNormalizer();
         aliasedObjectNameAT = schemaManager.getAttributeType( SchemaConstants.ALIASED_OBJECT_NAME_AT );
         entryCsnAT = schemaManager.getAttributeType( SchemaConstants.ENTRY_CSN_AT );
         entryDnAT = schemaManager.getAttributeType( SchemaConstants.ENTRY_DN_AT );
         entryUuidAT = schemaManager.getAttributeType( SchemaConstants.ENTRY_UUID_AT );
         administrativeRoleAT = schemaManager.getAttributeType( SchemaConstants.ADMINISTRATIVE_ROLE_AT );
         contextCsnAT = schemaManager.getAttributeType( SchemaConstants.CONTEXT_CSN_AT );
+        
+        // Relax the entryDnAT so that we don't check the EntryDN twice
+        entryDnAT.setRelaxed( true );
     }
 
 
@@ -256,6 +266,7 @@ public abstract class AbstractBTreeParti
      *
      * @return the maximum size of the cache as the number of entries maximum before paging out
      */
+    @Override
     public int getCacheSize()
     {
         return cacheSize;
@@ -269,6 +280,7 @@ public abstract class AbstractBTreeParti
      *
      * @param cacheSize the maximum size of the cache in the number of entries
      */
+    @Override
     public void setCacheSize( int cacheSize )
     {
         this.cacheSize = cacheSize;
@@ -301,6 +313,7 @@ public abstract class AbstractBTreeParti
      *
      * @param partitionDir the path in which this Partition stores data.
      */
+    @Override
     public void setPartitionPath( URI partitionPath )
     {
         checkInitialized( "partitionPath" );
@@ -311,6 +324,7 @@ public abstract class AbstractBTreeParti
     /**
      * {@inheritDoc}
      */
+    @Override
     public boolean isSyncOnWrite()
     {
         return isSyncOnWrite.get();
@@ -320,6 +334,7 @@ public abstract class AbstractBTreeParti
     /**
      * {@inheritDoc}
      */
+    @Override
     public void setSyncOnWrite( boolean isSyncOnWrite )
     {
         checkInitialized( "syncOnWrite" );
@@ -393,11 +408,11 @@ public abstract class AbstractBTreeParti
         }
 
         // convert and initialize system indices
-        for ( String oid : systemIndices.keySet() )
+        for ( Map.Entry<String, Index<?, String>> elem : systemIndices.entrySet() )
         {
-            Index<?, String> index = systemIndices.get( oid );
+            Index<?, String> index = elem.getValue();
             index = convertAndInit( index );
-            systemIndices.put( oid, index );
+            systemIndices.put( elem.getKey(), index );
         }
 
         // set index shortcuts
@@ -421,17 +436,19 @@ public abstract class AbstractBTreeParti
     protected void setupUserIndices() throws Exception
     {
         // convert and initialize system indices
-        Map<String, Index<?, String>> tmp = new HashMap<String, Index<?, String>>();
+        Map<String, Index<?, String>> tmp = new HashMap<>();
 
-        for ( String oid : userIndices.keySet() )
+        for ( Map.Entry<String, Index<?, String>> elem : userIndices.entrySet() )
         {
+            String oid = elem.getKey();
+            
             // check that the attributeType has an EQUALITY matchingRule
             AttributeType attributeType = schemaManager.lookupAttributeTypeRegistry( oid );
             MatchingRule mr = attributeType.getEquality();
 
             if ( mr != null )
             {
-                Index<?, String> index = userIndices.get( oid );
+                Index<?, String> index = elem.getValue();
                 index = convertAndInit( index );
                 tmp.put( oid, index );
             }
@@ -475,6 +492,7 @@ public abstract class AbstractBTreeParti
      *
      * @return the path in which this Partition stores data.
      */
+    @Override
     public URI getPartitionPath()
     {
         return partitionPath;
@@ -487,6 +505,7 @@ public abstract class AbstractBTreeParti
     /**
      * {@inheritDoc}
      */
+    @Override
     protected void doDestroy() throws LdapException, Exception
     {
         LOG.debug( "destroy() called on store for {}", this.suffixDn );
@@ -552,6 +571,7 @@ public abstract class AbstractBTreeParti
     /**
      * {@inheritDoc}
      */
+    @Override
     public void repair() throws Exception
     {
         // Do nothing by default
@@ -562,10 +582,11 @@ public abstract class AbstractBTreeParti
     /**
      * {@inheritDoc}
      */
+    @Override
     protected void doInit() throws Exception
     {
         // First, inject the indexed attributes if any
-        if ( ( indexedAttributes != null ) && ( indexedAttributes.size() > 0 ) )
+        if ( ( indexedAttributes != null ) && ( !indexedAttributes.isEmpty() ) )
         {
             for ( Index index : indexedAttributes )
             {
@@ -594,12 +615,12 @@ public abstract class AbstractBTreeParti
     
             if ( cacheSizeConfig < cacheSize )
             {
-                piarCache.getCacheConfiguration().setMaxElementsInMemory( cacheSize * 3 );
+                piarCache.getCacheConfiguration().setMaxEntriesLocalHeap( cacheSize * 3 );
             }
             
             entryDnCache = cacheService.getCache( "entryDn" );
             entryDnCache.setMemoryStoreEvictionPolicy( new LruPolicy() );
-            entryDnCache.getCacheConfiguration().setMaxElementsInMemory( cacheSize );
+            entryDnCache.getCacheConfiguration().setMaxEntriesLocalHeap( cacheSize );
         }
     }
 
@@ -629,7 +650,7 @@ public abstract class AbstractBTreeParti
         // Start with the root
         Cursor<IndexEntry<ParentIdAndRdn, String>> cursor = rdnIdx.forwardCursor();
 
-        IndexEntry<ParentIdAndRdn, String> startingPos = new IndexEntry<ParentIdAndRdn, String>();
+        IndexEntry<ParentIdAndRdn, String> startingPos = new IndexEntry<>();
         startingPos.setKey( new ParentIdAndRdn( id, ( Rdn[] ) null ) );
         cursor.before( startingPos );
 
@@ -648,7 +669,7 @@ public abstract class AbstractBTreeParti
         // Start with the root
         Cursor<IndexEntry<ParentIdAndRdn, String>> cursor = rdnIdx.forwardCursor();
 
-        IndexEntry<ParentIdAndRdn, String> startingPos = new IndexEntry<ParentIdAndRdn, String>();
+        IndexEntry<ParentIdAndRdn, String> startingPos = new IndexEntry<>();
         startingPos.setKey( new ParentIdAndRdn( id, ( Rdn[] ) null ) );
         cursor.before( startingPos );
         int countChildren = 0;
@@ -678,8 +699,10 @@ public abstract class AbstractBTreeParti
     /**
      * {@inheritDoc}
      */
+    @Override
     public void add( AddOperationContext addContext ) throws LdapException
     {
+//System.out.println( "Add: " + addContext.getDn() );
         try
         {
             setRWLock( addContext );
@@ -694,9 +717,8 @@ public abstract class AbstractBTreeParti
             {
                 if ( getEntryId( entryDn ) != null )
                 {
-                    LdapEntryAlreadyExistsException ne = new LdapEntryAlreadyExistsException(
+                    throw new LdapEntryAlreadyExistsException(
                         I18n.err( I18n.ERR_250_ENTRY_ALREADY_EXISTS, entryDn.getName() ) );
-                    throw ne;
                 }
             }
             finally
@@ -712,9 +734,9 @@ public abstract class AbstractBTreeParti
             // entry sequences start at 1.
             //
             Dn parentDn = null;
-            ParentIdAndRdn key = null;
+            ParentIdAndRdn key;
 
-            if ( entryDn.equals( suffixDn ) )
+            if ( entryDn.getNormName().equals( suffixDn.getNormName() ) )
             {
                 parentId = Partition.ROOT_ID;
                 key = new ParentIdAndRdn( parentId, suffixDn.getRdns() );
@@ -746,7 +768,7 @@ public abstract class AbstractBTreeParti
             // Get a new UUID for the added entry if it does not have any already
             Attribute entryUUID = entry.get( entryUuidAT );
 
-            String id = null;
+            String id;
 
             if ( entryUUID == null )
             {
@@ -756,6 +778,11 @@ public abstract class AbstractBTreeParti
             {
                 id = entryUUID.getString();
             }
+            
+            if ( entryDn.getNormName().equals( suffixDn.getNormName() ) )
+            {
+                suffixId = id;
+            }
 
             // Update the ObjectClass index
             Attribute objectClass = entry.get( objectClassAT );
@@ -764,26 +791,25 @@ public abstract class AbstractBTreeParti
             {
                 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;
+                throw new LdapSchemaViolationException( rc, msg );
             }
 
-            for ( Value<?> value : objectClass )
+            for ( Value value : objectClass )
             {
-                String valueStr = ( String ) value.getNormValue();
-
-                if ( valueStr.equals( SchemaConstants.TOP_OC ) )
+                if ( value.equals( SchemaConstants.TOP_OC ) )
                 {
                     continue;
                 }
+                
+                String normalizedOc = objectClassNormalizer.normalize( value.getValue() );
 
-                objectClassIdx.add( valueStr, id );
+                objectClassIdx.add( normalizedOc, id );
             }
 
             if ( objectClass.contains( SchemaConstants.ALIAS_OC ) )
             {
                 Attribute aliasAttr = entry.get( aliasedObjectNameAT );
+                
                 addAliasIndices( id, entryDn, new Dn( schemaManager, aliasAttr.getString() ) );
             }
 
@@ -804,9 +830,9 @@ public abstract class AbstractBTreeParti
                 // We may have more than one role
                 Attribute adminRoles = entry.get( administrativeRoleAT );
 
-                for ( Value<?> value : adminRoles )
+                for ( Value value : adminRoles )
                 {
-                    adminRoleIdx.add( ( String ) value.getNormValue(), id );
+                    adminRoleIdx.add( value.getValue(), id );
                 }
 
                 // Adds only those attributes that are indexed
@@ -821,14 +847,15 @@ public abstract class AbstractBTreeParti
 
                 if ( hasUserIndexOn( attributeType ) )
                 {
-                    Index<Object, String> idx = ( Index<Object, String> ) getUserIndex( attributeType );
+                    Index<Object, String> userIndex = ( Index<Object, String> ) getUserIndex( attributeType );
 
                     // 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 )
+                    for ( Value value : attribute )
                     {
-                        idx.add( value.getNormValue(), id );
+                        String normalized = value.getNormalized();
+                        userIndex.add( normalized, id );
                     }
 
                     // Adds only those attributes that are indexed
@@ -877,7 +904,6 @@ public abstract class AbstractBTreeParti
         }
         catch ( Exception e )
         {
-            e.printStackTrace();
             throw new LdapException( e );
         }
     }
@@ -889,8 +915,10 @@ public abstract class AbstractBTreeParti
     /**
      * {@inheritDoc}
      */
+    @Override
     public Entry delete( DeleteOperationContext deleteContext ) throws LdapException
     {
+//System.out.println( "Delete: " + deleteContext.getDn() );
         try
         {
             setRWLock( deleteContext );
@@ -918,9 +946,7 @@ public abstract class AbstractBTreeParti
 
             if ( childCount > 0 )
             {
-                LdapContextNotEmptyException cnee = new LdapContextNotEmptyException( I18n.err( I18n.ERR_700, dn ) );
-                //cnee.setRemainingName( dn );
-                throw cnee;
+                throw new LdapContextNotEmptyException( I18n.err( I18n.ERR_700, dn ) );
             }
 
             // We now defer the deletion to the implementing class
@@ -944,6 +970,7 @@ public abstract class AbstractBTreeParti
     protected void updateRdnIdx( String parentId, boolean addRemove, int nbDescendant ) throws Exception
     {
         boolean isFirst = true;
+        ////dumpRdnIdx();
 
         if ( parentId.equals( Partition.ROOT_ID ) )
         {
@@ -955,6 +982,7 @@ public abstract class AbstractBTreeParti
         while ( parent != null )
         {
             rdnIdx.drop( parentId );
+            ////dumpRdnIdx();
             
             if ( isFirst )
             {
@@ -982,6 +1010,8 @@ public abstract class AbstractBTreeParti
             // Inject the modified element into the index
             rdnIdx.add( parent, parentId );
 
+            ////dumpRdnIdx();
+
             parentId = parent.getParentId();
             parent = rdnIdx.reverseLookup( parentId );
         }
@@ -994,6 +1024,7 @@ public abstract class AbstractBTreeParti
      * @return the deleted entry if found
      * @throws Exception If the deletion failed
      */
+    @Override
     public Entry delete( String id ) throws LdapException
     {
         try
@@ -1026,16 +1057,16 @@ public abstract class AbstractBTreeParti
             }
 
             // Update the ObjectClass index
-            for ( Value<?> value : objectClass )
+            for ( Value value : objectClass )
             {
-                String valueStr = ( String ) value.getNormValue();
-
-                if ( valueStr.equals( SchemaConstants.TOP_OC ) )
+                if ( value.equals( SchemaConstants.TOP_OC ) )
                 {
                     continue;
                 }
                 
-                objectClassIdx.drop( valueStr, id );
+                String normalizedOc = objectClassNormalizer.normalize( value.getValue() );
+
+                objectClassIdx.drop( normalizedOc, id );
             }
 
             // Update the parent's nbChildren and nbDescendants values
@@ -1051,9 +1082,9 @@ public abstract class AbstractBTreeParti
                 // We may have more than one role
                 Attribute adminRoles = entry.get( administrativeRoleAT );
 
-                for ( Value<?> value : adminRoles )
+                for ( Value value : adminRoles )
                 {
-                    adminRoleIdx.drop( ( String ) value.getNormValue(), id );
+                    adminRoleIdx.drop( value.getValue(), id );
                 }
 
                 // Deletes only those attributes that are indexed
@@ -1068,13 +1099,14 @@ public abstract class AbstractBTreeParti
 
                 if ( hasUserIndexOn( attributeType ) )
                 {
-                    Index<?, String> index = getUserIndex( attributeType );
+                    Index<?, String> userIndex = getUserIndex( attributeType );
 
                     // 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 )
+                    for ( Value value : attribute )
                     {
-                        ( ( Index ) index ).drop( value.getValue(), id );
+                        String normalized =  value.getNormalized();
+                        ( ( Index ) userIndex ).drop( normalized, id );
                     }
 
                     presenceIdx.drop( attributeOid, id );
@@ -1087,7 +1119,7 @@ public abstract class AbstractBTreeParti
             {
                 rdnIdx.drop( id );
 
-                dumpRdnIdx();
+                ////dumpRdnIdx();
 
                 entryDnCache.remove( id );
                 
@@ -1125,13 +1157,14 @@ public abstract class AbstractBTreeParti
     /**
      * {@inheritDoc}
      */
+    @Override
     public EntryFilteringCursor search( SearchOperationContext searchContext ) throws LdapException
     {
         try
         {
             setRWLock( searchContext );
 
-            if ( ctxCsnChanged && getSuffixDn().getNormName().equals( searchContext.getDn().getNormName() ) )
+            if ( ctxCsnChanged && getSuffixDn().equals( searchContext.getDn() ) )
             {
                 try
                 {
@@ -1172,6 +1205,7 @@ public abstract class AbstractBTreeParti
     /**
      * {@inheritDoc}
      */
+    @Override
     public Entry lookup( LookupOperationContext lookupContext ) throws LdapException
     {
         setRWLock( lookupContext );
@@ -1199,9 +1233,7 @@ public abstract class AbstractBTreeParti
             }
         }
 
-        Entry entry = fetch( id, lookupContext.getDn() );
-
-        return entry;
+        return fetch( id, lookupContext.getDn() );
     }
 
 
@@ -1212,6 +1244,7 @@ public abstract class AbstractBTreeParti
      * @return The found Entry, or null if not found
      * @throws Exception If the lookup failed for any reason (except a not found entry)
      */
+    @Override
     public Entry fetch( String id ) throws LdapException
     {
         try
@@ -1240,6 +1273,7 @@ public abstract class AbstractBTreeParti
      * @return The found Entry, or null if not found
      * @throws Exception If the lookup failed for any reason (except a not found entry)
      */
+    @Override
     public Entry fetch( String id, Dn dn ) throws LdapException
     {
         try
@@ -1311,6 +1345,7 @@ public abstract class AbstractBTreeParti
     /**
      * {@inheritDoc}
      */
+    @Override
     public void modify( ModifyOperationContext modifyContext ) throws LdapException
     {
         try
@@ -1335,6 +1370,7 @@ public abstract class AbstractBTreeParti
     /**
      * {@inheritDoc}
      */
+    @Override
     public final synchronized Entry modify( Dn dn, Modification... mods ) throws Exception
     {
         String id = getEntryId( dn );
@@ -1400,66 +1436,69 @@ public abstract class AbstractBTreeParti
         }
 
         String modsOid = schemaManager.getAttributeTypeRegistry().getOidByName( mods.getId() );
+        String normalizedModsOid = presenceNormalizer.normalize( modsOid );
+
         AttributeType attributeType = mods.getAttributeType();
 
         // Special case for the ObjectClass index
         if ( modsOid.equals( SchemaConstants.OBJECT_CLASS_AT_OID ) )
         {
-            for ( Value<?> value : mods )
+            for ( Value value : mods )
             {
-                String valueStr = ( String ) value.getNormValue();
-
-                if ( valueStr.equals( SchemaConstants.TOP_OC ) )
+                if ( value.equals( SchemaConstants.TOP_OC ) )
                 {
                     continue;
                 }
                 
-                objectClassIdx.add( valueStr, id );
+                String normalizedOc = objectClassNormalizer.normalize( value.getValue() );
+
+                objectClassIdx.add( normalizedOc, id );
             }
         }
         else if ( hasUserIndexOn( attributeType ) )
         {
-            Index<?, String> index = getUserIndex( attributeType );
+            Index<?, String> userIndex = getUserIndex( attributeType );
 
             if ( mods.size() > 0 )
             {
-                for ( Value<?> value : mods )
+                for ( Value value : mods )
                 {
-                    ( ( Index ) index ).add( value.getNormValue(), id );
+                    String normalized = value.getNormalized();
+                    ( ( Index ) userIndex ).add( normalized, id );
                 }
             }
             else
             {
                 // Special case when we have null values
-                ( ( Index ) index ).add( null, id );
+                ( ( Index ) userIndex ).add( null, id );
             }
 
             // If the attr didn't exist for this id add it to presence index
-            if ( !presenceIdx.forward( modsOid, id ) )
+            if ( !presenceIdx.forward( normalizedModsOid, id ) )
             {
-                presenceIdx.add( modsOid, id );
+                presenceIdx.add( normalizedModsOid, id );
             }
         }
         // Special case for the AdministrativeRole index
         else if ( modsOid.equals( SchemaConstants.ADMINISTRATIVE_ROLE_AT_OID ) )
         {
             // We may have more than one role 
-            for ( Value<?> value : mods )
+            for ( Value value : mods )
             {
-                adminRoleIdx.add( ( String ) value.getNormValue(), id );
+                adminRoleIdx.add( value.getValue(), id );
             }
 
             // If the attr didn't exist for this id add it to presence index
-            if ( !presenceIdx.forward( modsOid, id ) )
+            if ( !presenceIdx.forward( normalizedModsOid, id ) )
             {
-                presenceIdx.add( modsOid, id );
+                presenceIdx.add( normalizedModsOid, id );
             }
         }
 
         // add all the values in mods to the same attribute in the entry
         if ( mods.size() > 0 )
         {
-            for ( Value<?> value : mods )
+            for ( Value value : mods )
             {
                 entry.add( mods.getAttributeType(), value );
             }
@@ -1469,11 +1508,11 @@ public abstract class AbstractBTreeParti
             // Special cases for null values
             if ( mods.getAttributeType().getSyntax().isHumanReadable() )
             {
-                entry.add( mods.getAttributeType(), new StringValue( ( String ) null ) );
+                entry.add( mods.getAttributeType(), new Value( mods.getAttributeType(), ( String ) null ) );
             }
             else
             {
-                entry.add( mods.getAttributeType(), new BinaryValue( null ) );
+                entry.add( mods.getAttributeType(), new Value( mods.getAttributeType(), ( byte[] ) null ) );
             }
         }
 
@@ -1513,49 +1552,51 @@ public abstract class AbstractBTreeParti
         {
             // if the id exists in the index drop all existing attribute
             // value index entries and add new ones
-            for ( Value<?> value : entry.get( objectClassAT ) )
+            for ( Value value : entry.get( objectClassAT ) )
             {
-                String valueStr = ( String ) value.getNormValue();
-
-                if ( valueStr.equals( SchemaConstants.TOP_OC ) )
+                if ( value.equals( SchemaConstants.TOP_OC ) )
                 {
                     continue;
                 }
+                
+                String normalizedOc = objectClassNormalizer.normalize( value.getValue() );
 
-                objectClassIdx.drop( valueStr, id );
+                objectClassIdx.drop( normalizedOc, id );
             }
 
-            for ( Value<?> value : mods )
+            for ( Value value : mods )
             {
-                String valueStr = ( String ) value.getNormValue();
-
-                if ( valueStr.equals( SchemaConstants.TOP_OC ) )
+                if ( value.equals( SchemaConstants.TOP_OC ) )
                 {
                     continue;
                 }
+                
+                String normalizedOc = objectClassNormalizer.normalize( value.getValue() );
 
-                objectClassIdx.add( valueStr, id );
+                objectClassIdx.add( normalizedOc, id );
             }
         }
         else if ( hasUserIndexOn( attributeType ) )
         {
-            Index<?, String> index = getUserIndex( attributeType );
+            Index<?, String> userIndex = getUserIndex( attributeType );
 
             // Drop all the previous values
             Attribute oldAttribute = entry.get( mods.getAttributeType() );
 
             if ( oldAttribute != null )
             {
-                for ( Value<?> value : oldAttribute )
+                for ( Value value : oldAttribute )
                 {
-                    ( ( Index<Object, String> ) index ).drop( value.getNormValue(), id );
+                    String normalized = value.getNormalized();
+                    ( ( Index<Object, String> ) userIndex ).drop( normalized, id );
                 }
             }
 
             // And add the new ones
-            for ( Value<?> value : mods )
+            for ( Value value : mods )
             {
-                ( ( Index<Object, String> ) index ).add( value.getNormValue(), id );
+                String normalized = value.getNormalized();
+                ( ( Index ) userIndex ).add( normalized, id );
             }
 
             /*
@@ -1570,22 +1611,22 @@ public abstract class AbstractBTreeParti
         else if ( attributeType.equals( administrativeRoleAT ) )
         {
             // Remove the previous values
-            for ( Value<?> value : entry.get( administrativeRoleAT ) )
+            for ( Value value : entry.get( administrativeRoleAT ) )
             {
-                String valueStr = ( String ) value.getNormValue();
-
-                if ( valueStr.equals( SchemaConstants.TOP_OC ) )
+                if ( value.equals( SchemaConstants.TOP_OC ) )
                 {
                     continue;
                 }
                 
-                objectClassIdx.drop( valueStr, id );
+                String normalizedOc = objectClassNormalizer.normalize( value.getValue() );
+
+                objectClassIdx.drop( normalizedOc, id );
             }
 
             // And add the new ones 
-            for ( Value<?> value : mods )
+            for ( Value value : mods )
             {
-                String valueStr = ( String ) value.getNormValue();
+                String valueStr = value.getValue();
 
                 if ( valueStr.equals( SchemaConstants.TOP_OC ) )
                 {
@@ -1657,36 +1698,36 @@ public abstract class AbstractBTreeParti
              */
             if ( mods.size() == 0 )
             {
-                for ( Value<?> value : entry.get( objectClassAT ) )
+                for ( Value value : entry.get( objectClassAT ) )
                 {
-                    String valueStr = ( String ) value.getNormValue();
-
-                    if ( valueStr.equals( SchemaConstants.TOP_OC ) )
+                    if ( value.equals( SchemaConstants.TOP_OC ) )
                     {
                         continue;
                     }
+                    
+                    String normalizedOc = objectClassNormalizer.normalize( value.getValue() );
 
-                    objectClassIdx.drop( valueStr, id );
+                    objectClassIdx.drop( normalizedOc, id );
                 }
             }
             else
             {
-                for ( Value<?> value : mods )
+                for ( Value value : mods )
                 {
-                    String valueStr = ( String ) value.getNormValue();
-
-                    if ( valueStr.equals( SchemaConstants.TOP_OC ) )
+                    if ( value.equals( SchemaConstants.TOP_OC ) )
                     {
                         continue;
                     }
+                    
+                    String normalizedOc = objectClassNormalizer.normalize( value.getValue() );
 
-                    objectClassIdx.drop( valueStr, id );
+                    objectClassIdx.drop( normalizedOc, id );
                 }
             }
         }
         else if ( hasUserIndexOn( attributeType ) )
         {
-            Index<?, String> index = getUserIndex( attributeType );
+            Index<?, String> userIndex = getUserIndex( attributeType );
 
             Attribute attribute = entry.get( attributeType ).clone();
             int nbValues = 0;
@@ -1703,12 +1744,12 @@ public abstract class AbstractBTreeParti
              */
             if ( mods.size() == 0 )
             {
-                ( ( Index ) index ).drop( id );
+                ( ( Index ) userIndex ).drop( id );
                 nbValues = 0;
             }
             else
             {
-                for ( Value<?> value : mods )
+                for ( Value value : mods )
                 {
                     if ( attribute.contains( value ) )
                     {
@@ -1716,7 +1757,8 @@ public abstract class AbstractBTreeParti
                         attribute.remove( value );
                     }
 
-                    ( ( Index ) index ).drop( value.getNormValue(), id );
+                    String normalized = value.getNormalized();
+                    ( ( Index ) userIndex ).drop( normalized, id );
                 }
             }
 
@@ -1733,9 +1775,9 @@ public abstract class AbstractBTreeParti
         else if ( modsOid.equals( SchemaConstants.ADMINISTRATIVE_ROLE_AT_OID ) )
         {
             // We may have more than one role 
-            for ( Value<?> value : mods )
+            for ( Value value : mods )
             {
-                adminRoleIdx.drop( ( String ) value.getNormValue(), id );
+                adminRoleIdx.drop( value.getValue(), id );
             }
 
             /*
@@ -1762,7 +1804,7 @@ public abstract class AbstractBTreeParti
         {
             Attribute entryAttr = entry.get( mods.getAttributeType() );
 
-            for ( Value<?> value : mods )
+            for ( Value value : mods )
             {
                 entryAttr.remove( value );
             }
@@ -1788,8 +1830,10 @@ public abstract class AbstractBTreeParti
     /**
      * {@inheritDoc}
      */
+    @Override
     public void move( MoveOperationContext moveContext ) throws LdapException
     {
+//System.out.println( "Move: " + moveContext.getDn() + " to:" + moveContext.getNewDn() );
         if ( moveContext.getNewSuperior().isDescendantOf( moveContext.getDn() ) )
         {
             throw new LdapUnwillingToPerformException( ResultCodeEnum.UNWILLING_TO_PERFORM,
@@ -1817,18 +1861,19 @@ public abstract class AbstractBTreeParti
     /**
      * {@inheritDoc}
      */
+    @Override
     public final synchronized void move( Dn oldDn, Dn newSuperiorDn, Dn newDn, Entry modifiedEntry )
         throws Exception
     {
+//System.out.println( "Move: " + oldDn + " to:" + newDn );
         // Check that the parent Dn exists
         String newParentId = getEntryId( newSuperiorDn );
 
         if ( newParentId == null )
         {
             // This is not allowed : the parent must exist
-            LdapEntryAlreadyExistsException ne = new LdapEntryAlreadyExistsException(
+            throw new LdapEntryAlreadyExistsException(
                 I18n.err( I18n.ERR_256_NO_SUCH_OBJECT, newSuperiorDn.getName() ) );
-            throw ne;
         }
 
         // Now check that the new entry does not exist
@@ -1838,9 +1883,8 @@ public abstract class AbstractBTreeParti
         {
             // This is not allowed : we should not be able to move an entry
             // to an existing position
-            LdapEntryAlreadyExistsException ne = new LdapEntryAlreadyExistsException(
+            throw new LdapEntryAlreadyExistsException(
                 I18n.err( I18n.ERR_250_ENTRY_ALREADY_EXISTS, newSuperiorDn.getName() ) );
-            throw ne;
         }
 
         // Get the entry and the old parent IDs
@@ -1885,7 +1929,12 @@ public abstract class AbstractBTreeParti
 
         if ( null != aliasTarget )
         {
-            aliasTarget.apply( schemaManager );
+            if ( !aliasTarget.isSchemaAware() )
+            {
+                aliasTarget = new Dn( schemaManager, aliasTarget );
+            }
+            
+
             addAliasIndices( entryId, buildEntryDn( entryId ), aliasTarget );
         }
 
@@ -1922,8 +1971,10 @@ public abstract class AbstractBTreeParti
     /**
      * {@inheritDoc}
      */
+    @Override
     public void moveAndRename( MoveAndRenameOperationContext moveAndRenameContext ) throws LdapException
     {
+//System.out.println( "Move and Rename from :" + moveAndRenameContext.getDn() + " to " + moveAndRenameContext.getNewDn() + ", deletOldRdn:" + moveAndRenameContext.getDeleteOldRdn() );
         if ( moveAndRenameContext.getNewSuperiorDn().isDescendantOf( moveAndRenameContext.getDn() ) )
         {
             throw new LdapUnwillingToPerformException( ResultCodeEnum.UNWILLING_TO_PERFORM,
@@ -1936,10 +1987,10 @@ public abstract class AbstractBTreeParti
             Dn oldDn = moveAndRenameContext.getDn();
             Dn newSuperiorDn = moveAndRenameContext.getNewSuperiorDn();
             Rdn newRdn = moveAndRenameContext.getNewRdn();
-            boolean deleteOldRdn = moveAndRenameContext.getDeleteOldRdn();
             Entry modifiedEntry = moveAndRenameContext.getModifiedEntry();
+            Map<String, List<ModDnAva>> modAvas = moveAndRenameContext.getModifiedAvas();
 
-            moveAndRename( oldDn, newSuperiorDn, newRdn, modifiedEntry, deleteOldRdn );
+            moveAndRename( oldDn, newSuperiorDn, newRdn, modAvas, modifiedEntry );
             updateCache( moveAndRenameContext );
         }
         catch ( LdapException le )
@@ -1956,35 +2007,34 @@ public abstract class AbstractBTreeParti
 
 
     /**
+     * Implementation. We have many things to check first to see if the modification is possible :
+     * <ul>
+     *  <li>The new superior must exist</li>
+     *  <li>The new Dn must not exist</li>
+     * </ul>
+     * (here, we assume the old entry exists)
+     * 
+     * The next step is to process the RDN, accordingly to the deleteOldRdn flag.
      * {@inheritDoc}
-     */
+     *
+    @Override
     public final synchronized void moveAndRename( Dn oldDn, Dn newSuperiorDn, Rdn newRdn, Entry modifiedEntry,
         boolean deleteOldRdn ) throws Exception
     {
-        // Check that the old entry exists
         String oldId = getEntryId( oldDn );
 
-        if ( oldId == null )
-        {
-            // This is not allowed : the old entry must exist
-            LdapNoSuchObjectException nse = new LdapNoSuchObjectException(
-                I18n.err( I18n.ERR_256_NO_SUCH_OBJECT, oldDn ) );
-            throw nse;
-        }
-
         // Check that the new superior exist
         String newSuperiorId = getEntryId( newSuperiorDn );
 
         if ( newSuperiorId == null )
         {
             // This is not allowed : the new superior must exist
-            LdapNoSuchObjectException nse = new LdapNoSuchObjectException(
+            throw new LdapNoSuchObjectException(
                 I18n.err( I18n.ERR_256_NO_SUCH_OBJECT, newSuperiorDn ) );
-            throw nse;
         }
 
         Dn newDn = newSuperiorDn.add( newRdn );
-
+            
         // Now check that the new entry does not exist
         String newId = getEntryId( newDn );
 
@@ -1992,9 +2042,8 @@ public abstract class AbstractBTreeParti
         {
             // This is not allowed : we should not be able to move an entry
             // to an existing position
-            LdapEntryAlreadyExistsException ne = new LdapEntryAlreadyExistsException(
+            throw new LdapEntryAlreadyExistsException(
                 I18n.err( I18n.ERR_250_ENTRY_ALREADY_EXISTS, newSuperiorDn.getName() ) );
-            throw ne;
         }
 
         // First, rename
@@ -2005,6 +2054,7 @@ public abstract class AbstractBTreeParti
         }
 
         rename( oldId, newRdn, deleteOldRdn, modifiedEntry );
+        //Rdn oldRdn = oldDn.getRdn();
         moveAndRename( oldDn, oldId, newSuperiorDn, newRdn, modifiedEntry );
 
         entryDnCache.removeAll();
@@ -2014,8 +2064,8 @@ public abstract class AbstractBTreeParti
             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
@@ -2031,13 +2081,49 @@ public abstract class AbstractBTreeParti
      * @param modifiedEntry the modified entry
      * @throws Exception if something goes wrong
      */
-    private void moveAndRename( Dn oldDn, String entryId, Dn newSuperior, Rdn newRdn,
-        Entry modifiedEntry )
-        throws Exception
+    public void moveAndRename( Dn oldDn, Dn newSuperiorDn, Rdn newRdn, Map<String, List<ModDnAva>> modAvas, 
+        Entry modifiedEntry ) throws Exception
     {
         // Get the child and the new parent to be entries and Ids
-        String newParentId = getEntryId( newSuperior );
-        String oldParentId = getParentId( entryId );
+        Attribute entryIdAt = modifiedEntry.get( SchemaConstants.ENTRY_UUID_AT );
+        String entryId;
+        
+        if ( entryIdAt == null )
+        {
+            entryId = getEntryId( modifiedEntry.getDn() );
+        }
+        else
+        {
+            entryId = modifiedEntry.get( SchemaConstants.ENTRY_UUID_AT ).getString();
+        }
+
+        Attribute oldParentIdAt = modifiedEntry.get( ApacheSchemaConstants.ENTRY_PARENT_ID_AT );
+        String oldParentId;
+        
+        if ( oldParentIdAt == null )
+        {
+            oldParentId = getEntryId( oldDn.getParent() );
+        }
+        else
+        {
+            oldParentId = oldParentIdAt.getString();
+        }
+
+        String newParentId = getEntryId( newSuperiorDn );
+
+        //Get the info about the moved entry
+        ParentIdAndRdn movedEntry = rdnIdx.reverseLookup( entryId );
+        
+        // First drop the moved entry from the rdn index
+        rdnIdx.drop( entryId );
+
+        //
+        // The update the Rdn index. We will remove the ParentIdAndRdn associated with the
+        // moved entry, and update the nbChilden of its parent and the nbSubordinates
+        // of all its ascendant, up to the common superior.
+        // Then we will add a ParentidAndRdn for the moved entry under the new superior,
+        // update its children number and the nbSubordinates of all the new ascendant.
+        updateRdnIdx( oldParentId, REMOVE_CHILD, movedEntry.getNbDescendants() );
 
         /*
          * All aliases including and below oldChildDn, will be affected by
@@ -2049,17 +2135,8 @@ public abstract class AbstractBTreeParti
          */
         dropMovedAliasIndices( oldDn );
 
-        /*
-         * Update the Rdn index
-         */
-        // First drop the old entry
-        ParentIdAndRdn movedEntry = rdnIdx.reverseLookup( entryId );
-
-        updateRdnIdx( oldParentId, REMOVE_CHILD, movedEntry.getNbDescendants() );
-
-        rdnIdx.drop( entryId );
-
         // Now, add the new entry at the right position
+        // First
         movedEntry.setParentId( newParentId );
         movedEntry.setRdns( new Rdn[]
             { newRdn } );
@@ -2067,7 +2144,8 @@ public abstract class AbstractBTreeParti
 
         updateRdnIdx( newParentId, ADD_CHILD, movedEntry.getNbDescendants() );
 
-        dumpRdnIdx();
+        // Process the modified indexes now
+        processModifiedAvas( modAvas, entryId );
 
         /*
          * Read Alias Index Tuples
@@ -2083,20 +2161,100 @@ public abstract class AbstractBTreeParti
 
         if ( null != aliasTarget )
         {
-            aliasTarget.apply( schemaManager );
+            if ( !aliasTarget.isSchemaAware() )
+            {
+                aliasTarget = new Dn( schemaManager, aliasTarget );
+            }
+            
             addAliasIndices( entryId, buildEntryDn( entryId ), aliasTarget );
         }
+
+        // Remove the EntryDN
+        modifiedEntry.removeAttributes( entryDnAT );
+        
+        // Update the entryParentId attribute
+        modifiedEntry.removeAttributes( ApacheSchemaConstants.ENTRY_PARENT_ID_OID );
+        modifiedEntry.add( ApacheSchemaConstants.ENTRY_PARENT_ID_OID, newParentId );
+        
+        // Doom the DN cache now
+        entryDnCache.removeAll();
+
+        setContextCsn( modifiedEntry.get( entryCsnAT ).getString() );
+
+        // save the modified entry at the new place
+        master.put( entryId, modifiedEntry );
     }
+    
+    
+    /**
+     * Update the index accordingly to the changed Attribute in the old and new RDN
+     */
+    private void processModifiedAvas( Map<String, List<ModDnAva>> modAvas, String entryId ) throws Exception
+    {
+        for ( List<ModDnAva> modDnAvas : modAvas.values() )
+        {
+            for ( ModDnAva modDnAva : modDnAvas )
+            {
+                AttributeType attributeType = modDnAva.getAva().getAttributeType();
+                
+                if ( !hasIndexOn( attributeType ) )
+                {
+                    break;
+                }
 
+                Index<?, String> index = getUserIndex( attributeType );
+                
+                switch ( modDnAva.getType() )
+                {
+                    case ADD :
+                    case UPDATE_ADD :
+                        // Add Value in the index
+                        ( ( Index ) index ).add( modDnAva.getAva().getValue().getNormalized(), entryId );
 
+                        /*
+                         * If there is no value for id in this index due to our
+                         * add above we add the entry in the presence idx
+                         */
+                        if ( null == index.reverseLookup( entryId ) )
+                        {
+                            presenceIdx.add( attributeType.getOid(), entryId );
+                        }
+                        
+                        break;
+
+                    case DELETE :
+                    case UPDATE_DELETE :
+                        ( ( Index ) index ).drop( modDnAva.getAva().getValue().getNormalized(), entryId );
+
+                        /*
+                         * 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( entryId ) )
+                        {
+                            presenceIdx.drop( attributeType.getOid(), entryId );
+                        }
+                        
+                        break;
+                        
+                    default :
+                        break;
+                }
+            }
+        }
+    }
+    
+    
     //---------------------------------------------------------------------------------------------
     // The Rename operation
     //---------------------------------------------------------------------------------------------
     /**
      * {@inheritDoc}
      */
+    @Override
     public void rename( RenameOperationContext renameContext ) throws LdapException
     {
+//System.out.println( "Rename from :" + renameContext.getDn() + " to " + renameContext.getNewDn() + ", deletOldRdn:" + renameContext.getDeleteOldRdn() );
         try
         {
             setRWLock( renameContext );
@@ -2138,7 +2296,10 @@ public abstract class AbstractBTreeParti
 
         Dn updn = entry.getDn();
 
-        newRdn.apply( schemaManager );
+        if ( !newRdn.isSchemaAware() )
+        {
+            newRdn = new Rdn( schemaManager, newRdn );
+        }
 
         /*
          * H A N D L E   N E W   R D N
@@ -2153,7 +2314,7 @@ public abstract class AbstractBTreeParti
         for ( Ava newAtav : newRdn )
         {
             String newNormType = newAtav.getNormType();
-            Object newNormValue = newAtav.getValue().getNormValue();
+            Object newNormValue = newAtav.getValue().getValue();
             boolean oldRemoved = false;
 
             AttributeType newRdnAttrType = schemaManager.lookupAttributeTypeRegistry( newNormType );
@@ -2161,6 +2322,7 @@ public abstract class AbstractBTreeParti
             if ( newRdnAttrType.isSingleValued() && entry.containsAttribute( newRdnAttrType ) )
             {
                 Attribute oldAttribute = entry.get( newRdnAttrType );
+                AttributeType oldAttributeType = oldAttribute.getAttributeType();
                 
                 // We have to remove the old attribute value, if we have some
                 entry.removeAttributes( newRdnAttrType );
@@ -2168,14 +2330,16 @@ public abstract class AbstractBTreeParti
                 // Deal with the index
                 if ( hasUserIndexOn( newRdnAttrType ) )
                 {
-                    Index<?, String> index = getUserIndex( newRdnAttrType );
-                    ( ( Index ) index ).drop( oldAttribute.get().getNormValue(), id );
+                    Index<?, String> userIndex = getUserIndex( newRdnAttrType );
+
+                    String normalized = oldAttributeType.getEquality().getNormalizer().normalize( oldAttribute.get().getValue() );
+                    ( ( Index ) userIndex ).drop( normalized, 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( oldId ) )
+                    if ( null == userIndex.reverseLookup( oldId ) )
                     {
                         presenceIdx.drop( newRdnAttrType.getOid(), oldId );
                     }
@@ -2185,28 +2349,38 @@ public abstract class AbstractBTreeParti
 
             if ( newRdnAttrType.getSyntax().isHumanReadable() )
             {
-                entry.add( newRdnAttrType, ( String ) newAtav.getValue().getNormValue() );
+                entry.add( newRdnAttrType, newAtav.getValue().getValue() );
             }
             else
             {
-                entry.add( newRdnAttrType, ( byte[] ) newAtav.getValue().getNormValue() );
+                entry.add( newRdnAttrType, newAtav.getValue().getBytes() );
             }
 
             if ( hasUserIndexOn( newRdnAttrType ) )
             {
-                Index<?, String> index = getUserIndex( newRdnAttrType );
+                Index<?, String> userIndex = getUserIndex( newRdnAttrType );
                 
+                /*
                 if ( oldRemoved )
                 {
+                    String normalized = newRdnAttrType.getEquality().getNormalizer().normalize( newNormValue );
+                    ( ( Index ) userIndex ).add( normalized, id );
                     ( ( Index ) index ).drop( newNormValue, oldId );
                 }
+                */
+                
+                String normalized = newRdnAttrType.getEquality().getNormalizer().normalize( ( String ) newNormValue );
+                ( ( Index ) userIndex ).add( normalized, oldId );
                 
-                ( ( Index ) index ).add( newNormValue, oldId );
+                
+                //( ( Index ) index ).add( newNormValue, oldId );
 
                 // Make sure the altered entry shows the existence of the new attrib
-                if ( !presenceIdx.forward( newNormType, oldId ) )
+                String normTypeOid = presenceNormalizer.normalize( newNormType );
+                
+                if ( !presenceIdx.forward( normTypeOid, oldId ) )
                 {
-                    presenceIdx.add( newNormType, oldId );
+                    presenceIdx.add( normTypeOid, oldId );
                 }
             }
         }
@@ -2250,22 +2424,25 @@ public abstract class AbstractBTreeParti
                 if ( mustRemove )
                 {
                     String oldNormType = oldAtav.getNormType();
-                    String oldNormValue = ( String ) oldAtav.getValue().getNormValue();
+                    String oldNormValue = oldAtav.getValue().getValue();
                     AttributeType oldRdnAttrType = schemaManager.lookupAttributeTypeRegistry( oldNormType );
                     entry.remove( oldRdnAttrType, oldNormValue );
 
                     if ( hasUserIndexOn( oldRdnAttrType ) )
                     {
-                        Index<?, String> index = getUserIndex( oldRdnAttrType );
-                        ( ( Index ) index ).drop( oldNormValue, id );
+                        Index<?, String> userIndex = getUserIndex( oldRdnAttrType );
+                        
+                        String normalized = oldRdnAttrType.getEquality().getNormalizer().normalize( oldNormValue );
+                        ( ( Index ) userIndex ).drop( normalized, 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( oldId ) )
+                        if ( null == userIndex.reverseLookup( oldId ) )
                         {
-                            presenceIdx.drop( oldNormType, oldId );
+                            String oldNormTypeOid = presenceNormalizer.normalize( oldNormType );
+                            presenceIdx.drop( oldNormTypeOid, oldId );
                         }
                     }
                 }
@@ -2286,6 +2463,7 @@ public abstract class AbstractBTreeParti
      * {@inheritDoc}
      */
     @SuppressWarnings("unchecked")
+    @Override
     public final synchronized void rename( Dn dn, Rdn newRdn, boolean deleteOldRdn, Entry entry ) throws Exception
     {
         String oldId = getEntryId( dn );
@@ -2327,6 +2505,7 @@ public abstract class AbstractBTreeParti
     /**
      * {@inheritDoc}
      */
+    @Override
     public final void unbind( UnbindOperationContext unbindContext ) throws LdapException
     {
         // does nothing
@@ -2338,6 +2517,7 @@ public abstract class AbstractBTreeParti
      * if it returns an entry by default.  Please override this method if
      * there is more effective way for your implementation.
      */
+    @Override
     public boolean hasEntry( HasEntryOperationContext entryContext ) throws LdapException
     {
         try
@@ -2404,12 +2584,12 @@ public abstract class AbstractBTreeParti
             
             if ( el != null )
             {
-                return ( Dn ) el.getValue();
+                return ( Dn ) el.getObjectValue();
             }
             
             do
             {
-                ParentIdAndRdn cur = null;
+                ParentIdAndRdn cur;
             
                 if ( piarCache != null )
                 {
@@ -2417,7 +2597,7 @@ public abstract class AbstractBTreeParti
                     
                     if ( piar != null )
                     {
-                        cur = ( ParentIdAndRdn ) piar.getValue();
+                        cur = ( ParentIdAndRdn ) piar.getObjectValue();
                     }
                     else
                     {
@@ -2475,6 +2655,7 @@ public abstract class AbstractBTreeParti
     /**
      * {@inheritDoc}
      */
+    @Override
     public long count() throws Exception
     {
         return master.count();
@@ -2484,6 +2665,7 @@ public abstract class AbstractBTreeParti
     /**
      * {@inheritDoc}
      */
+    @Override
     public final long getChildCount( String id ) throws LdapException
     {
         try
@@ -2502,6 +2684,7 @@ public abstract class AbstractBTreeParti
     /**
      * {@inheritDoc}
      */
+    @Override
     public final Dn getEntryDn( String id ) throws Exception
     {
         return buildEntryDn( id );
@@ -2511,6 +2694,7 @@ public abstract class AbstractBTreeParti
     /**
      * {@inheritDoc}
      */
+    @Override
     public final String getEntryId( Dn dn ) throws LdapException
     {
         try
@@ -2532,6 +2716,7 @@ public abstract class AbstractBTreeParti
                 {
                     Rdn rdn = dn.getRdn( i - 1 );
                     ParentIdAndRdn currentRdn = new ParentIdAndRdn( currentId, rdn );
+                    
                     currentId = rdnIdx.forwardLookup( currentRdn );
 
                     if ( currentId == null )
@@ -2557,6 +2742,7 @@ public abstract class AbstractBTreeParti
     /**
      * {@inheritDoc}
      */
+    @Override
     public String getParentId( String childId ) throws Exception
     {
         try
@@ -2581,7 +2767,7 @@ public abstract class AbstractBTreeParti
     /**
      * Retrieve the SuffixID
      */
-    protected String getSuffixId() throws Exception
+    public String getSuffixId() throws Exception
     {
         if ( suffixId == null )
         {
@@ -2608,6 +2794,7 @@ public abstract class AbstractBTreeParti
     /**
      * {@inheritDoc}
      */
+    @Override
     public void addIndex( Index<?, String> index ) throws Exception
     {
         checkInitialized( "addIndex" );
@@ -2681,6 +2868,7 @@ public abstract class AbstractBTreeParti
     /**
      * {@inheritDoc}
      */
+    @Override
     public Iterator<String> getUserIndices()
     {
         return userIndices.keySet().iterator();
@@ -2690,6 +2878,7 @@ public abstract class AbstractBTreeParti
     /**
      * {@inheritDoc}
      */
+    @Override
     public Iterator<String> getSystemIndices()
     {
         return systemIndices.keySet().iterator();
@@ -2699,6 +2888,7 @@ public abstract class AbstractBTreeParti
     /**
      * {@inheritDoc}
      */
+    @Override
     public Index<?, String> getIndex( AttributeType attributeType ) throws IndexNotFoundException
     {
         String id = attributeType.getOid();
@@ -2720,6 +2910,7 @@ public abstract class AbstractBTreeParti
     /**
      * {@inheritDoc}
      */
+    @Override
     public Index<?, String> getUserIndex( AttributeType attributeType ) throws IndexNotFoundException
     {
         if ( attributeType == null )
@@ -2741,6 +2932,7 @@ public abstract class AbstractBTreeParti
     /**
      * {@inheritDoc}
      */
+    @Override
     public Index<?, String> getSystemIndex( AttributeType attributeType ) throws IndexNotFoundException
     {
         if ( attributeType == null )
@@ -2763,6 +2955,7 @@ public abstract class AbstractBTreeParti
      * {@inheritDoc}
      */
     @SuppressWarnings("unchecked")
+    @Override
     public Index<Dn, String> getAliasIndex()
     {
         return ( Index<Dn, String> ) systemIndices.get( ApacheSchemaConstants.APACHE_ALIAS_AT_OID );
@@ -2773,6 +2966,7 @@ public abstract class AbstractBTreeParti
      * {@inheritDoc}
      */
     @SuppressWarnings("unchecked")
+    @Override
     public Index<String, String> getOneAliasIndex()
     {
         return ( Index<String, String> ) systemIndices.get( ApacheSchemaConstants.APACHE_ONE_ALIAS_AT_OID );
@@ -2783,6 +2977,7 @@ public abstract class AbstractBTreeParti
      * {@inheritDoc}
      */
     @SuppressWarnings("unchecked")
+    @Override
     public Index<String, String> getSubAliasIndex()
     {
         return ( Index<String, String> ) systemIndices.get( ApacheSchemaConstants.APACHE_SUB_ALIAS_AT_OID );
@@ -2793,6 +2988,7 @@ public abstract class AbstractBTreeParti
      * {@inheritDoc}
      */
     @SuppressWarnings("unchecked")
+    @Override
     public Index<String, String> getObjectClassIndex()
     {
         return ( Index<String, String> ) systemIndices.get( SchemaConstants.OBJECT_CLASS_AT_OID );
@@ -2803,6 +2999,7 @@ public abstract class AbstractBTreeParti
      * {@inheritDoc}
      */
     @SuppressWarnings("unchecked")
+    @Override
     public Index<String, String> getEntryCsnIndex()
     {
         return ( Index<String, String> ) systemIndices.get( SchemaConstants.ENTRY_CSN_AT_OID );
@@ -2823,6 +3020,7 @@ public abstract class AbstractBTreeParti
      * {@inheritDoc}
      */
     @SuppressWarnings("unchecked")
+    @Override
     public Index<String, String> getPresenceIndex()
     {
         return ( Index<String, String> ) systemIndices.get( ApacheSchemaConstants.APACHE_PRESENCE_AT_OID );
@@ -2833,6 +3031,7 @@ public abstract class AbstractBTreeParti
      * {@inheritDoc}
      */
     @SuppressWarnings("unchecked")
+    @Override
     public Index<ParentIdAndRdn, String> getRdnIndex()
     {
         return ( Index<ParentIdAndRdn, String> ) systemIndices.get( ApacheSchemaConstants.APACHE_RDN_AT_OID );
@@ -2842,15 +3041,18 @@ public abstract class AbstractBTreeParti
     /**
      * {@inheritDoc}
      */
+    @Override
     public boolean hasUserIndexOn( AttributeType attributeType ) throws LdapException
     {
-        return userIndices.containsKey( attributeType.getOid() );
+        String oid = attributeType.getOid();
+        return userIndices.containsKey( oid );
     }
 
 
     /**
      * {@inheritDoc}
      */
+    @Override
     public boolean hasSystemIndexOn( AttributeType attributeType ) throws LdapException
     {
         return systemIndices.containsKey( attributeType.getOid() );
@@ -2860,6 +3062,7 @@ public abstract class AbstractBTreeParti
     /**
      * {@inheritDoc}
      */
+    @Override
     public boolean hasIndexOn( AttributeType attributeType ) throws LdapException
     {
         return hasUserIndexOn( attributeType ) || hasSystemIndexOn( attributeType );
@@ -2897,9 +3100,7 @@ public abstract class AbstractBTreeParti
         if ( !aliasTarget.isDescendantOf( suffixDn ) )
         {
             String msg = I18n.err( I18n.ERR_225, suffixDn.getName() );
-            LdapAliasDereferencingException e = new LdapAliasDereferencingException( msg );
-            //e.setResolvedName( aliasDn );
-            throw e;
+            throw new LdapAliasDereferencingException( msg );
         }
 
         // L O O K U P   T A R G E T   I D
@@ -2915,9 +3116,7 @@ public abstract class AbstractBTreeParti
         {
             // Complain about target not existing
             String msg = I18n.err( I18n.ERR_581, aliasDn.getName(), aliasTarget );
-            LdapAliasException e = new LdapAliasException( msg );
-            //e.setResolvedName( aliasDn );
-            throw e;
+            throw new LdapAliasException( msg );
         }
 
         /*
@@ -2933,9 +3132,7 @@ public abstract class AbstractBTreeParti
         if ( null != aliasIdx.reverseLookup( targetId ) )
         {
             String msg = I18n.err( I18n.ERR_227 );
-            LdapAliasDereferencingException e = new LdapAliasDereferencingException( msg );
-            //e.setResolvedName( aliasDn );
-            throw e;
+            throw new LdapAliasDereferencingException( msg );
         }
 
         // Add the alias to the simple alias index
@@ -2999,7 +3196,12 @@ public abstract class AbstractBTreeParti
     protected void dropAliasIndices( String aliasId ) throws Exception
     {
         Dn targetDn = aliasIdx.reverseLookup( aliasId );
-        targetDn.apply( schemaManager );
+        
+        if ( !targetDn.isSchemaAware() )
+        {
+            targetDn = new Dn( schemaManager, targetDn );
+        }
+
         String targetId = getEntryId( targetDn );
 
         if ( targetId == null )
@@ -3062,7 +3264,11 @@ public abstract class AbstractBTreeParti
         
         if ( targetDn != null )
         {
-            targetDn.apply( schemaManager );
+            if ( !targetDn.isSchemaAware() )
+            {
+                targetDn = new Dn( schemaManager, targetDn );
+            }
+
             String targetId = getEntryId( targetDn );
             Dn aliasDn = getEntryDn( movedBaseId );
 
@@ -3129,6 +3335,7 @@ public abstract class AbstractBTreeParti
     /**
      * {@inheritDoc}
      */
+    @Override
     public void dumpIndex( OutputStream stream, String name ) throws IOException
     {
         try
@@ -3157,6 +3364,7 @@ public abstract class AbstractBTreeParti
     /**
      * {@inheritDoc}
      */
+    @Override
     public String toString()
     {
         return "Partition<" + id + ">";
@@ -3177,6 +3385,7 @@ public abstract class AbstractBTreeParti
     /**
      * {@inheritDoc}
      */
+    @Override
     public MasterTable getMasterTable()
     {
         return master;
@@ -3308,6 +3517,7 @@ public abstract class AbstractBTreeParti
     /**
      * {@inheritDoc}
      */
+    @Override
     public ReadWriteLock getReadWriteLock()
     {
         return rwLock;
@@ -3317,6 +3527,7 @@ public abstract class AbstractBTreeParti
     /**
      * {@inheritDoc}
      */
+    @Override
     public Cache getAliasCache()
     {
         return aliasCache;
@@ -3380,6 +3591,7 @@ public abstract class AbstractBTreeParti
      */
     // store the contextCSN value in the context entry 
     // note that this modification shouldn't change the entryCSN value of the context entry
+    @Override
     public void saveContextCsn() throws LdapException
     {
         if ( !ctxCsnChanged )
@@ -3429,6 +3641,7 @@ public abstract class AbstractBTreeParti
      * @return The Subordinate instance that contains the values.
      * @throws LdapException If we had an issue while processing the request
      */
+    @Override
     public Subordinates getSubordinates( Entry entry ) throws LdapException
     {
         Subordinates subordinates = new Subordinates();

Modified: directory/apacheds/branches/apacheds-value/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/ParentIdAndRdn.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-value/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/ParentIdAndRdn.java?rev=1748572&r1=1748571&r2=1748572&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-value/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/ParentIdAndRdn.java (original)
+++ directory/apacheds/branches/apacheds-value/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/ParentIdAndRdn.java Wed Jun 15 12:29:57 2016
@@ -189,6 +189,7 @@ public class ParentIdAndRdn implements E
     /**
      * {@inheritDoc}
      */
+    @Override
     public int compareTo( ParentIdAndRdn that )
     {
         // Special case when that.rdns = null : we are searching for oneLevel or subLevel scope
@@ -229,7 +230,6 @@ public class ParentIdAndRdn implements E
         }
 
         // The ID is the same, check the RDNs now
-
         val = rdns.length - that.rdns.length;
 
         if ( val != 0 )
@@ -240,15 +240,29 @@ public class ParentIdAndRdn implements E
         if ( rdns.length == 1 )
         {
             // Special case : we only have one rdn.
-            val = rdns[0].getNormName().compareTo( that.rdns[0].getNormName() );
+            // first try with the normalized name
+            if ( rdns[0].getNormName() != null )
+            {
+                return rdns[0].getNormName().compareTo( that.rdns[0].getNormName() );
+            }
+
+            val = rdns[0].compareTo( that.rdns[0] );
 
             return val;
         }
         else
         {
+            // We need to compare the Rdns in the order they are given.
+            // Actually, this is a Dn, not a Rdn.
             for ( int i = 0; i < rdns.length; i++ )
             {
-                val = rdns[i].getNormName().compareTo( that.rdns[i].getNormName() );
+                // first try with the normalized name
+                if ( rdns[i].getNormName() != null )
+                {
+                    return rdns[i].getNormName().compareTo( that.rdns[i].getNormName() );
+                }
+
+                val = rdns[i].compareTo( that.rdns[i] );
 
                 if ( val != 0 )
                 {
@@ -261,6 +275,10 @@ public class ParentIdAndRdn implements E
     }
 
 
+    /**
+     * {@inheritDoc}
+     */
+    @Override
     public void writeExternal( ObjectOutput out ) throws IOException
     {
         out.writeUTF( parentId );
@@ -275,7 +293,11 @@ public class ParentIdAndRdn implements E
     }
 
 
+    /**
+     * {@inheritDoc}
+     */
     @SuppressWarnings("unchecked")
+    @Override
     public void readExternal( ObjectInput in ) throws IOException, ClassNotFoundException
     {
         parentId = in.readUTF();
@@ -334,6 +356,7 @@ public class ParentIdAndRdn implements E
     /**
      * {@inheritDoc}
      */
+    @Override
     public String toString()
     {
         StringBuilder sb = new StringBuilder();

Modified: directory/apacheds/branches/apacheds-value/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/Store.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-value/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/Store.java?rev=1748572&r1=1748571&r2=1748572&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-value/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/Store.java (original)
+++ directory/apacheds/branches/apacheds-value/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/Store.java Wed Jun 15 12:29:57 2016
@@ -25,6 +25,8 @@ import java.util.Arrays;
 import java.util.Collections;
 import java.util.HashSet;
 import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
 import java.util.Set;
 import java.util.concurrent.locks.ReadWriteLock;
 
@@ -38,6 +40,7 @@ import org.apache.directory.api.ldap.mod
 import org.apache.directory.api.ldap.model.name.Rdn;
 import org.apache.directory.api.ldap.model.schema.AttributeType;
 import org.apache.directory.server.constants.ApacheSchemaConstants;
+import org.apache.directory.server.core.api.interceptor.context.ModDnAva;
 
 
 /**
@@ -192,6 +195,12 @@ public interface Store
 
 
     /**
+     * Retrieve the SuffixID
+     */
+    String getSuffixId() throws Exception;
+
+
+    /**
      * @return The Rdn system index
      */
     Index<ParentIdAndRdn, String> getRdnIndex();
@@ -389,7 +398,20 @@ public interface Store
     void rename( Dn dn, Rdn newRdn, boolean deleteOldRdn, Entry entry ) throws Exception;
 
 
-    void moveAndRename( Dn oldChildDn, Dn newParentDn, Rdn newRdn, Entry entry, boolean deleteOldRdn ) throws Exception;
+    /**
+     * Move and Rename operation. The entry is moved from one part of the DIT to another part of 
+     * the DIT. Its RDN is also changed in the process.
+     * 
+     * @param oldDn The previous DN
+     * @param newSuperiorDn The previous parent's DN
+     * @param newDn The new DN
+     * @param modAvas The changed Attributes caused by the renaming (added and removed attributes)
+     * @param entry the entry to move
+     * @throws Exception If the modification failed
+     */
+    void moveAndRename( Dn oldDn, Dn newSuperiorDn, Rdn newRdn, Map<String, List<ModDnAva>> modAvas, 
+        Entry modifiedEntry ) throws Exception;
+    //void moveAndRename( Dn oldDn, Dn newSuperiorDn, Rdn newRdn, Entry entry, boolean deleteOldRdn ) throws Exception;
 
 
     /**

Modified: directory/apacheds/branches/apacheds-value/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/cursor/ApproximateCursor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-value/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/cursor/ApproximateCursor.java?rev=1748572&r1=1748571&r2=1748572&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-value/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/cursor/ApproximateCursor.java (original)
+++ directory/apacheds/branches/apacheds-value/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/cursor/ApproximateCursor.java Wed Jun 15 12:29:57 2016
@@ -88,12 +88,12 @@ public class ApproximateCursor<V> extend
         this.approximateEvaluator = approximateEvaluator;
 
         AttributeType attributeType = approximateEvaluator.getExpression().getAttributeType();
-        Value<V> value = approximateEvaluator.getExpression().getValue();
+        Value value = approximateEvaluator.getExpression().getValue();
 
         if ( store.hasIndexOn( attributeType ) )
         {
             Index<V, String> index = ( Index<V, String> ) store.getIndex( attributeType );
-            userIdxCursor = index.forwardCursor( value.getValue() );
+            userIdxCursor = index.forwardCursor( ( V ) value.getValue() );
             uuidIdxCursor = null;
         }
         else

Modified: directory/apacheds/branches/apacheds-value/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/cursor/EqualityCursor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-value/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/cursor/EqualityCursor.java?rev=1748572&r1=1748571&r2=1748572&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-value/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/cursor/EqualityCursor.java (original)
+++ directory/apacheds/branches/apacheds-value/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/cursor/EqualityCursor.java Wed Jun 15 12:29:57 2016
@@ -86,12 +86,13 @@ public class EqualityCursor<V> extends A
         this.equalityEvaluator = equalityEvaluator;
 
         AttributeType attributeType = equalityEvaluator.getExpression().getAttributeType();
-        Value<V> value = equalityEvaluator.getExpression().getValue();
+        Value value = equalityEvaluator.getExpression().getValue();
 
         if ( store.hasIndexOn( attributeType ) )
         {
             Index<V, String> userIndex = ( Index<V, String> ) store.getIndex( attributeType );
-            userIdxCursor = userIndex.forwardCursor( value.getValue() );
+            String normalizedValue = attributeType.getEquality().getNormalizer().normalize( value.getValue() );
+            userIdxCursor = userIndex.forwardCursor( ( V ) normalizedValue );
             uuidIdxCursor = null;
         }
         else

Modified: directory/apacheds/branches/apacheds-value/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/cursor/GreaterEqCursor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-value/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/cursor/GreaterEqCursor.java?rev=1748572&r1=1748571&r2=1748572&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-value/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/cursor/GreaterEqCursor.java (original)
+++ directory/apacheds/branches/apacheds-value/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/cursor/GreaterEqCursor.java Wed Jun 15 12:29:57 2016
@@ -205,7 +205,8 @@ public class GreaterEqCursor<V> extends
         if ( userIdxCursor != null )
         {
             IndexEntry<V, String> advanceTo = new IndexEntry<V, String>();
-            advanceTo.setKey( ( V ) greaterEqEvaluator.getExpression().getValue().getValue() );
+            String normalizedNode = greaterEqEvaluator.getNormalizer().normalize( greaterEqEvaluator.getExpression().getValue().getValue() );
+            advanceTo.setKey( ( V ) normalizedNode );
             userIdxCursor.before( advanceTo );
         }
         else

Modified: directory/apacheds/branches/apacheds-value/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/cursor/LessEqCursor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-value/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/cursor/LessEqCursor.java?rev=1748572&r1=1748571&r2=1748572&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-value/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/cursor/LessEqCursor.java (original)
+++ directory/apacheds/branches/apacheds-value/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/cursor/LessEqCursor.java Wed Jun 15 12:29:57 2016
@@ -222,11 +222,15 @@ public class LessEqCursor<V> extends Abs
     public void afterLast() throws LdapException, CursorException
     {
         checkNotClosed( "afterLast()" );
+        
         if ( userIdxCursor != null )
         {
             IndexEntry<V, String> advanceTo = new IndexEntry<V, String>();
             //noinspection unchecked
-            advanceTo.setKey( lessEqEvaluator.getExpression().getValue().getValue() );
+            String normalizedKey = lessEqEvaluator.getAttributeType().getEquality().getNormalizer().normalize( 
+                lessEqEvaluator.getExpression().getValue().getValue() );
+            
+            advanceTo.setKey( ( V ) normalizedKey );
             userIdxCursor.after( advanceTo );
         }
         else

Modified: directory/apacheds/branches/apacheds-value/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/cursor/SubstringCursor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-value/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/cursor/SubstringCursor.java?rev=1748572&r1=1748571&r2=1748572&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-value/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/cursor/SubstringCursor.java (original)
+++ directory/apacheds/branches/apacheds-value/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/cursor/SubstringCursor.java Wed Jun 15 12:29:57 2016
@@ -27,6 +27,7 @@ import org.apache.directory.api.ldap.mod
 import org.apache.directory.api.ldap.model.cursor.CursorException;
 import org.apache.directory.api.ldap.model.cursor.InvalidCursorPositionException;
 import org.apache.directory.api.ldap.model.exception.LdapException;
+import org.apache.directory.api.ldap.model.schema.PrepareString;
 import org.apache.directory.server.i18n.I18n;
 import org.apache.directory.server.xdbm.AbstractIndexCursor;
 import org.apache.directory.server.xdbm.Index;
@@ -110,7 +111,9 @@ public class SubstringCursor extends Abs
         if ( evaluator.getExpression().getInitial() != null && hasIndex )
         {
             IndexEntry<String, String> indexEntry = new IndexEntry<String, String>();
-            indexEntry.setKey( evaluator.getExpression().getInitial() );
+            String normalizedKey = evaluator.getExpression().getAttributeType().getEquality().getNormalizer().normalize( 
+                evaluator.getExpression().getInitial(), PrepareString.AssertionType.SUBSTRING_INITIAL );
+            indexEntry.setKey( normalizedKey );
             wrapped.before( indexEntry );
         }
         else

Modified: directory/apacheds/branches/apacheds-value/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/evaluator/AndEvaluator.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-value/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/evaluator/AndEvaluator.java?rev=1748572&r1=1748571&r2=1748572&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-value/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/evaluator/AndEvaluator.java (original)
+++ directory/apacheds/branches/apacheds-value/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/evaluator/AndEvaluator.java Wed Jun 15 12:29:57 2016
@@ -73,13 +73,75 @@ public class AndEvaluator implements Eva
     private List<Evaluator<? extends ExprNode>> optimize(
         List<Evaluator<? extends ExprNode>> unoptimized )
     {
-        List<Evaluator<? extends ExprNode>> optimized = new ArrayList<Evaluator<? extends ExprNode>>(
-            unoptimized.size() );
-        optimized.addAll( unoptimized );
+        switch ( unoptimized.size() )
+        {
+            case 0 :
+            case 1 :
+                return unoptimized;
+                
+            case 2 :
+                Object count1 = unoptimized.get( 0 ).getExpression().get( "count" );
+                Object count2 = unoptimized.get( 1 ).getExpression().get( "count" );
+                
+                if ( count1 == null )
+                {
+                    if ( count2 != null )
+                    {
+                        unoptimized.add( unoptimized.remove( 0 ) );
+                    }
+                }
+                else
+                {
+                    if ( ( count2 != null ) && ( ( Long ) count1 > ( Long ) count2 ) )
+                    {
+                        unoptimized.add( unoptimized.remove( 0 ) );
+                    }
+                }
+                
+                return unoptimized;
 
-        Collections.sort( optimized, new ScanCountComparator() );
+            default :
+                List<Evaluator<? extends ExprNode>> optimized = new ArrayList<Evaluator<? extends ExprNode>>(
+                    unoptimized.size() );
+                optimized.addAll( unoptimized );
 
-        return optimized;
+                Collections.sort( optimized, new ScanCountComparator() );
+
+                return evaluators;
+        }
+        
+        /* Potential speed up, for when we do'nt care about the evaluation itself.
+    private List<Evaluator<? extends ExprNode>> optimize(
+        List<Evaluator<? extends ExprNode>> evaluators )
+    {
+        long minCount = Long.MAX_VALUE;
+        int pos = 0;
+        int minPos = 0;
+        
+        for ( Evaluator<? extends ExprNode> evaluator : evaluators )
+        {
+            long count = ( Long ) evaluator.getExpression().get( "count" );
+            
+            if ( count < minCount )
+            {
+                minCount = count;
+                minPos = pos;
+            }
+            
+            pos++;
+        }
+        
+        if ( minPos > 0 )
+        {
+            Evaluator<? extends ExprNode> minEvaluator = evaluators.remove( minPos );
+            evaluators.set( 0,  minEvaluator );
+            
+        }
+
+        return evaluators;
+    }
+
+         */
     }
 
 

Modified: directory/apacheds/branches/apacheds-value/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/evaluator/ApproximateEvaluator.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-value/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/evaluator/ApproximateEvaluator.java?rev=1748572&r1=1748571&r2=1748572&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-value/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/evaluator/ApproximateEvaluator.java (original)
+++ directory/apacheds/branches/apacheds-value/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/evaluator/ApproximateEvaluator.java Wed Jun 15 12:29:57 2016
@@ -82,6 +82,7 @@ public class ApproximateEvaluator<T> ext
     /**
      * {@inheritDoc}
      */
+    @Override
     public ApproximateNode<T> getExpression()
     {
         return ( ApproximateNode<T> ) node;
@@ -91,6 +92,7 @@ public class ApproximateEvaluator<T> ext
     /**
      * {@inheritDoc}
      */
+    @Override
     public boolean evaluate( Entry entry ) throws LdapException
     {
         // get the attribute
@@ -133,6 +135,7 @@ public class ApproximateEvaluator<T> ext
     /**
      * {@inheritDoc}
      */
+    @Override
     public boolean evaluate( IndexEntry<?, String> indexEntry ) throws LdapException
     {
         Entry entry = indexEntry.getEntry();
@@ -166,9 +169,9 @@ public class ApproximateEvaluator<T> ext
          * appropriate matching rule to perform the check.
          */
 
-        for ( Value<?> value : attribute )
+        for ( Value value : attribute )
         {
-            if ( ldapComparator.compare( value.getNormValue(), node.getValue().getNormValue() ) == 0 )
+            if ( value.compareTo( node.getValue() )  == 0 )
             {
                 return true;
             }
@@ -181,6 +184,7 @@ public class ApproximateEvaluator<T> ext
     /**
      * @see Object#toString()
      */
+    @Override
     public String toString( String tabs )
     {
         StringBuilder sb = new StringBuilder();
@@ -194,6 +198,7 @@ public class ApproximateEvaluator<T> ext
     /**
      * @see Object#toString()
      */
+    @Override
     public String toString()
     {
         return toString( "" );



Mime
View raw message