directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1389184 [2/13] - in /directory/apacheds/trunk: core-annotations/src/main/java/org/apache/directory/server/core/factory/ core-api/src/main/java/org/apache/directory/server/core/api/ core-api/src/main/java/org/apache/directory/server/core/ap...
Date Mon, 24 Sep 2012 02:17:20 GMT
Modified: directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/DefaultOperationManager.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/DefaultOperationManager.java?rev=1389184&r1=1389183&r2=1389184&view=diff
==============================================================================
--- directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/DefaultOperationManager.java (original)
+++ directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/DefaultOperationManager.java Mon Sep 24 02:17:13 2012
@@ -22,6 +22,8 @@ package org.apache.directory.server.core
 
 import java.util.ArrayList;
 import java.util.List;
+import java.util.concurrent.locks.ReadWriteLock;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
 
 import org.apache.directory.server.core.api.CoreSession;
 import org.apache.directory.server.core.api.DirectoryService;
@@ -75,12 +77,18 @@ public class DefaultOperationManager imp
     /** The logger */
     private static final Logger LOG = LoggerFactory.getLogger( DefaultOperationManager.class );
 
+    /** Speedup for logs */
+    private static final boolean IS_DEBUG = LOG.isDebugEnabled();
+
     /** A logger specifically for change operations */
     private static final Logger LOG_CHANGES = LoggerFactory.getLogger( "LOG_CHANGES" );
 
     /** The directory service instance */
     private final DirectoryService directoryService;
 
+    /** A lock used to protect against concurrent operations */
+    private ReadWriteLock rwLock = new ReentrantReadWriteLock( true );
+
 
     public DefaultOperationManager( DirectoryService directoryService )
     {
@@ -89,6 +97,42 @@ public class DefaultOperationManager imp
 
 
     /**
+     * Acquires a ReadLock
+     */
+    private void lockRead()
+    {
+        rwLock.readLock().lock();
+    }
+
+
+    /**
+     * Acquires a WriteLock
+     */
+    private void lockWrite()
+    {
+        rwLock.writeLock().lock();
+    }
+
+
+    /**
+     * Releases a ReadLock
+     */
+    private void unlockRead()
+    {
+        rwLock.readLock().unlock();
+    }
+
+
+    /**
+     * Releases a WriteLock
+     */
+    private void unlockWrite()
+    {
+        rwLock.writeLock().unlock();
+    }
+
+
+    /**
      * Eagerly populates fields of operation contexts so multiple Interceptors
      * in the processing pathway can reuse this value without performing a
      * redundant lookup operation.
@@ -278,8 +322,11 @@ public class DefaultOperationManager imp
      */
     public void add( AddOperationContext addContext ) throws LdapException
     {
-        LOG.debug( ">> AddOperation : {}", addContext );
-        LOG_CHANGES.debug( ">> AddOperation : {}", addContext );
+        if ( IS_DEBUG )
+        {
+            LOG.debug( ">> AddOperation : {}", addContext );
+            LOG_CHANGES.debug( ">> AddOperation : {}", addContext );
+        }
 
         ensureStarted();
 
@@ -321,11 +368,23 @@ public class DefaultOperationManager imp
             // Call the Add method
             Interceptor head = directoryService.getInterceptor( addContext.getNextInterceptor() );
 
-            head.add( addContext );
+            try
+            {
+                lockWrite();
+
+                head.add( addContext );
+            }
+            finally
+            {
+                unlockWrite();
+            }
         }
 
-        LOG.debug( "<< AddOperation successful" );
-        LOG_CHANGES.debug( "<< AddOperation successful" );
+        if ( IS_DEBUG )
+        {
+            LOG.debug( "<< AddOperation successful" );
+            LOG_CHANGES.debug( "<< AddOperation successful" );
+        }
     }
 
 
@@ -334,16 +393,31 @@ public class DefaultOperationManager imp
      */
     public void bind( BindOperationContext bindContext ) throws LdapException
     {
-        LOG.debug( ">> BindOperation : {}", bindContext );
+        if ( IS_DEBUG )
+        {
+            LOG.debug( ">> BindOperation : {}", bindContext );
+        }
 
         ensureStarted();
 
         // Call the Delete method
         Interceptor head = directoryService.getInterceptor( bindContext.getNextInterceptor() );
 
-        head.bind( bindContext );
+        try
+        {
+            lockRead();
 
-        LOG.debug( "<< BindOperation successful" );
+            head.bind( bindContext );
+        }
+        finally
+        {
+            unlockRead();
+        }
+
+        if ( IS_DEBUG )
+        {
+            LOG.debug( "<< BindOperation successful" );
+        }
     }
 
 
@@ -352,7 +426,10 @@ public class DefaultOperationManager imp
      */
     public boolean compare( CompareOperationContext compareContext ) throws LdapException
     {
-        LOG.debug( ">> CompareOperation : {}", compareContext );
+        if ( IS_DEBUG )
+        {
+            LOG.debug( ">> CompareOperation : {}", compareContext );
+        }
 
         ensureStarted();
         // Normalize the compareContext Dn
@@ -415,9 +492,23 @@ public class DefaultOperationManager imp
         // Call the Compare method
         Interceptor head = directoryService.getInterceptor( compareContext.getNextInterceptor() );
 
-        boolean result = head.compare( compareContext );
+        boolean result = false;
+
+        try
+        {
+            lockRead();
+
+            result = head.compare( compareContext );
+        }
+        finally
+        {
+            unlockRead();
+        }
 
-        LOG.debug( "<< CompareOperation successful" );
+        if ( IS_DEBUG )
+        {
+            LOG.debug( "<< CompareOperation successful" );
+        }
 
         return result;
     }
@@ -428,8 +519,11 @@ public class DefaultOperationManager imp
      */
     public void delete( DeleteOperationContext deleteContext ) throws LdapException
     {
-        LOG.debug( ">> DeleteOperation : {}", deleteContext );
-        LOG_CHANGES.debug( ">> DeleteOperation : {}", deleteContext );
+        if ( IS_DEBUG )
+        {
+            LOG.debug( ">> DeleteOperation : {}", deleteContext );
+            LOG_CHANGES.debug( ">> DeleteOperation : {}", deleteContext );
+        }
 
         ensureStarted();
 
@@ -489,15 +583,27 @@ public class DefaultOperationManager imp
         directoryService.getReferralManager().unlock();
 
         // populate the context with the old entry
-        eagerlyPopulateFields( deleteContext );
+        try
+        {
+            lockWrite();
 
-        // Call the Delete method
-        Interceptor head = directoryService.getInterceptor( deleteContext.getNextInterceptor() );
+            eagerlyPopulateFields( deleteContext );
 
-        head.delete( deleteContext );
+            // Call the Delete method
+            Interceptor head = directoryService.getInterceptor( deleteContext.getNextInterceptor() );
 
-        LOG.debug( "<< DeleteOperation successful" );
-        LOG_CHANGES.debug( "<< DeleteOperation successful" );
+            head.delete( deleteContext );
+        }
+        finally
+        {
+            unlockWrite();
+        }
+
+        if ( IS_DEBUG )
+        {
+            LOG.debug( "<< DeleteOperation successful" );
+            LOG_CHANGES.debug( "<< DeleteOperation successful" );
+        }
     }
 
 
@@ -506,7 +612,10 @@ public class DefaultOperationManager imp
      */
     public Entry getRootDse( GetRootDseOperationContext getRootDseContext ) throws LdapException
     {
-        LOG.debug( ">> GetRootDseOperation : {}", getRootDseContext );
+        if ( IS_DEBUG )
+        {
+            LOG.debug( ">> GetRootDseOperation : {}", getRootDseContext );
+        }
 
         ensureStarted();
 
@@ -514,7 +623,10 @@ public class DefaultOperationManager imp
 
         Entry root = head.getRootDse( getRootDseContext );
 
-        LOG.debug( "<< getRootDseOperation successful" );
+        if ( IS_DEBUG )
+        {
+            LOG.debug( "<< getRootDseOperation successful" );
+        }
 
         return root;
     }
@@ -525,15 +637,32 @@ public class DefaultOperationManager imp
      */
     public boolean hasEntry( HasEntryOperationContext hasEntryContext ) throws LdapException
     {
-        LOG.debug( ">> hasEntryOperation : {}", hasEntryContext );
+        if ( IS_DEBUG )
+        {
+            LOG.debug( ">> hasEntryOperation : {}", hasEntryContext );
+        }
 
         ensureStarted();
 
         Interceptor head = directoryService.getInterceptor( hasEntryContext.getNextInterceptor() );
 
-        boolean result = head.hasEntry( hasEntryContext );
+        boolean result = false;
 
-        LOG.debug( "<< HasEntryOperation successful" );
+        try
+        {
+            lockRead();
+
+            result = head.hasEntry( hasEntryContext );
+        }
+        finally
+        {
+            unlockRead();
+        }
+
+        if ( IS_DEBUG )
+        {
+            LOG.debug( "<< HasEntryOperation successful" );
+        }
 
         return result;
     }
@@ -544,15 +673,32 @@ public class DefaultOperationManager imp
      */
     public EntryFilteringCursor list( ListOperationContext listContext ) throws LdapException
     {
-        LOG.debug( ">> ListOperation : {}", listContext );
+        if ( IS_DEBUG )
+        {
+            LOG.debug( ">> ListOperation : {}", listContext );
+        }
 
         ensureStarted();
 
         Interceptor head = directoryService.getInterceptor( listContext.getNextInterceptor() );
 
-        EntryFilteringCursor cursor = head.list( listContext );
+        EntryFilteringCursor cursor = null;
+
+        try
+        {
+            lockRead();
 
-        LOG.debug( "<< ListOperation successful" );
+            cursor = head.list( listContext );
+        }
+        finally
+        {
+            unlockRead();
+        }
+
+        if ( IS_DEBUG )
+        {
+            LOG.debug( "<< ListOperation successful" );
+        }
 
         return cursor;
     }
@@ -563,15 +709,32 @@ public class DefaultOperationManager imp
      */
     public Entry lookup( LookupOperationContext lookupContext ) throws LdapException
     {
-        LOG.debug( ">> LookupOperation : {}", lookupContext );
+        if ( IS_DEBUG )
+        {
+            LOG.debug( ">> LookupOperation : {}", lookupContext );
+        }
 
         ensureStarted();
 
         Interceptor head = directoryService.getInterceptor( lookupContext.getNextInterceptor() );
 
-        Entry entry = head.lookup( lookupContext );
+        Entry entry = null;
+
+        try
+        {
+            lockRead();
+
+            entry = head.lookup( lookupContext );
+        }
+        finally
+        {
+            unlockRead();
+        }
 
-        LOG.debug( "<< LookupOperation successful" );
+        if ( IS_DEBUG )
+        {
+            LOG.debug( "<< LookupOperation successful" );
+        }
 
         return entry;
     }
@@ -582,8 +745,11 @@ public class DefaultOperationManager imp
      */
     public void modify( ModifyOperationContext modifyContext ) throws LdapException
     {
-        LOG.debug( ">> ModifyOperation : {}", modifyContext );
-        LOG_CHANGES.debug( ">> ModifyOperation : {}", modifyContext );
+        if ( IS_DEBUG )
+        {
+            LOG.debug( ">> ModifyOperation : {}", modifyContext );
+            LOG_CHANGES.debug( ">> ModifyOperation : {}", modifyContext );
+        }
 
         ensureStarted();
 
@@ -651,16 +817,28 @@ public class DefaultOperationManager imp
         // Unlock the ReferralManager
         referralManager.unlock();
 
-        // populate the context with the old entry
-        eagerlyPopulateFields( modifyContext );
+        try
+        {
+            lockWrite();
+
+            // populate the context with the old entry
+            eagerlyPopulateFields( modifyContext );
 
-        // Call the Modify method
-        Interceptor head = directoryService.getInterceptor( modifyContext.getNextInterceptor() );
+            // Call the Modify method
+            Interceptor head = directoryService.getInterceptor( modifyContext.getNextInterceptor() );
 
-        head.modify( modifyContext );
+            head.modify( modifyContext );
+        }
+        finally
+        {
+            unlockWrite();
+        }
 
-        LOG.debug( "<< ModifyOperation successful" );
-        LOG_CHANGES.debug( "<< ModifyOperation successful" );
+        if ( IS_DEBUG )
+        {
+            LOG.debug( "<< ModifyOperation successful" );
+            LOG_CHANGES.debug( "<< ModifyOperation successful" );
+        }
     }
 
 
@@ -669,8 +847,11 @@ public class DefaultOperationManager imp
      */
     public void move( MoveOperationContext moveContext ) throws LdapException
     {
-        LOG.debug( ">> MoveOperation : {}", moveContext );
-        LOG_CHANGES.debug( ">> MoveOperation : {}", moveContext );
+        if ( IS_DEBUG )
+        {
+            LOG.debug( ">> MoveOperation : {}", moveContext );
+            LOG_CHANGES.debug( ">> MoveOperation : {}", moveContext );
+        }
 
         ensureStarted();
 
@@ -749,17 +930,29 @@ public class DefaultOperationManager imp
         // Unlock the ReferralManager
         directoryService.getReferralManager().unlock();
 
-        Entry originalEntry = getOriginalEntry( moveContext );
+        try
+        {
+            lockWrite();
 
-        moveContext.setOriginalEntry( originalEntry );
+            Entry originalEntry = getOriginalEntry( moveContext );
 
-        // Call the Move method
-        Interceptor head = directoryService.getInterceptor( moveContext.getNextInterceptor() );
+            moveContext.setOriginalEntry( originalEntry );
 
-        head.move( moveContext );
+            // Call the Move method
+            Interceptor head = directoryService.getInterceptor( moveContext.getNextInterceptor() );
 
-        LOG.debug( "<< MoveOperation successful" );
-        LOG_CHANGES.debug( "<< MoveOperation successful" );
+            head.move( moveContext );
+        }
+        finally
+        {
+            unlockWrite();
+        }
+
+        if ( IS_DEBUG )
+        {
+            LOG.debug( "<< MoveOperation successful" );
+            LOG_CHANGES.debug( "<< MoveOperation successful" );
+        }
     }
 
 
@@ -768,8 +961,11 @@ public class DefaultOperationManager imp
      */
     public void moveAndRename( MoveAndRenameOperationContext moveAndRenameContext ) throws LdapException
     {
-        LOG.debug( ">> MoveAndRenameOperation : {}", moveAndRenameContext );
-        LOG_CHANGES.debug( ">> MoveAndRenameOperation : {}", moveAndRenameContext );
+        if ( IS_DEBUG )
+        {
+            LOG.debug( ">> MoveAndRenameOperation : {}", moveAndRenameContext );
+            LOG_CHANGES.debug( ">> MoveAndRenameOperation : {}", moveAndRenameContext );
+        }
 
         ensureStarted();
 
@@ -850,16 +1046,28 @@ public class DefaultOperationManager imp
         // Unlock the ReferralManager
         directoryService.getReferralManager().unlock();
 
-        moveAndRenameContext.setOriginalEntry( getOriginalEntry( moveAndRenameContext ) );
-        moveAndRenameContext.setModifiedEntry( moveAndRenameContext.getOriginalEntry().clone() );
+        try
+        {
+            lockWrite();
+
+            moveAndRenameContext.setOriginalEntry( getOriginalEntry( moveAndRenameContext ) );
+            moveAndRenameContext.setModifiedEntry( moveAndRenameContext.getOriginalEntry().clone() );
 
-        // Call the MoveAndRename method
-        Interceptor head = directoryService.getInterceptor( moveAndRenameContext.getNextInterceptor() );
+            // Call the MoveAndRename method
+            Interceptor head = directoryService.getInterceptor( moveAndRenameContext.getNextInterceptor() );
 
-        head.moveAndRename( moveAndRenameContext );
+            head.moveAndRename( moveAndRenameContext );
+        }
+        finally
+        {
+            unlockWrite();
+        }
 
-        LOG.debug( "<< MoveAndRenameOperation successful" );
-        LOG_CHANGES.debug( "<< MoveAndRenameOperation successful" );
+        if ( IS_DEBUG )
+        {
+            LOG.debug( "<< MoveAndRenameOperation successful" );
+            LOG_CHANGES.debug( "<< MoveAndRenameOperation successful" );
+        }
     }
 
 
@@ -868,8 +1076,11 @@ public class DefaultOperationManager imp
      */
     public void rename( RenameOperationContext renameContext ) throws LdapException
     {
-        LOG.debug( ">> RenameOperation : {}", renameContext );
-        LOG_CHANGES.debug( ">> RenameOperation : {}", renameContext );
+        if ( IS_DEBUG )
+        {
+            LOG.debug( ">> RenameOperation : {}", renameContext );
+            LOG_CHANGES.debug( ">> RenameOperation : {}", renameContext );
+        }
 
         ensureStarted();
 
@@ -940,18 +1151,31 @@ public class DefaultOperationManager imp
 
         // Call the rename method
         // populate the context with the old entry
-        eagerlyPopulateFields( renameContext );
-        Entry originalEntry = getOriginalEntry( renameContext );
-        renameContext.setOriginalEntry( originalEntry );
-        renameContext.setModifiedEntry( originalEntry.clone() );
 
-        // Call the Rename method
-        Interceptor head = directoryService.getInterceptor( renameContext.getNextInterceptor() );
+        try
+        {
+            lockWrite();
+
+            eagerlyPopulateFields( renameContext );
+            Entry originalEntry = getOriginalEntry( renameContext );
+            renameContext.setOriginalEntry( originalEntry );
+            renameContext.setModifiedEntry( originalEntry.clone() );
 
-        head.rename( renameContext );
+            // Call the Rename method
+            Interceptor head = directoryService.getInterceptor( renameContext.getNextInterceptor() );
 
-        LOG.debug( "<< RenameOperation successful" );
-        LOG_CHANGES.debug( "<< RenameOperation successful" );
+            head.rename( renameContext );
+        }
+        finally
+        {
+            unlockWrite();
+        }
+
+        if ( IS_DEBUG )
+        {
+            LOG.debug( "<< RenameOperation successful" );
+            LOG_CHANGES.debug( "<< RenameOperation successful" );
+        }
     }
 
 
@@ -960,12 +1184,16 @@ public class DefaultOperationManager imp
      */
     public EntryFilteringCursor search( SearchOperationContext searchContext ) throws LdapException
     {
-        LOG.debug( ">> SearchOperation : {}", searchContext );
+        if ( IS_DEBUG )
+        {
+            LOG.debug( ">> SearchOperation : {}", searchContext );
+        }
 
         ensureStarted();
 
         // Normalize the searchContext Dn
         Dn dn = searchContext.getDn();
+
         dn.apply( directoryService.getSchemaManager() );
 
         // We have to deal with the referral first
@@ -1025,9 +1253,23 @@ public class DefaultOperationManager imp
         // Call the Search method
         Interceptor head = directoryService.getInterceptor( searchContext.getNextInterceptor() );
 
-        EntryFilteringCursor cursor = head.search( searchContext );
+        EntryFilteringCursor cursor = null;
 
-        LOG.debug( "<< SearchOperation successful" );
+        try
+        {
+            lockRead();
+
+            cursor = head.search( searchContext );
+        }
+        finally
+        {
+            unlockRead();
+        }
+
+        if ( IS_DEBUG )
+        {
+            LOG.debug( "<< SearchOperation successful" );
+        }
 
         return cursor;
     }
@@ -1038,7 +1280,10 @@ public class DefaultOperationManager imp
      */
     public void unbind( UnbindOperationContext unbindContext ) throws LdapException
     {
-        LOG.debug( ">> UnbindOperation : {}", unbindContext );
+        if ( IS_DEBUG )
+        {
+            LOG.debug( ">> UnbindOperation : {}", unbindContext );
+        }
 
         ensureStarted();
 
@@ -1053,7 +1298,10 @@ public class DefaultOperationManager imp
         {
         }
 
-        LOG.debug( "<< UnbindOperation successful" );
+        if ( IS_DEBUG )
+        {
+            LOG.debug( "<< UnbindOperation successful" );
+        }
     }
 
 

Modified: directory/apacheds/trunk/interceptors/admin/src/main/java/org/apache/directory/server/core/admin/AdministrativePointInterceptor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/interceptors/admin/src/main/java/org/apache/directory/server/core/admin/AdministrativePointInterceptor.java?rev=1389184&r1=1389183&r2=1389184&view=diff
==============================================================================
--- directory/apacheds/trunk/interceptors/admin/src/main/java/org/apache/directory/server/core/admin/AdministrativePointInterceptor.java (original)
+++ directory/apacheds/trunk/interceptors/admin/src/main/java/org/apache/directory/server/core/admin/AdministrativePointInterceptor.java Mon Sep 24 02:17:13 2012
@@ -31,7 +31,6 @@ import java.util.concurrent.locks.Reentr
 import javax.naming.directory.SearchControls;
 
 import org.apache.directory.server.constants.ServerDNConstants;
-import org.apache.directory.server.core.shared.DefaultCoreSession;
 import org.apache.directory.server.core.api.CoreSession;
 import org.apache.directory.server.core.api.DirectoryService;
 import org.apache.directory.server.core.api.InterceptorEnum;
@@ -63,6 +62,7 @@ import org.apache.directory.server.core.
 import org.apache.directory.server.core.api.interceptor.context.RenameOperationContext;
 import org.apache.directory.server.core.api.interceptor.context.SearchOperationContext;
 import org.apache.directory.server.core.api.partition.PartitionNexus;
+import org.apache.directory.server.core.shared.DefaultCoreSession;
 import org.apache.directory.shared.ldap.model.constants.AuthenticationLevel;
 import org.apache.directory.shared.ldap.model.constants.SchemaConstants;
 import org.apache.directory.shared.ldap.model.entry.Attribute;

Modified: directory/apacheds/trunk/interceptors/authz/src/main/java/org/apache/directory/server/core/authz/AciAuthorizationInterceptor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/interceptors/authz/src/main/java/org/apache/directory/server/core/authz/AciAuthorizationInterceptor.java?rev=1389184&r1=1389183&r2=1389184&view=diff
==============================================================================
--- directory/apacheds/trunk/interceptors/authz/src/main/java/org/apache/directory/server/core/authz/AciAuthorizationInterceptor.java (original)
+++ directory/apacheds/trunk/interceptors/authz/src/main/java/org/apache/directory/server/core/authz/AciAuthorizationInterceptor.java Mon Sep 24 02:17:13 2012
@@ -809,10 +809,7 @@ public class AciAuthorizationInterceptor
         LdapPrincipal principal = session.getEffectivePrincipal();
         Dn principalDn = principal.getDn();
 
-        if ( !principalDn.isSchemaAware() )
-        {
-            principalDn.apply( schemaManager );
-        }
+        principalDn.apply( schemaManager );
 
         // Bypass this interceptor if we disabled the AC subsystem or if the principal is the admin
         if ( isPrincipalAnAdministrator( principalDn ) || !directoryService.isAccessControlEnabled() )

Modified: directory/apacheds/trunk/interceptors/authz/src/main/java/org/apache/directory/server/core/authz/DefaultAuthorizationInterceptor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/interceptors/authz/src/main/java/org/apache/directory/server/core/authz/DefaultAuthorizationInterceptor.java?rev=1389184&r1=1389183&r2=1389184&view=diff
==============================================================================
--- directory/apacheds/trunk/interceptors/authz/src/main/java/org/apache/directory/server/core/authz/DefaultAuthorizationInterceptor.java (original)
+++ directory/apacheds/trunk/interceptors/authz/src/main/java/org/apache/directory/server/core/authz/DefaultAuthorizationInterceptor.java Mon Sep 24 02:17:13 2012
@@ -26,7 +26,6 @@ import java.util.Set;
 import javax.naming.NoPermissionException;
 
 import org.apache.directory.server.constants.ServerDNConstants;
-import org.apache.directory.server.core.shared.DefaultCoreSession;
 import org.apache.directory.server.core.api.CoreSession;
 import org.apache.directory.server.core.api.DirectoryService;
 import org.apache.directory.server.core.api.InterceptorEnum;
@@ -46,6 +45,8 @@ import org.apache.directory.server.core.
 import org.apache.directory.server.core.api.interceptor.context.SearchOperationContext;
 import org.apache.directory.server.core.api.interceptor.context.SearchingOperationContext;
 import org.apache.directory.server.core.api.partition.PartitionNexus;
+import org.apache.directory.server.core.shared.DefaultCoreSession;
+import org.apache.directory.server.core.shared.partition.DefaultPartitionNexus;
 import org.apache.directory.server.i18n.I18n;
 import org.apache.directory.shared.ldap.model.constants.AuthenticationLevel;
 import org.apache.directory.shared.ldap.model.entry.Attribute;
@@ -98,6 +99,7 @@ public class DefaultAuthorizationInterce
         }
     }
 
+
     /**
      * Creates a new instance of DefaultAuthorizationInterceptor.
      */
@@ -130,7 +132,8 @@ public class DefaultAuthorizationInterce
         // read in the administrators and cache their normalized names
         Set<String> newAdministrators = new HashSet<String>( 2 );
         Dn adminDn = directoryService.getDnFactory().create( ServerDNConstants.ADMIN_SYSTEM_DN_NORMALIZED );
-        CoreSession adminSession = new DefaultCoreSession( new LdapPrincipal( schemaManager, adminDn, AuthenticationLevel.STRONG ),
+        CoreSession adminSession = new DefaultCoreSession( new LdapPrincipal( schemaManager, adminDn,
+            AuthenticationLevel.STRONG ),
             directoryService );
 
         Entry adminGroup = nexus.lookup( new LookupOperationContext( adminSession, ADMIN_GROUP_DN ) );
@@ -191,7 +194,7 @@ public class DefaultAuthorizationInterce
             throw new LdapNoPermissionException( msg );
         }
 
-        if ( dn.size() > 2 && !isAnAdministrator(principalDn) )
+        if ( dn.size() > 2 && !isAnAdministrator( principalDn ) )
         {
             if ( dn.isDescendantOf( ADMIN_SYSTEM_DN ) )
             {
@@ -456,14 +459,14 @@ public class DefaultAuthorizationInterce
                 LOG.error( msg );
                 throw new LdapNoPermissionException( msg );
             }
-    
+
             if ( dn.isDescendantOf( GROUPS_BASE_DN ) )
             {
                 String msg = I18n.err( I18n.ERR_24, principalDn.getName(), dn.getName() );
                 LOG.error( msg );
                 throw new LdapNoPermissionException( msg );
             }
-            
+
             if ( dn.isDescendantOf( USERS_BASE_DN ) )
             {
                 String msg = I18n.err( I18n.ERR_24, principalDn.getName(), dn.getName() );
@@ -493,7 +496,7 @@ public class DefaultAuthorizationInterce
                     throw new LdapNoPermissionException( msg );
                 }
 
-                if ( normalizedDn.isDescendantOf( GROUPS_BASE_DN ) || normalizedDn.isDescendantOf( USERS_BASE_DN ))
+                if ( normalizedDn.isDescendantOf( GROUPS_BASE_DN ) || normalizedDn.isDescendantOf( USERS_BASE_DN ) )
                 {
                     // allow for self reads
                     if ( normalizedDn.equals( principalDn ) )
@@ -530,10 +533,7 @@ public class DefaultAuthorizationInterce
         Dn principalDn = opContext.getSession().getEffectivePrincipal().getDn();
         Dn dn = entry.getDn();
 
-        if ( !dn.isSchemaAware() )
-        {
-            dn.apply( opContext.getSession().getDirectoryService().getSchemaManager() );
-        }
+        dn.apply( opContext.getSession().getDirectoryService().getSchemaManager() );
 
         // Admin users gets full access to all entries
         if ( isAnAdministrator( principalDn ) )
@@ -555,7 +555,8 @@ public class DefaultAuthorizationInterce
             // stuff this if in here instead of up in outer if to prevent
             // constant needless reexecution for all entries in other depths
 
-            if ( dn.isDescendantOf( ADMIN_SYSTEM_DN ) || dn.isDescendantOf( GROUPS_BASE_DN ) || dn.isDescendantOf( USERS_BASE_DN ))
+            if ( dn.isDescendantOf( ADMIN_SYSTEM_DN ) || dn.isDescendantOf( GROUPS_BASE_DN )
+                || dn.isDescendantOf( USERS_BASE_DN ) )
             {
                 return false;
             }

Modified: directory/apacheds/trunk/interceptors/authz/src/main/java/org/apache/directory/server/core/authz/GroupCache.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/interceptors/authz/src/main/java/org/apache/directory/server/core/authz/GroupCache.java?rev=1389184&r1=1389183&r2=1389184&view=diff
==============================================================================
--- directory/apacheds/trunk/interceptors/authz/src/main/java/org/apache/directory/server/core/authz/GroupCache.java (original)
+++ directory/apacheds/trunk/interceptors/authz/src/main/java/org/apache/directory/server/core/authz/GroupCache.java Mon Sep 24 02:17:13 2012
@@ -185,6 +185,7 @@ public class GroupCache
             }
             catch ( Exception e )
             {
+                e.printStackTrace();
                 LdapOperationException le = new LdapOperationException( e.getMessage(), e );
                 le.initCause( e );
                 throw le;

Modified: directory/apacheds/trunk/interceptors/normalization/src/main/java/org/apache/directory/server/core/normalization/NormalizationInterceptor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/interceptors/normalization/src/main/java/org/apache/directory/server/core/normalization/NormalizationInterceptor.java?rev=1389184&r1=1389183&r2=1389184&view=diff
==============================================================================
--- directory/apacheds/trunk/interceptors/normalization/src/main/java/org/apache/directory/server/core/normalization/NormalizationInterceptor.java (original)
+++ directory/apacheds/trunk/interceptors/normalization/src/main/java/org/apache/directory/server/core/normalization/NormalizationInterceptor.java Mon Sep 24 02:17:13 2012
@@ -141,10 +141,7 @@ public class NormalizationInterceptor ex
      */
     public boolean compare( CompareOperationContext compareContext ) throws LdapException
     {
-        if ( !compareContext.getDn().isSchemaAware() )
-        {
-            compareContext.getDn().apply( schemaManager );
-        }
+        compareContext.getDn().apply( schemaManager );
 
         // Get the attributeType from the OID
         try
@@ -176,10 +173,7 @@ public class NormalizationInterceptor ex
     {
         Dn dn = deleteContext.getDn();
 
-        if ( !dn.isSchemaAware() )
-        {
-            dn.apply( schemaManager );
-        }
+        dn.apply( schemaManager );
 
         next( deleteContext );
     }
@@ -231,10 +225,7 @@ public class NormalizationInterceptor ex
      */
     public void modify( ModifyOperationContext modifyContext ) throws LdapException
     {
-        if ( !modifyContext.getDn().isSchemaAware() )
-        {
-            modifyContext.getDn().apply( schemaManager );
-        }
+        modifyContext.getDn().apply( schemaManager );
 
         if ( modifyContext.getModItems() != null )
         {
@@ -254,25 +245,10 @@ public class NormalizationInterceptor ex
      */
     public void move( MoveOperationContext moveContext ) throws LdapException
     {
-        if ( !moveContext.getDn().isSchemaAware() )
-        {
-            moveContext.getDn().apply( schemaManager );
-        }
-
-        if ( !moveContext.getOldSuperior().isSchemaAware() )
-        {
-            moveContext.getOldSuperior().apply( schemaManager );
-        }
-
-        if ( !moveContext.getNewSuperior().isSchemaAware() )
-        {
-            moveContext.getNewSuperior().apply( schemaManager );
-        }
-
-        if ( !moveContext.getNewDn().isSchemaAware() )
-        {
-            moveContext.getNewDn().apply( schemaManager );
-        }
+        moveContext.getDn().apply( schemaManager );
+        moveContext.getOldSuperior().apply( schemaManager );
+        moveContext.getNewSuperior().apply( schemaManager );
+        moveContext.getNewDn().apply( schemaManager );
 
         if ( !moveContext.getRdn().isSchemaAware() )
         {
@@ -293,20 +269,9 @@ public class NormalizationInterceptor ex
             moveAndRenameContext.getNewRdn().apply( schemaManager );
         }
 
-        if ( !moveAndRenameContext.getDn().isSchemaAware() )
-        {
-            moveAndRenameContext.getDn().apply( schemaManager );
-        }
-
-        if ( !moveAndRenameContext.getNewDn().isSchemaAware() )
-        {
-            moveAndRenameContext.getNewDn().apply( schemaManager );
-        }
-
-        if ( !moveAndRenameContext.getNewSuperiorDn().isSchemaAware() )
-        {
-            moveAndRenameContext.getNewSuperiorDn().apply( schemaManager );
-        }
+        moveAndRenameContext.getDn().apply( schemaManager );
+        moveAndRenameContext.getNewDn().apply( schemaManager );
+        moveAndRenameContext.getNewSuperiorDn().apply( schemaManager );
 
         next( moveAndRenameContext );
     }
@@ -318,18 +283,9 @@ public class NormalizationInterceptor ex
     public void rename( RenameOperationContext renameContext ) throws LdapException
     {
         // Normalize the new Rdn and the Dn if needed
-
-        if ( !renameContext.getDn().isSchemaAware() )
-        {
-            renameContext.getDn().apply( schemaManager );
-        }
-
+        renameContext.getDn().apply( schemaManager );
         renameContext.getNewRdn().apply( schemaManager );
-
-        if ( !renameContext.getNewDn().isSchemaAware() )
-        {
-            renameContext.getNewDn().apply( schemaManager );
-        }
+        renameContext.getNewDn().apply( schemaManager );
 
         // Push to the next interceptor
         next( renameContext );
@@ -343,10 +299,7 @@ public class NormalizationInterceptor ex
     {
         Dn dn = searchContext.getDn();
 
-        if ( !dn.isSchemaAware() )
-        {
-            dn.apply( schemaManager );
-        }
+        dn.apply( schemaManager );
 
         ExprNode filter = searchContext.getFilter();
 

Modified: directory/apacheds/trunk/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/DupsContainerCursor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/DupsContainerCursor.java?rev=1389184&r1=1389183&r2=1389184&view=diff
==============================================================================
--- directory/apacheds/trunk/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/DupsContainerCursor.java (original)
+++ directory/apacheds/trunk/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/DupsContainerCursor.java Mon Sep 24 02:17:13 2012
@@ -74,7 +74,7 @@ public class DupsContainerCursor<K, V> e
     public DupsContainerCursor( JdbmTable<K, V> table ) throws IOException
     {
         LOG_CURSOR.debug( "Creating DupsContainerCursor {}", this );
-        
+
         if ( !table.isDupsEnabled() )
         {
             throw new IllegalStateException( I18n.err( I18n.ERR_572 ) );

Modified: directory/apacheds/trunk/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmIndex.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmIndex.java?rev=1389184&r1=1389183&r2=1389184&view=diff
==============================================================================
--- directory/apacheds/trunk/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmIndex.java (original)
+++ directory/apacheds/trunk/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmIndex.java Mon Sep 24 02:17:13 2012
@@ -26,16 +26,17 @@ import java.io.IOException;
 import java.net.URI;
 
 import jdbm.RecordManager;
+import jdbm.helper.ByteArraySerializer;
+import jdbm.helper.MRU;
 import jdbm.recman.BaseRecordManager;
-import jdbm.recman.SnapshotRecordManager;
+import jdbm.recman.CacheRecordManager;
 
 import org.apache.directory.server.core.partition.impl.btree.IndexCursorAdaptor;
-import org.apache.directory.server.core.partition.impl.btree.LongComparator;
 import org.apache.directory.server.i18n.I18n;
 import org.apache.directory.server.xdbm.AbstractIndex;
 import org.apache.directory.server.xdbm.EmptyIndexCursor;
 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.model.cursor.Cursor;
 import org.apache.directory.shared.ldap.model.cursor.EmptyCursor;
 import org.apache.directory.shared.ldap.model.cursor.Tuple;
@@ -43,6 +44,7 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.model.schema.MatchingRule;
 import org.apache.directory.shared.ldap.model.schema.SchemaManager;
 import org.apache.directory.shared.ldap.model.schema.comparators.SerializableComparator;
+import org.apache.directory.shared.ldap.model.schema.comparators.UuidComparator;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -52,7 +54,7 @@ import org.slf4j.LoggerFactory;
  *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
-public class JdbmIndex<K, O> extends AbstractIndex<K, O, Long>
+public class JdbmIndex<K, V> extends AbstractIndex<K, V, String>
 {
     /** A logger for this class */
     private static final Logger LOG = LoggerFactory.getLogger( JdbmIndex.class.getSimpleName() );
@@ -73,14 +75,14 @@ public class JdbmIndex<K, O> extends Abs
      * the value of the btree is the entry id of the entry containing an attribute with
      * that value
      */
-    protected JdbmTable<K, Long> forward;
+    protected JdbmTable<K, String> forward;
 
     /**
      * the reverse btree where the btree key is the entry id of the entry containing a
      * value for the indexed attribute, and the btree value is the value of the indexed
      * attribute
      */
-    protected JdbmTable<Long, K> reverse;
+    protected JdbmTable<String, K> reverse;
 
     /**
      * the JDBM record manager for the file containing this index
@@ -118,31 +120,12 @@ public class JdbmIndex<K, O> extends Abs
     // C O N S T R U C T O R S
     // ----------------------------------------------------------------------
     /**
-     * Creates a JdbmIndex instance.
-     */
-    public JdbmIndex()
-    {
-        super( true );
-        initialized = false;
-    }
-
-
-    /**
-     * Creates a JdbmIndex instance for a give AttributeId
-     */
-    public JdbmIndex( String attributeId )
-    {
-        super( attributeId, true );
-        initialized = false;
-    }
-
-
-    /**
      * Creates a JdbmIndex instance for a give AttributeId
      */
     public JdbmIndex( String attributeId, boolean withReverse )
     {
         super( attributeId, withReverse );
+
         initialized = false;
     }
 
@@ -176,8 +159,7 @@ public class JdbmIndex<K, O> extends Abs
         String path = new File( this.wkDirPath, attributeType.getOid() ).getAbsolutePath();
 
         BaseRecordManager base = new BaseRecordManager( path );
-        base.disableTransactions();
-        this.recMan = new SnapshotRecordManager( base, DEFAULT_INDEX_CACHE_SIZE );
+        recMan = new CacheRecordManager( base, new MRU( DEFAULT_INDEX_CACHE_SIZE ) );
 
         try
         {
@@ -225,11 +207,21 @@ public class JdbmIndex<K, O> extends Abs
          * primary keys.  A value for an attribute can occur several times in
          * different entries so the forward map can have more than one value.
          */
-        LongComparator.INSTANCE.setSchemaManager( schemaManager );
+        UuidComparator.INSTANCE.setSchemaManager( schemaManager );
         comp.setSchemaManager( schemaManager );
 
-        forward = new JdbmTable<K, Long>( schemaManager, attributeType.getOid() + FORWARD_BTREE, numDupLimit, recMan,
-            comp, LongComparator.INSTANCE, null, LongSerializer.INSTANCE );
+        if ( mr.getSyntax().isHumanReadable() )
+        {
+            forward = new JdbmTable<K, String>( schemaManager, attributeType.getOid() + FORWARD_BTREE, numDupLimit,
+                recMan,
+                comp, UuidComparator.INSTANCE, StringSerializer.INSTANCE, UuidSerializer.INSTANCE );
+        }
+        else
+        {
+            forward = new JdbmTable<K, String>( schemaManager, attributeType.getOid() + FORWARD_BTREE, numDupLimit,
+                recMan,
+                comp, UuidComparator.INSTANCE, new ByteArraySerializer(), UuidSerializer.INSTANCE );
+        }
 
         /*
          * Now the reverse map stores the primary key into the master table as
@@ -241,14 +233,14 @@ public class JdbmIndex<K, O> extends Abs
         {
             if ( attributeType.isSingleValued() )
             {
-                reverse = new JdbmTable<Long, K>( schemaManager, attributeType.getOid() + REVERSE_BTREE, recMan,
-                    LongComparator.INSTANCE, LongSerializer.INSTANCE, null );
+                reverse = new JdbmTable<String, K>( schemaManager, attributeType.getOid() + REVERSE_BTREE, recMan,
+                    UuidComparator.INSTANCE, UuidSerializer.INSTANCE, null );
             }
             else
             {
-                reverse = new JdbmTable<Long, K>( schemaManager, attributeType.getOid() + REVERSE_BTREE, numDupLimit,
+                reverse = new JdbmTable<String, K>( schemaManager, attributeType.getOid() + REVERSE_BTREE, numDupLimit,
                     recMan,
-                    LongComparator.INSTANCE, comp, LongSerializer.INSTANCE, null );
+                    UuidComparator.INSTANCE, comp, UuidSerializer.INSTANCE, null );
             }
         }
     }
@@ -351,7 +343,7 @@ public class JdbmIndex<K, O> extends Abs
     /**
      * @see Index#forwardLookup(java.lang.Object)
      */
-    public Long forwardLookup( K attrVal ) throws Exception
+    public String forwardLookup( K attrVal ) throws Exception
     {
         return forward.get( attrVal );
     }
@@ -360,7 +352,7 @@ public class JdbmIndex<K, O> extends Abs
     /**
      * {@inheritDoc}
      */
-    public K reverseLookup( Long id ) throws Exception
+    public K reverseLookup( String id ) throws Exception
     {
         if ( withReverse )
         {
@@ -380,7 +372,7 @@ public class JdbmIndex<K, O> extends Abs
     /**
      * {@inheritDoc}
      */
-    public synchronized void add( K attrVal, Long id ) throws Exception
+    public synchronized void add( K attrVal, String id ) throws Exception
     {
         // The pair to be removed must exists
         forward.put( attrVal, id );
@@ -395,7 +387,7 @@ public class JdbmIndex<K, O> extends Abs
     /**
      * {@inheritDoc}
      */
-    public synchronized void drop( K attrVal, Long id ) throws Exception
+    public synchronized void drop( K attrVal, String id ) throws Exception
     {
         // The pair to be removed must exists
         if ( forward.has( attrVal, id ) )
@@ -413,7 +405,7 @@ public class JdbmIndex<K, O> extends Abs
     /**
      * {@inheritDoc}
      */
-    public void drop( Long entryId ) throws Exception
+    public void drop( String entryId ) throws Exception
     {
         if ( withReverse )
         {
@@ -421,7 +413,7 @@ public class JdbmIndex<K, O> extends Abs
             {
                 // Build a cursor to iterate on all the keys referencing
                 // this entryId
-                Cursor<Tuple<Long, K>> values = reverse.cursor( entryId );
+                Cursor<Tuple<String, K>> values = reverse.cursor( entryId );
 
                 while ( values.next() )
                 {
@@ -448,48 +440,48 @@ public class JdbmIndex<K, O> extends Abs
     // Index Cursor Operations
     // ------------------------------------------------------------------------
     @SuppressWarnings("unchecked")
-    public IndexCursor<K, O, Long> reverseCursor() throws Exception
+    public Cursor<IndexEntry<K, String>> reverseCursor() throws Exception
     {
         if ( withReverse )
         {
-            return new IndexCursorAdaptor<K, O, Long>( ( Cursor ) reverse.cursor(), false );
+            return new IndexCursorAdaptor<K>( ( Cursor ) reverse.cursor(), false );
         }
         else
         {
-            return new EmptyIndexCursor<K, O, Long>();
+            return new EmptyIndexCursor<K>();
         }
     }
 
 
     @SuppressWarnings("unchecked")
-    public IndexCursor<K, O, Long> forwardCursor() throws Exception
+    public Cursor<IndexEntry<K, String>> forwardCursor() throws Exception
     {
-        return new IndexCursorAdaptor<K, O, Long>( ( Cursor ) forward.cursor(), true );
+        return new IndexCursorAdaptor<K>( ( Cursor ) forward.cursor(), true );
     }
 
 
     @SuppressWarnings("unchecked")
-    public IndexCursor<K, O, Long> reverseCursor( Long id ) throws Exception
+    public Cursor<IndexEntry<K, String>> reverseCursor( String id ) throws Exception
     {
         if ( withReverse )
         {
-            return new IndexCursorAdaptor<K, O, Long>( ( Cursor ) reverse.cursor( id ), false );
+            return new IndexCursorAdaptor<K>( ( Cursor ) reverse.cursor( id ), false );
         }
         else
         {
-            return new EmptyIndexCursor<K, O, Long>();
+            return new EmptyIndexCursor<K>();
         }
     }
 
 
     @SuppressWarnings("unchecked")
-    public IndexCursor<K, O, Long> forwardCursor( K key ) throws Exception
+    public Cursor<IndexEntry<K, String>> forwardCursor( K key ) throws Exception
     {
-        return new IndexCursorAdaptor<K, O, Long>( ( Cursor ) forward.cursor( key ), true );
+        return new IndexCursorAdaptor<K>( ( Cursor ) forward.cursor( key ), true );
     }
 
 
-    public Cursor<K> reverseValueCursor( Long id ) throws Exception
+    public Cursor<K> reverseValueCursor( String id ) throws Exception
     {
         if ( withReverse )
         {
@@ -502,7 +494,7 @@ public class JdbmIndex<K, O> extends Abs
     }
 
 
-    public Cursor<Long> forwardValueCursor( K key ) throws Exception
+    public Cursor<String> forwardValueCursor( K key ) throws Exception
     {
         return forward.valueCursor( key );
     }
@@ -523,7 +515,7 @@ public class JdbmIndex<K, O> extends Abs
     /**
      * {@inheritDoc}
      */
-    public boolean forward( K attrVal, Long id ) throws Exception
+    public boolean forward( K attrVal, String id ) throws Exception
     {
         return forward.has( attrVal, id );
     }
@@ -532,7 +524,7 @@ public class JdbmIndex<K, O> extends Abs
     /**
      * {@inheritDoc}
      */
-    public boolean reverse( Long id ) throws Exception
+    public boolean reverse( String id ) throws Exception
     {
         if ( withReverse )
         {
@@ -548,7 +540,7 @@ public class JdbmIndex<K, O> extends Abs
     /**
      * {@inheritDoc}
      */
-    public boolean reverse( Long id, K attrVal ) throws Exception
+    public boolean reverse( String id, K attrVal ) throws Exception
     {
         return forward.has( attrVal, id );
     }
@@ -566,7 +558,7 @@ public class JdbmIndex<K, O> extends Abs
     /**
      * {@inheritDoc}
      */
-    public boolean forwardGreaterOrEq( K attrVal, Long id ) throws Exception
+    public boolean forwardGreaterOrEq( K attrVal, String id ) throws Exception
     {
         return forward.hasGreaterOrEqual( attrVal, id );
     }
@@ -584,7 +576,7 @@ public class JdbmIndex<K, O> extends Abs
     /**
      * {@inheritDoc}
      */
-    public boolean forwardLessOrEq( K attrVal, Long id ) throws Exception
+    public boolean forwardLessOrEq( K attrVal, String id ) throws Exception
     {
         return forward.hasLessOrEqual( attrVal, id );
     }
@@ -593,7 +585,7 @@ public class JdbmIndex<K, O> extends Abs
     /**
      * {@inheritDoc}
      */
-    public boolean reverseGreaterOrEq( Long id ) throws Exception
+    public boolean reverseGreaterOrEq( String id ) throws Exception
     {
         if ( withReverse )
         {
@@ -609,7 +601,7 @@ public class JdbmIndex<K, O> extends Abs
     /**
      * {@inheritDoc}
      */
-    public boolean reverseGreaterOrEq( Long id, K attrVal ) throws Exception
+    public boolean reverseGreaterOrEq( String id, K attrVal ) throws Exception
     {
         if ( withReverse )
         {
@@ -625,7 +617,7 @@ public class JdbmIndex<K, O> extends Abs
     /**
      * {@inheritDoc}
      */
-    public boolean reverseLessOrEq( Long id ) throws Exception
+    public boolean reverseLessOrEq( String id ) throws Exception
     {
         if ( withReverse )
         {
@@ -641,7 +633,7 @@ public class JdbmIndex<K, O> extends Abs
     /**
      * {@inheritDoc}
      */
-    public boolean reverseLessOrEq( Long id, K attrVal ) throws Exception
+    public boolean reverseLessOrEq( String id, K attrVal ) throws Exception
     {
         if ( withReverse )
         {

Modified: directory/apacheds/trunk/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmMasterTable.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmMasterTable.java?rev=1389184&r1=1389183&r2=1389184&view=diff
==============================================================================
--- directory/apacheds/trunk/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmMasterTable.java (original)
+++ directory/apacheds/trunk/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmMasterTable.java Mon Sep 24 02:17:13 2012
@@ -20,15 +20,17 @@
 package org.apache.directory.server.core.partition.impl.btree.jdbm;
 
 
+import java.util.UUID;
+
 import jdbm.RecordManager;
-import jdbm.helper.LongSerializer;
 import jdbm.helper.Serializer;
 import jdbm.helper.StringComparator;
 
-import org.apache.directory.server.i18n.I18n;
 import org.apache.directory.server.xdbm.MasterTable;
+import org.apache.directory.shared.ldap.model.entry.Entry;
 import org.apache.directory.shared.ldap.model.schema.SchemaManager;
 import org.apache.directory.shared.ldap.model.schema.comparators.SerializableComparator;
+import org.apache.directory.shared.ldap.model.schema.comparators.UuidComparator;
 
 
 /**
@@ -36,59 +38,10 @@ import org.apache.directory.shared.ldap.
  *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
-public class JdbmMasterTable<E> extends JdbmTable<Long, E> implements MasterTable<Long, E>
+public class JdbmMasterTable extends JdbmTable<String, Entry> implements MasterTable
 {
     private static final StringComparator STRCOMP = new StringComparator();
 
-    private static final SerializableComparator<Long> LONG_COMPARATOR =
-        new SerializableComparator<Long>( "1.3.6.1.4.1.18060.0.4.1.1.2" )
-        {
-            private static final long serialVersionUID = 4048791282048841016L;
-
-
-            public int compare( Long o1, Long o2 )
-            {
-                if ( o1 == null )
-                {
-                    throw new IllegalArgumentException( I18n.err( I18n.ERR_525 ) );
-                }
-                else if ( o2 == null )
-                {
-                    throw new IllegalArgumentException( I18n.err( I18n.ERR_526 ) );
-                }
-
-                if ( o1 == ( long ) o2 )
-                {
-                    return 0;
-                }
-
-                if ( o1 == ( long ) o2 )
-                {
-                    return 0;
-                }
-
-                if ( o1 >= 0 )
-                {
-                    if ( o2 >= 0 )
-                    {
-                        return ( o1 > ( long ) o2 ) ? 1 : -1;
-                    }
-                    else
-                    {
-                        return -1;
-                    }
-                }
-                else if ( o2 >= 0 )
-                {
-                    return 1;
-                }
-                else
-                {
-                    return ( o1 < ( long ) o2 ) ? -1 : 1;
-                }
-            }
-        };
-
     private static final SerializableComparator<String> STRING_COMPARATOR =
         new SerializableComparator<String>( "1.3.6.1.4.1.18060.0.4.1.1.3" )
         {
@@ -108,14 +61,15 @@ public class JdbmMasterTable<E> extends 
      * Creates the master table using JDBM B+Trees for the backing store.
      *
      * @param recMan the JDBM record manager
-     * @param schemaManager the schema mamanger
+     * @param schemaManager the schema manager
      * @throws Exception if there is an error opening the Db file.
      */
     public JdbmMasterTable( RecordManager recMan, SchemaManager schemaManager ) throws Exception
     {
-        super( schemaManager, DBF, recMan, LONG_COMPARATOR, LongSerializer.INSTANCE,
+        super( schemaManager, DBF, recMan, UuidComparator.INSTANCE, UuidSerializer.INSTANCE,
             new EntrySerializer( schemaManager ) );
-        adminTbl = new JdbmTable<String, String>( schemaManager, "admin", recMan, STRING_COMPARATOR, null, null );
+        adminTbl = new JdbmTable<String, String>( schemaManager, "admin", recMan, STRING_COMPARATOR,
+            StringSerializer.INSTANCE, StringSerializer.INSTANCE );
         String seqValue = adminTbl.get( SEQPROP_KEY );
 
         if ( null == seqValue )
@@ -123,7 +77,7 @@ public class JdbmMasterTable<E> extends 
             adminTbl.put( SEQPROP_KEY, "0" );
         }
 
-        LONG_COMPARATOR.setSchemaManager( schemaManager );
+        UuidComparator.INSTANCE.setSchemaManager( schemaManager );
         STRING_COMPARATOR.setSchemaManager( schemaManager );
     }
 
@@ -131,8 +85,9 @@ public class JdbmMasterTable<E> extends 
     protected JdbmMasterTable( RecordManager recMan, SchemaManager schemaManager, String dbName, Serializer serializer )
         throws Exception
     {
-        super( schemaManager, DBF, recMan, LONG_COMPARATOR, LongSerializer.INSTANCE, serializer );
-        adminTbl = new JdbmTable<String, String>( schemaManager, dbName, recMan, STRING_COMPARATOR, null, null );
+        super( schemaManager, DBF, recMan, UuidComparator.INSTANCE, UuidSerializer.INSTANCE, serializer );
+        adminTbl = new JdbmTable<String, String>( schemaManager, dbName, recMan, STRING_COMPARATOR,
+            StringSerializer.INSTANCE, StringSerializer.INSTANCE );
         String seqValue = adminTbl.get( SEQPROP_KEY );
 
         if ( null == seqValue )
@@ -152,19 +107,9 @@ public class JdbmMasterTable<E> extends 
      * @throws Exception if the admin table storing sequences cannot be
      *                         read and written to.
      */
-    public Long getNextId( E entry ) throws Exception
+    public String getNextId( Entry entry ) throws Exception
     {
-        Long nextVal;
-        Long lastVal;
-
-        synchronized ( adminTbl )
-        {
-            lastVal = new Long( adminTbl.get( SEQPROP_KEY ) );
-            nextVal = lastVal + 1L;
-            adminTbl.put( SEQPROP_KEY, nextVal.toString() );
-        }
-
-        return nextVal;
+        return UUID.randomUUID().toString();
     }
 
 

Modified: directory/apacheds/trunk/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmPartition.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmPartition.java?rev=1389184&r1=1389183&r2=1389184&view=diff
==============================================================================
--- directory/apacheds/trunk/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmPartition.java (original)
+++ directory/apacheds/trunk/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmPartition.java Mon Sep 24 02:17:13 2012
@@ -29,8 +29,9 @@ import java.util.Arrays;
 import java.util.List;
 
 import jdbm.RecordManager;
+import jdbm.helper.MRU;
 import jdbm.recman.BaseRecordManager;
-import jdbm.recman.SnapshotRecordManager;
+import jdbm.recman.CacheRecordManager;
 
 import org.apache.directory.server.constants.ApacheSchemaConstants;
 import org.apache.directory.server.core.api.partition.Partition;
@@ -60,7 +61,7 @@ import org.slf4j.LoggerFactory;
  *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
-public class JdbmPartition extends AbstractBTreePartition<Long>
+public class JdbmPartition extends AbstractBTreePartition
 {
     /** static logger */
     private static final Logger LOG = LoggerFactory.getLogger( JdbmPartition.class );
@@ -112,13 +113,13 @@ public class JdbmPartition extends Abstr
             }
             else
             {
-                optimizer = new DefaultOptimizer<Entry, Long>( this );
+                optimizer = new DefaultOptimizer<Entry>( this );
             }
 
-            EvaluatorBuilder<Long> evaluatorBuilder = new EvaluatorBuilder<Long>( this, schemaManager );
-            CursorBuilder<Long> cursorBuilder = new CursorBuilder<Long>( this, evaluatorBuilder );
+            EvaluatorBuilder evaluatorBuilder = new EvaluatorBuilder( this, schemaManager );
+            CursorBuilder cursorBuilder = new CursorBuilder( this, evaluatorBuilder );
 
-            searchEngine = new DefaultSearchEngine<Long>( this, cursorBuilder, evaluatorBuilder, optimizer );
+            searchEngine = new DefaultSearchEngine( this, cursorBuilder, evaluatorBuilder, optimizer );
 
             // Create the underlying directories (only if needed)
             File partitionDir = new File( getPartitionPath() );
@@ -132,8 +133,9 @@ public class JdbmPartition extends Abstr
 
             // First, check if the file storing the data exists
             String path = partitionDir.getPath() + File.separator + "master";
-            BaseRecordManager baseRecordManager = new BaseRecordManager( path );
-            baseRecordManager.disableTransactions();
+
+            BaseRecordManager base = new BaseRecordManager( path );
+            base.disableTransactions();
 
             if ( cacheSize < 0 )
             {
@@ -145,11 +147,10 @@ public class JdbmPartition extends Abstr
                 LOG.debug( "Using the custom configured cache size of {} for {} partition", cacheSize, id );
             }
 
-            // Now, create the entry cache for this partition
-            recMan = new SnapshotRecordManager( baseRecordManager, cacheSize );
+            recMan = new CacheRecordManager( base, new MRU( cacheSize ) );
 
             // Create the master table (the table containing all the entries)
-            master = new JdbmMasterTable<Entry>( recMan, schemaManager );
+            master = new JdbmMasterTable( recMan, schemaManager );
 
             // get all index db files first
             File[] allIndexDbFiles = partitionDir.listFiles( DB_FILTER );
@@ -160,22 +161,22 @@ public class JdbmPartition extends Abstr
             // then add all index objects to a list
             List<String> allIndices = new ArrayList<String>();
 
-            for ( Index<?, Entry, Long> index : systemIndices.values() )
+            for ( Index<?, Entry, String> index : systemIndices.values() )
             {
                 allIndices.add( index.getAttribute().getOid() );
             }
-            
-            List<Index<?, Entry, Long>> indexToBuild = new ArrayList<Index<?, Entry, Long>>();
+
+            List<Index<?, Entry, String>> indexToBuild = new ArrayList<Index<?, Entry, String>>();
 
             // this loop is used for two purposes
             // one for collecting all user indices
             // two for finding a new index to be built
             // just to avoid another iteration for determining which is the new index
-            for ( Index<?, Entry, Long> index : userIndices.values() )
+            for ( Index<?, Entry, String> index : userIndices.values() )
             {
                 String indexOid = index.getAttribute().getOid();
                 allIndices.add( indexOid );
-                
+
                 // take the part after removing .db from the
                 String name = indexOid + JDBM_DB_FILE_EXTN;
 
@@ -186,11 +187,6 @@ public class JdbmPartition extends Abstr
                     indexToBuild.add( index );
                 }
             }
-            
-            if ( indexToBuild.size() > 0 )
-            {
-                buildUserIndex( indexToBuild );
-            }
 
             if ( indexToBuild.size() > 0 )
             {
@@ -208,18 +204,18 @@ public class JdbmPartition extends Abstr
     /**
      * {@inheritDoc}}
      */
-    public Long getDefaultId()
+    public String getDefaultId()
     {
-        return 1L;
+        return Partition.DEFAULT_ID;
     }
 
 
     /**
      * {@inheritDoc}
      */
-    public Long getRootId()
+    public String getRootId()
     {
-        return 0L;
+        return Partition.ROOT_ID;
     }
 
 
@@ -237,18 +233,18 @@ public class JdbmPartition extends Abstr
         }
 
         // Sync all system indices
-        for ( Index<?, Entry, Long> idx : systemIndices.values() )
+        for ( Index<?, Entry, String> idx : systemIndices.values() )
         {
             idx.sync();
         }
 
         // Sync all user defined userIndices
-        for ( Index<?, Entry, Long> idx : userIndices.values() )
+        for ( Index<?, Entry, String> idx : userIndices.values() )
         {
             idx.sync();
         }
 
-        ( ( JdbmMasterTable<Entry> ) master ).sync();
+        ( ( JdbmMasterTable ) master ).sync();
         recMan.commit();
     }
 
@@ -259,9 +255,9 @@ public class JdbmPartition extends Abstr
      * @param userIndexes then user defined indexes to create
      * @throws Exception in case of any problems while building the index
      */
-    private void buildUserIndex( List<Index<?, Entry, Long>> userIndexes ) throws Exception
+    private void buildUserIndex( List<Index<?, Entry, String>> userIndexes ) throws Exception
     {
-        Cursor<Tuple<Long, Entry>> cursor = master.cursor();
+        Cursor<Tuple<String, Entry>> cursor = master.cursor();
         cursor.beforeFirst();
 
         while ( cursor.next() )
@@ -269,25 +265,25 @@ public class JdbmPartition extends Abstr
             for ( Index index : userIndexes )
             {
                 AttributeType atType = index.getAttribute();
-  
+
                 String attributeOid = index.getAttribute().getOid();
-  
+
                 LOG.info( "building the index for attribute type {}", atType );
-          
-                Tuple<Long, Entry> tuple = cursor.get();
 
-                Long id = tuple.getKey();
+                Tuple<String, Entry> tuple = cursor.get();
+
+                String id = tuple.getKey();
                 Entry entry = tuple.getValue();
-    
+
                 Attribute entryAttr = entry.get( atType );
-    
+
                 if ( entryAttr != null )
                 {
                     for ( Value<?> value : entryAttr )
                     {
                         index.add( value.getValue(), id );
                     }
-    
+
                     // Adds only those attributes that are indexed
                     presenceIdx.add( attributeOid, id );
                 }
@@ -349,17 +345,13 @@ public class JdbmPartition extends Abstr
     /**
      * {@inheritDoc}
      */
-    protected Index<?, Entry, Long> convertAndInit( Index<?, Entry, Long> index ) throws Exception
+    protected Index<?, Entry, String> convertAndInit( Index<?, Entry, String> index ) throws Exception
     {
         JdbmIndex<?, Entry> jdbmIndex;
 
-        if ( index.getAttributeId().equals( ApacheSchemaConstants.APACHE_RDN_AT_OID ) )
+        if ( index instanceof JdbmRdnIndex )
         {
-            jdbmIndex = new JdbmRdnIndex();
-            jdbmIndex.setAttributeId( ApacheSchemaConstants.APACHE_RDN_AT_OID );
-            jdbmIndex.setCacheSize( index.getCacheSize() );
-            jdbmIndex.setNumDupLimit( JdbmIndex.DEFAULT_DUPLICATE_LIMIT );
-            jdbmIndex.setWkDirPath( index.getWkDirPath() );
+            jdbmIndex = ( JdbmRdnIndex ) index;
         }
         else if ( index instanceof JdbmIndex<?, ?> )
         {
@@ -429,10 +421,10 @@ public class JdbmPartition extends Abstr
     /**
      * {@inheritDoc}
      */
-    protected final Index createSystemIndex( String oid, URI path, boolean withReverse )  throws Exception
+    protected final Index createSystemIndex( String oid, URI path, boolean withReverse ) throws Exception
     {
         LOG.debug( "Supplied index {} is not a JdbmIndex.  " +
-         "Will create new JdbmIndex using copied configuration parameters." );
+            "Will create new JdbmIndex using copied configuration parameters." );
         JdbmIndex<?, Entry> jdbmIndex;
 
         if ( oid.equals( ApacheSchemaConstants.APACHE_RDN_AT_OID ) )

Modified: directory/apacheds/trunk/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmRdnIndex.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmRdnIndex.java?rev=1389184&r1=1389183&r2=1389184&view=diff
==============================================================================
--- directory/apacheds/trunk/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmRdnIndex.java (original)
+++ directory/apacheds/trunk/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmRdnIndex.java Mon Sep 24 02:17:13 2012
@@ -27,16 +27,19 @@ import java.io.IOException;
 
 import javax.naming.NamingException;
 
+import jdbm.helper.MRU;
 import jdbm.recman.BaseRecordManager;
-import jdbm.recman.SnapshotRecordManager;
+import jdbm.recman.CacheRecordManager;
 
-import org.apache.directory.server.core.partition.impl.btree.LongComparator;
+import org.apache.directory.server.constants.ApacheSchemaConstants;
 import org.apache.directory.server.i18n.I18n;
 import org.apache.directory.server.xdbm.ParentIdAndRdn;
 import org.apache.directory.server.xdbm.ParentIdAndRdnComparator;
+import org.apache.directory.shared.ldap.model.entry.Entry;
 import org.apache.directory.shared.ldap.model.schema.AttributeType;
 import org.apache.directory.shared.ldap.model.schema.MatchingRule;
 import org.apache.directory.shared.ldap.model.schema.SchemaManager;
+import org.apache.directory.shared.ldap.model.schema.comparators.UuidComparator;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -46,7 +49,7 @@ import org.slf4j.LoggerFactory;
  * 
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
-public class JdbmRdnIndex<E> extends JdbmIndex<ParentIdAndRdn<Long>, E>
+public class JdbmRdnIndex extends JdbmIndex<ParentIdAndRdn, Entry>
 {
 
     /** A logger for this class */
@@ -55,18 +58,11 @@ public class JdbmRdnIndex<E> extends Jdb
 
     public JdbmRdnIndex()
     {
-        super();
+        super( ApacheSchemaConstants.APACHE_RDN_AT_OID, true );
         initialized = false;
     }
 
 
-    public JdbmRdnIndex( String attributeId )
-    {
-        initialized = false;
-        setAttributeId( attributeId );
-    }
-
-
     public void init( SchemaManager schemaManager, AttributeType attributeType ) throws IOException
     {
         LOG.debug( "Initializing an Index for attribute '{}'", attributeType.getName() );
@@ -88,10 +84,10 @@ public class JdbmRdnIndex<E> extends Jdb
 
         String path = new File( this.wkDirPath, attributeType.getOid() ).getAbsolutePath();
 
-        //System.out.println( "IDX Created index " + path );
+        //System.out.println( "IDX Created index " + path )
         BaseRecordManager base = new BaseRecordManager( path );
         base.disableTransactions();
-        this.recMan = new SnapshotRecordManager( base, cacheSize );
+        recMan = new CacheRecordManager( base, new MRU( cacheSize ) );
 
         try
         {
@@ -132,13 +128,15 @@ public class JdbmRdnIndex<E> extends Jdb
             throw new IOException( I18n.err( I18n.ERR_574, attributeType.getName() ) );
         }
 
-        ParentIdAndRdnComparator<Long> comp = new ParentIdAndRdnComparator<Long>( mr.getOid() );
+        ParentIdAndRdnComparator<String> comp = new ParentIdAndRdnComparator<String>( mr.getOid() );
+
+        UuidComparator.INSTANCE.setSchemaManager( schemaManager );
 
-        LongComparator.INSTANCE.setSchemaManager( schemaManager );
+        ParentIdAndRdnSerializer parentIdAndSerializer = new ParentIdAndRdnSerializer( schemaManager );
 
-        forward = new JdbmTable<ParentIdAndRdn<Long>, Long>( schemaManager, attributeType.getOid() + FORWARD_BTREE,
-            recMan, comp, null, LongSerializer.INSTANCE );
-        reverse = new JdbmTable<Long, ParentIdAndRdn<Long>>( schemaManager, attributeType.getOid() + REVERSE_BTREE,
-            recMan, LongComparator.INSTANCE, LongSerializer.INSTANCE, null );
+        forward = new JdbmTable<ParentIdAndRdn, String>( schemaManager, attributeType.getOid() + FORWARD_BTREE,
+            recMan, comp, parentIdAndSerializer, UuidSerializer.INSTANCE );
+        reverse = new JdbmTable<String, ParentIdAndRdn>( schemaManager, attributeType.getOid() + REVERSE_BTREE,
+            recMan, UuidComparator.INSTANCE, UuidSerializer.INSTANCE, parentIdAndSerializer );
     }
 }

Modified: directory/apacheds/trunk/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTable.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTable.java?rev=1389184&r1=1389183&r2=1389184&view=diff
==============================================================================
--- directory/apacheds/trunk/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTable.java (original)
+++ directory/apacheds/trunk/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTable.java Mon Sep 24 02:17:13 2012
@@ -36,6 +36,7 @@ import org.apache.directory.server.core.
 import org.apache.directory.server.core.avltree.Marshaller;
 import org.apache.directory.server.i18n.I18n;
 import org.apache.directory.server.xdbm.AbstractTable;
+import org.apache.directory.server.xdbm.KeyTupleArrayCursor;
 import org.apache.directory.server.xdbm.Table;
 import org.apache.directory.shared.ldap.model.cursor.Cursor;
 import org.apache.directory.shared.ldap.model.cursor.EmptyCursor;
@@ -308,11 +309,11 @@ public class JdbmTable<K, V> extends Abs
 
         if ( !allowsDuplicates )
         {
-            return ( V ) bt.find( key );
+            return bt.find( key );
         }
 
         DupsContainer<V> values = getDupsContainer( ( byte[] ) bt.find( key ) );
-        
+
         if ( values.isArrayTree() )
         {
             ArrayTree<V> set = values.getArrayTree();
@@ -439,7 +440,7 @@ public class JdbmTable<K, V> extends Abs
         Tuple<K, V> tuple = bt.findGreaterOrEqual( key );
 
         // Test for equality first since it satisfies equal to condition
-        if ( null != tuple && keyComparator.compare( ( K ) tuple.getKey(), key ) == 0 )
+        if ( null != tuple && keyComparator.compare( tuple.getKey(), key ) == 0 )
         {
             return true;
         }
@@ -492,7 +493,7 @@ public class JdbmTable<K, V> extends Abs
 
         if ( !allowsDuplicates )
         {
-            V stored = ( V ) bt.find( key );
+            V stored = bt.find( key );
             return null != stored && stored.equals( value );
         }
 
@@ -638,7 +639,7 @@ public class JdbmTable<K, V> extends Abs
 
             if ( !allowsDuplicates )
             {
-                V oldValue = ( V ) bt.find( key );
+                V oldValue = bt.find( key );
 
                 // Remove the value only if it is the same as value.
                 if ( ( oldValue != null ) && oldValue.equals( value ) )
@@ -833,7 +834,7 @@ public class JdbmTable<K, V> extends Abs
         if ( !allowsDuplicates )
         {
             return new SingletonCursor<org.apache.directory.shared.ldap.model.cursor.Tuple<K, V>>(
-                new org.apache.directory.shared.ldap.model.cursor.Tuple<K, V>( key, ( V ) raw ) );
+                new org.apache.directory.shared.ldap.model.cursor.Tuple<K, V>( key, raw ) );
         }
 
         byte[] serialized = ( byte[] ) raw;
@@ -867,7 +868,7 @@ public class JdbmTable<K, V> extends Abs
 
         if ( !allowsDuplicates )
         {
-            return new SingletonCursor<V>( ( V ) raw );
+            return new SingletonCursor<V>( raw );
         }
 
         byte[] serialized = ( byte[] ) raw;
@@ -1070,7 +1071,7 @@ public class JdbmTable<K, V> extends Abs
         {
             bTree.insert( keys.get(), ( K ) StringConstants.EMPTY_BYTES, true );
         }
-        
+
         keys.close();
 
         return bTree;

Modified: directory/apacheds/trunk/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/NoDupsCursor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/NoDupsCursor.java?rev=1389184&r1=1389183&r2=1389184&view=diff
==============================================================================
--- directory/apacheds/trunk/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/NoDupsCursor.java (original)
+++ directory/apacheds/trunk/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/NoDupsCursor.java Mon Sep 24 02:17:13 2012
@@ -217,7 +217,7 @@ class NoDupsCursor<K, V> extends Abstrac
     public boolean next() throws Exception
     {
         checkNotClosed( "previous()" );
-        
+
         if ( browser == null )
         {
             beforeFirst();

Added: directory/apacheds/trunk/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/ParentIdAndRdnSerializer.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/ParentIdAndRdnSerializer.java?rev=1389184&view=auto
==============================================================================
--- directory/apacheds/trunk/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/ParentIdAndRdnSerializer.java (added)
+++ directory/apacheds/trunk/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/ParentIdAndRdnSerializer.java Mon Sep 24 02:17:13 2012
@@ -0,0 +1,183 @@
+/*
+ *  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.impl.btree.jdbm;
+
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutput;
+import java.io.ObjectOutputStream;
+
+import jdbm.helper.Serializer;
+
+import org.apache.directory.server.i18n.I18n;
+import org.apache.directory.server.xdbm.ParentIdAndRdn;
+import org.apache.directory.shared.ldap.model.name.Rdn;
+import org.apache.directory.shared.ldap.model.schema.SchemaManager;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * Serialize and deserialize a ParentidAndRdn.
+ * </br></br>
+ * <b>This class must *not* be used outside of the server.</b>
+ *  
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class ParentIdAndRdnSerializer implements Serializer
+{
+    /** The serialVersionUID */
+    private static final long serialVersionUID = 1L;
+
+    /** the logger for this class */
+    private static final Logger LOG = LoggerFactory.getLogger( ParentIdAndRdnSerializer.class );
+
+    /**
+     * Speedup for logs
+     */
+    private static final boolean IS_DEBUG = LOG.isDebugEnabled();
+
+    /** The schemaManager reference */
+    private transient SchemaManager schemaManager;
+
+
+    /**
+     * Creates a new instance of ParentIdAndRdnSerializer.
+     * 
+     * @param schemaManager The reference to the global schemaManager
+     */
+    public ParentIdAndRdnSerializer( SchemaManager schemaManager )
+    {
+        this.schemaManager = schemaManager;
+    }
+
+
+    /**
+     * <p>
+     * 
+     * This is the place where we serialize ParentIdAndRdn
+     * <p>
+     */
+    public byte[] serialize( Object object ) throws IOException
+    {
+        ParentIdAndRdn parentIdAndRdn = ( ParentIdAndRdn ) object;
+
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        ObjectOutput out = new ObjectOutputStream( baos );
+
+        // First, the Dn
+        Rdn[] rdns = parentIdAndRdn.getRdns();
+
+        // Write the Rdn of the Dn
+        if ( ( rdns == null ) || ( rdns.length == 0 ) )
+        {
+            out.writeByte( 0 );
+        }
+        else
+        {
+            out.writeByte( rdns.length );
+
+            for ( Rdn rdn : rdns )
+            {
+                rdn.writeExternal( out );
+            }
+        }
+
+        // Then the parentId.
+        out.writeUTF( parentIdAndRdn.getParentId() );
+
+        // The number of children
+        out.writeInt( parentIdAndRdn.getNbChildren() );
+
+        // The number of descendants
+        out.writeInt( parentIdAndRdn.getNbDescendants() );
+
+        out.flush();
+
+        if ( IS_DEBUG )
+        {
+            LOG.debug( ">------------------------------------------------" );
+            LOG.debug( "Serialize " + parentIdAndRdn );
+        }
+
+        return baos.toByteArray();
+    }
+
+
+    /**
+     *  Deserialize a ParentIdAndRdn.
+     *  
+     *  @param bytes the byte array containing the serialized ParentIdAndRdn
+     *  @return An instance of a ParentIdAndRdn object 
+     *  @throws IOException if we can't deserialize the ParentIdAndRdn
+     */
+    public Object deserialize( byte[] bytes ) throws IOException
+    {
+        ObjectInputStream in = new ObjectInputStream( new ByteArrayInputStream( bytes ) );
+
+        try
+        {
+            ParentIdAndRdn parentIdAndRdn = new ParentIdAndRdn();
+
+            // Read the number of rdns, if any
+            byte nbRdns = in.readByte();
+
+            if ( nbRdns == 0 )
+            {
+                parentIdAndRdn.setRdns( new Rdn[0] );
+            }
+            else
+            {
+                Rdn[] rdns = new Rdn[nbRdns];
+
+                for ( int i = 0; i < nbRdns; i++ )
+                {
+                    Rdn rdn = new Rdn( schemaManager );
+                    rdn.readExternal( in );
+                    rdns[i] = rdn;
+                }
+
+                parentIdAndRdn.setRdns( rdns );
+            }
+
+            // Read the parent ID
+            String uuid = in.readUTF();
+
+            parentIdAndRdn.setParentId( uuid );
+
+            // Read the nulber of children and descendants
+            int nbChildren = in.readInt();
+            int nbDescendants = in.readInt();
+
+            parentIdAndRdn.setNbChildren( nbChildren );
+            parentIdAndRdn.setNbDescendants( nbDescendants );
+
+            return parentIdAndRdn;
+        }
+        catch ( ClassNotFoundException cnfe )
+        {
+            LOG.error( I18n.err( I18n.ERR_134, cnfe.getLocalizedMessage() ) );
+            throw new IOException( cnfe.getLocalizedMessage() );
+        }
+    }
+}

Modified: directory/apacheds/trunk/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/StringSerializer.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/StringSerializer.java?rev=1389184&r1=1389183&r2=1389184&view=diff
==============================================================================
--- directory/apacheds/trunk/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/StringSerializer.java (original)
+++ directory/apacheds/trunk/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/StringSerializer.java Mon Sep 24 02:17:13 2012
@@ -24,6 +24,8 @@ import java.io.IOException;
 
 import jdbm.helper.Serializer;
 
+import org.apache.directory.shared.util.Strings;
+
 
 /**
  * A custom String serializer to [de]serialize Strings.
@@ -34,29 +36,39 @@ public class StringSerializer implements
 {
     private static final long serialVersionUID = -173163945773783649L;
 
+    /** A static instance of a StringSerializer */
+    public static StringSerializer INSTANCE = new StringSerializer();
+
+
+    /**
+     * Default private constructor
+     */
+    private StringSerializer()
+    {
+    }
+
 
     /* (non-Javadoc)
      * @see jdbm.helper.Serializer#deserialize(byte[])
      */
-    public Object deserialize( byte[] bites ) throws IOException
+    public Object deserialize( byte[] bytes ) throws IOException
     {
-        if ( bites.length == 0 )
+        if ( bytes.length == 0 )
         {
             return "";
         }
 
-        char[] strchars = new char[bites.length >> 1];
-        for ( int ii = 0, jj = 0; ii < strchars.length; ii++, jj = ii << 1 )
+        char[] strchars = new char[bytes.length >> 1];
+        int pos = 0;
+
+        for ( int i = 0; i < bytes.length; i += 2 )
         {
-            int ch = bites[jj] << 8 & 0x0000FF00;
-            ch |= bites[jj + 1] & 0x000000FF;
-            strchars[ii] = ( char ) ch;
+            strchars[pos++] = ( char ) ( ( ( bytes[i] << 8 ) & 0x0000FF00 ) | ( bytes[i + 1] & 0x000000FF ) );
         }
+
         return new String( strchars );
     }
 
-    private static final byte[] EMPTY_BYTE_ARRAY = new byte[0];
-
 
     /* (non-Javadoc)
      * @see jdbm.helper.Serializer#serialize(java.lang.Object)
@@ -65,15 +77,17 @@ public class StringSerializer implements
     {
         if ( ( ( String ) str ).length() == 0 )
         {
-            return EMPTY_BYTE_ARRAY;
+            return Strings.EMPTY_BYTES;
         }
 
         char[] strchars = ( ( String ) str ).toCharArray();
         byte[] bites = new byte[strchars.length << 1];
-        for ( int ii = 0, jj = 0; ii < strchars.length; ii++, jj = ii << 1 )
+        int pos = 0;
+
+        for ( char c : strchars )
         {
-            bites[jj] = ( byte ) ( strchars[ii] >> 8 & 0x00FF );
-            bites[jj + 1] = ( byte ) ( strchars[ii] & 0x00FF );
+            bites[pos++] = ( byte ) ( c >> 8 & 0x00FF );
+            bites[pos++] = ( byte ) ( c & 0x00FF );
         }
 
         return bites;

Added: directory/apacheds/trunk/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/UuidSerializer.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/UuidSerializer.java?rev=1389184&view=auto
==============================================================================
--- directory/apacheds/trunk/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/UuidSerializer.java (added)
+++ directory/apacheds/trunk/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/UuidSerializer.java Mon Sep 24 02:17:13 2012
@@ -0,0 +1,57 @@
+/*
+ *  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.impl.btree.jdbm;
+
+
+import java.io.IOException;
+
+import jdbm.helper.Serializer;
+
+
+/**
+ * A {@link Serializer} for UUIDs
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class UuidSerializer implements Serializer
+{
+    private static final long serialVersionUID = 237756689544852128L;
+    public static final UuidSerializer INSTANCE = new UuidSerializer();
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public byte[] serialize( Object o ) throws IOException
+    {
+        String uuid = ( String ) o;
+
+        return StringSerializer.INSTANCE.serialize( uuid );
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public Object deserialize( byte[] bytes ) throws IOException
+    {
+        return StringSerializer.INSTANCE.deserialize( bytes );
+    }
+}



Mime
View raw message