directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1332268 [2/5] - in /directory/apacheds/trunk: ./ all/ core-annotations/ core-annotations/src/main/java/org/apache/directory/server/core/factory/ core-api/ core-api/src/main/java/org/apache/directory/server/core/api/changelog/ core-api/src/...
Date Mon, 30 Apr 2012 15:59:27 GMT
Added: directory/apacheds/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/operations/search/SearchWithIndexTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/operations/search/SearchWithIndexTest.java?rev=1332268&view=auto
==============================================================================
--- directory/apacheds/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/operations/search/SearchWithIndexTest.java (added)
+++ directory/apacheds/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/operations/search/SearchWithIndexTest.java Mon Apr 30 15:59:22 2012
@@ -0,0 +1,218 @@
+package org.apache.directory.shared.client.api.operations.search;
+
+import org.apache.directory.ldap.client.api.LdapNetworkConnection;
+import org.apache.directory.server.annotations.CreateLdapServer;
+import org.apache.directory.server.annotations.CreateTransport;
+import org.apache.directory.server.core.annotations.ContextEntry;
+import org.apache.directory.server.core.annotations.CreateDS;
+import org.apache.directory.server.core.annotations.CreateIndex;
+import org.apache.directory.server.core.annotations.CreatePartition;
+import org.apache.directory.server.core.integ.AbstractLdapTestUnit;
+import org.apache.directory.server.core.integ.FrameworkRunner;
+import org.apache.directory.shared.client.api.LdapApiIntegrationUtils;
+import org.apache.directory.shared.ldap.model.cursor.EntryCursor;
+import org.apache.directory.shared.ldap.model.entry.DefaultEntry;
+import org.apache.directory.shared.ldap.model.entry.Entry;
+import org.apache.directory.shared.ldap.model.message.SearchScope;
+import org.apache.directory.shared.ldap.model.name.Dn;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+@RunWith(FrameworkRunner.class)
+@CreateDS(
+    name="AddPerfDS",
+    partitions =
+    {
+        @CreatePartition(
+            name = "example",
+            suffix = "dc=example,dc=com",
+            contextEntry = @ContextEntry(
+                entryLdif =
+                    "dn: dc=example,dc=com\n" +
+                    "dc: example\n" +
+                    "objectClass: top\n" +
+                    "objectClass: domain\n\n" ),
+            indexes =
+            {
+                @CreateIndex( attribute = "objectClass" ),
+                @CreateIndex( attribute = "sn" ),
+                @CreateIndex( attribute = "cn" ),
+                @CreateIndex( attribute = "displayName" )
+            } )
+            
+    },
+    enableChangeLog = false )
+@CreateLdapServer(transports =
+    {
+        @CreateTransport(protocol = "LDAP"),
+        @CreateTransport(protocol = "LDAPS")
+    })
+public class SearchWithIndexTest extends AbstractLdapTestUnit
+{
+    private LdapNetworkConnection connection;
+    
+    
+    @Before
+    public void setup() throws Exception
+    {
+        connection = (LdapNetworkConnection)LdapApiIntegrationUtils.getPooledAdminConnection( getLdapServer() );
+
+        // Restart the service so that the index is created
+        getService().shutdown();
+        getService().startup();
+    }
+    
+    
+    @After
+    public void shutdown() throws Exception
+    {
+        LdapApiIntegrationUtils.releasePooledAdminConnection( connection, getLdapServer() );
+    }
+
+    /**
+     * Test an add operation performance
+     */
+    @Test
+    @Ignore
+    public void testAddPer2f() throws Exception
+    {
+        Dn dn = new Dn( "cn=test,ou=system" );
+        Entry entry = new DefaultEntry( getService().getSchemaManager(), dn,
+            "ObjectClass: top",
+            "ObjectClass: person",
+            "sn: TEST",
+            "cn: test" );
+    
+        connection.add( entry );
+        int nbIterations = 8000;
+
+        //BufferedWriter out = new BufferedWriter( new FileWriter("/tmp/out.txt") );
+
+        long t0 = System.currentTimeMillis();
+        long t00 = 0L;
+        long tt0 = System.currentTimeMillis();
+        
+        for ( int i = 0; i < nbIterations; i++ )
+        {
+            if ( i % 1000 == 0 )
+            {
+                long tt1 = System.currentTimeMillis();
+    
+                System.out.println( i + ", " + ( tt1 - tt0 ) );
+                tt0 = tt1;
+            }
+    
+            if ( i == 5000 )
+            {
+                t00 = System.currentTimeMillis();
+            }
+    
+            dn = new Dn( "uid=" + i + ",dc=example,dc=com" );
+            entry = new DefaultEntry( getService().getSchemaManager(), dn,
+                "objectClass: top",
+                "objectClass: person",
+                "objectClass: organizationalPerson",
+                "objectClass: inetOrgPerson",
+                "uid", Integer.toString( i ),
+                "mail: A-A-R.Awg-Rosli@acme.com",
+                "title: Snr Operations Technician (D)",
+                "sn: Awg-Rosli",
+                "departmentNumber: SMDS - UIA/G/MMO52D",
+                "cn: Awg-Rosli, Awg-Abd-Rahim SMDS-UIA/G/MMO52D",
+                "description: UI - S",
+                "telephoneNumber: 555-1212",
+                "givenName: Awg-Abd-Rahim",
+                "businessCategory: Ops MDS (Malaysia) Sdn Bhd",
+                "displayName", i + "Awg-Rosli, Awg-Abd-Rahim SMDS-UIA/G/MMO52D",
+                "employeeNumber: A-A-R.Awg-Rosli",
+                "pwdPolicySubEntry: ads-pwdId=cproint,ou=passwordPolicies,ads-interceptorId=authenticationInterceptor,ou=interceptors,ads-directoryServiceId=default,ou=config" );
+    
+            //out.write( LdifUtils.convertToLdif( entry ) );
+            connection.add( entry );
+        }
+        
+        //out.flush();
+        //out.close();
+    
+        long t1 = System.currentTimeMillis();
+    
+        Long deltaWarmed = ( t1 - t00 );
+        System.out.println( "Delta : " + deltaWarmed + "( " + ( ( ( nbIterations - 5000 ) * 1000 ) / deltaWarmed ) + " per s ) /" + ( t1 - t0 ) );
+
+        Entry entry1 = null;
+        Entry entry2 = null;
+        Entry entry3 = null;
+        
+        long ns0 = System.currentTimeMillis();
+        EntryCursor results = connection.search("dc=example,dc=com", "(displayName=1234Awg-Rosli, Awg-Abd-Rahim SMDS-UIA/G/MMO52D)", SearchScope.SUBTREE, "*" );
+        
+        while ( results.next() )
+        {
+            entry1 = results.get();
+            break;
+        }
+        
+        results.close();
+        
+        long ns1 = System.currentTimeMillis();
+        
+        System.out.println( "Delta search : " + ( ns1 - ns0 ) );
+
+        long ns2 = System.currentTimeMillis();
+        results = connection.search("dc=example,dc=com", "(displayName=3456*)", SearchScope.SUBTREE, "*" );
+                
+        while ( results.next() )
+        {
+            entry2 = results.get();
+            break;
+        }
+        results.close();
+        long ns3 = System.currentTimeMillis();
+        
+        System.out.println( "Delta search substring : " + ( ns3 - ns2 ) );
+
+        long ns4 = System.currentTimeMillis();
+        results = connection.search("dc=example,dc=com", "(uid=6789)", SearchScope.SUBTREE, "*" );
+                
+        while ( results.next() )
+        {
+            entry3 = results.get();
+            break;
+        }
+        
+        results.close();
+        long ns5 = System.currentTimeMillis();
+        
+        System.out.println( "Delta search no index : " + ( ns5 - ns4 ) );
+
+        System.out.println( "Entry 1 : " + entry1 );
+        System.out.println( "Entry 2 : " + entry2 );
+        System.out.println( "Entry 3 : " + entry3 );
+        connection.close();
+        
+        // Now, shutdown and restart the server once more
+        getService().shutdown();
+        getService().startup();
+        
+        // and do a search again
+        connection = (LdapNetworkConnection)LdapApiIntegrationUtils.getPooledAdminConnection( getLdapServer() );
+
+        long ns6 = System.currentTimeMillis();
+        results = connection.search("dc=example,dc=com", "(displayName=3456*)", SearchScope.SUBTREE, "*" );
+                
+        while ( results.next() )
+        {
+            entry3 = results.get();
+            break;
+        }
+        
+        results.close();
+        long ns7 = System.currentTimeMillis();
+        System.out.println( "New Delta search substring : " + ( ns7 - ns6 ) );
+
+        connection.close();
+    }
+}

Propchange: directory/apacheds/trunk/ldif-partition/
------------------------------------------------------------------------------
  Merged /directory/apacheds/branches/index-work/ldif-partition:r1324715-1332211

Modified: directory/apacheds/trunk/ldif-partition/src/main/java/org/apache/directory/server/core/partition/ldif/LdifPartition.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/ldif-partition/src/main/java/org/apache/directory/server/core/partition/ldif/LdifPartition.java?rev=1332268&r1=1332267&r2=1332268&view=diff
==============================================================================
--- directory/apacheds/trunk/ldif-partition/src/main/java/org/apache/directory/server/core/partition/ldif/LdifPartition.java (original)
+++ directory/apacheds/trunk/ldif-partition/src/main/java/org/apache/directory/server/core/partition/ldif/LdifPartition.java Mon Apr 30 15:59:22 2012
@@ -34,14 +34,19 @@ import org.apache.directory.server.core.
 import org.apache.directory.server.core.api.interceptor.context.MoveOperationContext;
 import org.apache.directory.server.core.api.interceptor.context.RenameOperationContext;
 import org.apache.directory.server.i18n.I18n;
+import org.apache.directory.server.xdbm.ForwardIndexEntry;
 import org.apache.directory.server.xdbm.IndexCursor;
 import org.apache.directory.server.xdbm.IndexEntry;
+import org.apache.directory.server.xdbm.ParentIdAndRdn;
+import org.apache.directory.server.xdbm.SingletonIndexCursor;
+import org.apache.directory.server.xdbm.search.impl.DescendantCursor;
 import org.apache.directory.shared.ldap.model.constants.SchemaConstants;
 import org.apache.directory.shared.ldap.model.entry.DefaultEntry;
 import org.apache.directory.shared.ldap.model.entry.Entry;
 import org.apache.directory.shared.ldap.model.entry.Modification;
 import org.apache.directory.shared.ldap.model.exception.LdapException;
 import org.apache.directory.shared.ldap.model.exception.LdapInvalidDnException;
+import org.apache.directory.shared.ldap.model.exception.LdapOperationErrorException;
 import org.apache.directory.shared.ldap.model.exception.LdapOperationException;
 import org.apache.directory.shared.ldap.model.ldif.LdifEntry;
 import org.apache.directory.shared.ldap.model.ldif.LdifReader;
@@ -266,7 +271,7 @@ public class LdifPartition extends Abstr
         }
 
         // Get the modified entry and store it in the context for post usage
-        Entry modifiedEntry = lookup( id );
+        Entry modifiedEntry = lookup( id, modifyContext.getDn() );
         modifyContext.setAlteredEntry( modifiedEntry );
 
         // just overwrite the existing file
@@ -297,9 +302,16 @@ public class LdifPartition extends Abstr
         super.move( moveContext );
 
         // Get the modified entry
-        Entry modifiedEntry = lookup( id );
+        Entry modifiedEntry = lookup( id, moveContext.getNewDn() );
 
-        entryMoved( oldDn, modifiedEntry, id );
+        try
+        {
+            entryMoved( oldDn, modifiedEntry, id );
+        }
+        catch ( Exception e )
+        {
+            throw new LdapOperationErrorException( e.getMessage(), e );
+        }
     }
 
 
@@ -314,10 +326,17 @@ public class LdifPartition extends Abstr
         super.moveAndRename( moveAndRenameContext );
 
         // Get the modified entry and store it in the context for post usage
-        Entry modifiedEntry = lookup( id );
+        Entry modifiedEntry = lookup( id, moveAndRenameContext.getNewDn() );
         moveAndRenameContext.setModifiedEntry( modifiedEntry );
 
-        entryMoved( oldDn, modifiedEntry, id );
+        try
+        {
+            entryMoved( oldDn, modifiedEntry, id );
+        }
+        catch ( Exception e )
+        {
+            throw new LdapOperationErrorException( e.getMessage(), e );
+        }
     }
 
 
@@ -333,12 +352,20 @@ public class LdifPartition extends Abstr
         super.rename( renameContext );
 
         // Get the modified entry and store it in the context for post usage
-        Entry modifiedEntry = lookup( id );
+        Dn newDn = oldDn.getParent().add( renameContext.getNewRdn() );
+        Entry modifiedEntry = lookup( id, newDn );
         renameContext.setModifiedEntry( modifiedEntry );
 
         // Now move the potential children for the old entry
         // and remove the old entry
-        entryMoved( oldDn, modifiedEntry, id );
+        try
+        {
+            entryMoved( oldDn, modifiedEntry, id );
+        }
+        catch ( Exception e )
+        {
+            throw new LdapOperationErrorException( e.getMessage(), e );
+        }
     }
 
 
@@ -352,19 +379,30 @@ public class LdifPartition extends Abstr
      * @param deleteOldEntry a flag to tell whether to delete the old entry files
      * @throws Exception
      */
-    private void entryMoved( Dn oldEntryDn, Entry modifiedEntry, Long entryIdOld ) throws LdapException
+    private void entryMoved( Dn oldEntryDn, Entry modifiedEntry, Long entryIdOld ) throws Exception
     {
         // First, add the new entry
         addEntry( modifiedEntry );
+        
+        Long baseId = getEntryId( modifiedEntry.getDn() );
+
+        ParentIdAndRdn<Long> parentIdAndRdn = getRdnIndex().reverseLookup( baseId ); 
+        IndexEntry indexEntry = new ForwardIndexEntry();
+        
+        indexEntry.setId(baseId);
+        indexEntry.setKey( parentIdAndRdn );
+
+        IndexCursor<ParentIdAndRdn<Long>,Entry, Long> cursor = new SingletonIndexCursor<ParentIdAndRdn<Long>, Long>( indexEntry );
+        Long parentId = parentIdAndRdn.getParentId();
+
+        IndexCursor<Long, Entry, Long> scopeCursor = new DescendantCursor( this, baseId, parentId, cursor );
 
         // Then, if there are some children, move then to the new place
         try
         {
-            IndexCursor<Long, Entry, Long> cursor = getSubLevelIndex().forwardCursor( entryIdOld );
-
-            while ( cursor.next() )
+            while ( scopeCursor.next() )
             {
-                IndexEntry<Long, Long> entry = cursor.get();
+                IndexEntry<Long, Long> entry = scopeCursor.get();
 
                 // except the parent entry add the rest of entries
                 if ( entry.getId() != entryIdOld )
@@ -373,13 +411,13 @@ public class LdifPartition extends Abstr
                 }
             }
 
-            cursor.close();
+            scopeCursor.close();
         }
         catch ( Exception e )
         {
             throw new LdapOperationException( e.getMessage(), e );
         }
-
+        
         // And delete the old entry's LDIF file
         File file = getFile( oldEntryDn, DELETE );
         boolean deleted = deleteFile( file );

Modified: directory/apacheds/trunk/ldif-partition/src/main/java/org/apache/directory/server/core/partition/ldif/SingleFileLdifPartition.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/ldif-partition/src/main/java/org/apache/directory/server/core/partition/ldif/SingleFileLdifPartition.java?rev=1332268&r1=1332267&r2=1332268&view=diff
==============================================================================
--- directory/apacheds/trunk/ldif-partition/src/main/java/org/apache/directory/server/core/partition/ldif/SingleFileLdifPartition.java (original)
+++ directory/apacheds/trunk/ldif-partition/src/main/java/org/apache/directory/server/core/partition/ldif/SingleFileLdifPartition.java Mon Apr 30 15:59:22 2012
@@ -331,7 +331,7 @@ public class SingleFileLdifPartition ext
         IndexCursor<ParentIdAndRdn<Long>,Entry,Long> cursor = rdnIdx.forwardCursor();
         
         IndexEntry<ParentIdAndRdn<Long>, Long> startingPos = new ForwardIndexEntry<ParentIdAndRdn<Long>, Long>();
-        startingPos.setValue( new ParentIdAndRdn<Long>( id, (Rdn[]) null ) );
+        startingPos.setKey( new ParentIdAndRdn<Long>( id, (Rdn[]) null ) );
         cursor.before( startingPos );
         int countChildren = 0;
         
@@ -346,7 +346,7 @@ public class SingleFileLdifPartition ext
             countChildren++;
             
             // And now, the children
-            int nbChildren = element.getValue().getNbChildren();
+            int nbChildren = element.getKey().getNbChildren();
             
             if ( nbChildren > 0 )
             {

Propchange: directory/apacheds/trunk/protocol-changepw/
------------------------------------------------------------------------------
  Merged /directory/apacheds/branches/index-work/protocol-changepw:r1324715-1332211

Propchange: directory/apacheds/trunk/protocol-dhcp/
------------------------------------------------------------------------------
  Merged /directory/apacheds/branches/index-work/protocol-dhcp:r1324715-1332211

Propchange: directory/apacheds/trunk/protocol-dns/
------------------------------------------------------------------------------
  Merged /directory/apacheds/branches/index-work/protocol-dns:r1324715-1332211

Propchange: directory/apacheds/trunk/protocol-kerberos/
------------------------------------------------------------------------------
  Merged /directory/apacheds/branches/index-work/protocol-kerberos:r1324715-1332211

Propchange: directory/apacheds/trunk/protocol-ldap/
------------------------------------------------------------------------------
  Merged /directory/apacheds/branches/index-work/protocol-ldap:r1324715-1332211

Propchange: directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/replication/consumer/ReplicationConsumerImpl.java
------------------------------------------------------------------------------
  Merged /directory/apacheds/branches/index-work/protocol-ldap/src/main/java/org/apache/directory/server/ldap/replication/consumer/ReplicationConsumerImpl.java:r1324715-1332211

Propchange: directory/apacheds/trunk/protocol-ntp/
------------------------------------------------------------------------------
  Merged /directory/apacheds/branches/index-work/protocol-ntp:r1324715-1332211

Propchange: directory/apacheds/trunk/protocol-shared/
------------------------------------------------------------------------------
  Merged /directory/apacheds/branches/index-work/protocol-shared:r1324715-1332211

Propchange: directory/apacheds/trunk/server-annotations/
------------------------------------------------------------------------------
  Merged /directory/apacheds/branches/index-work/server-annotations:r1324715-1332211

Propchange: directory/apacheds/trunk/server-config/
------------------------------------------------------------------------------
  Merged /directory/apacheds/branches/index-work/server-config:r1324715-1332211

Modified: directory/apacheds/trunk/server-config/src/main/java/org/apache/directory/server/config/ConfigPartitionReader.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/server-config/src/main/java/org/apache/directory/server/config/ConfigPartitionReader.java?rev=1332268&r1=1332267&r2=1332268&view=diff
==============================================================================
--- directory/apacheds/trunk/server-config/src/main/java/org/apache/directory/server/config/ConfigPartitionReader.java (original)
+++ directory/apacheds/trunk/server-config/src/main/java/org/apache/directory/server/config/ConfigPartitionReader.java Mon Apr 30 15:59:22 2012
@@ -728,8 +728,6 @@ public class ConfigPartitionReader
         // Prepare the search request
         AttributeType adsdAt = schemaManager.getAttributeType( SchemaConstants.OBJECT_CLASS_AT );
         EqualityNode<?> filter = new EqualityNode( adsdAt, new StringValue( name ) );
-        SearchControls controls = new SearchControls();
-        controls.setSearchScope( scope.ordinal() );
         IndexCursor<Long, Entry, Long> cursor = null;
 
         // Create a container for all the read beans
@@ -738,7 +736,7 @@ public class ConfigPartitionReader
         try
         {
             // Do the search
-            cursor = se.cursor( baseDn, AliasDerefMode.NEVER_DEREF_ALIASES, filter, controls );
+            cursor = se.cursor( baseDn, AliasDerefMode.NEVER_DEREF_ALIASES, filter, scope );
 
             // First, check if we have some entries to process.
             if ( !cursor.next() )

Propchange: directory/apacheds/trunk/server-config/src/main/java/org/apache/directory/server/config/ConfigPartitionReader.java
------------------------------------------------------------------------------
  Merged /directory/apacheds/branches/index-work/server-config/src/main/java/org/apache/directory/server/config/ConfigPartitionReader.java:r1324715-1332211

Propchange: directory/apacheds/trunk/server-config/src/main/resources/
------------------------------------------------------------------------------
  Merged /directory/apacheds/branches/index-work/server-config/src/main/resources:r1324715-1332211

Propchange: directory/apacheds/trunk/server-config/src/test/java/org/apache/directory/server/config/ConfigPartitionReaderTest.java
------------------------------------------------------------------------------
  Merged /directory/apacheds/branches/index-work/server-config/src/test/java/org/apache/directory/server/config/ConfigPartitionReaderTest.java:r1324715-1332211

Propchange: directory/apacheds/trunk/server-integ/
------------------------------------------------------------------------------
  Merged /directory/apacheds/branches/index-work/server-integ:r1324715-1332211

Modified: directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/search/ReferralSearchIT.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/search/ReferralSearchIT.java?rev=1332268&r1=1332267&r2=1332268&view=diff
==============================================================================
--- directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/search/ReferralSearchIT.java (original)
+++ directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/search/ReferralSearchIT.java Mon Apr 30 15:59:22 2012
@@ -124,306 +124,334 @@ import org.junit.runner.RunWith;
 })
 public class ReferralSearchIT extends AbstractLdapTestUnit
 {
-
-@Before
-public void setupReferrals() throws Exception
-{
-    String ldif =
-        "dn: c=europ,ou=Countries,ou=system\n" +
-            "objectClass: top\n" +
-            "objectClass: referral\n" +
-            "objectClass: extensibleObject\n" +
-            "c: europ\n" +
-            "ref: ldap://localhost:" + getLdapServer().getPort() + "/c=france,ou=system\n\n" +
-
-            "dn: c=america,ou=Countries,ou=system\n" +
-            "objectClass: top\n" +
-            "objectClass: referral\n" +
-            "objectClass: extensibleObject\n" +
-            "c: america\n" +
-            "ref: ldap://localhost:" + getLdapServer().getPort() + "/c=usa,ou=system\n\n";
-
-    LdifReader reader = new LdifReader( new StringReader( ldif ) );
-
-    while ( reader.hasNext() )
-    {
-        LdifEntry entry = reader.next();
-        getLdapServer().getDirectoryService().getAdminSession().add(
-            new DefaultEntry( getLdapServer().getDirectoryService().getSchemaManager(), entry.getEntry() ) );
-    }
-}
-
-
-@Test
-public void testSearchBaseIsReferral() throws Exception
-{
-    DirContext ctx = getWiredContextThrowOnRefferal( getLdapServer() );
-    SearchControls controls = new SearchControls();
-    controls.setSearchScope( SearchControls.SUBTREE_SCOPE );
-
-    try
-    {
-        ctx.search( "ou=RemoteUsers,ou=system", "(objectClass=*)", controls );
-        fail( "should never get here" );
-    }
-    catch ( ReferralException e )
-    {
-        assertEquals( "ldap://fermi:10389/ou=users,ou=system??sub", e.getReferralInfo() );
-        assertTrue( e.skipReferral() );
-        assertEquals( "ldap://hertz:10389/ou=users,dc=example,dc=com??sub", e.getReferralInfo() );
-        assertTrue( e.skipReferral() );
-        assertEquals( "ldap://maxwell:10389/ou=users,ou=system??sub", e.getReferralInfo() );
-        assertFalse( e.skipReferral() );
-    }
-}
-
-
-@Test
-public void testSearchBaseParentIsReferral() throws Exception
-{
-    DirContext ctx = getWiredContextThrowOnRefferal( getLdapServer() );
-    SearchControls controls = new SearchControls();
-    controls.setSearchScope( SearchControls.OBJECT_SCOPE );
-
-    try
+    @Before
+    public void setupReferrals() throws Exception
     {
-        ctx.search( "cn=alex karasulu,ou=RemoteUsers,ou=system", "(objectClass=*)", controls );
+        String ldif =
+            "dn: c=europ,ou=Countries,ou=system\n" +
+                "objectClass: top\n" +
+                "objectClass: referral\n" +
+                "objectClass: extensibleObject\n" +
+                "c: europ\n" +
+                "ref: ldap://localhost:" + getLdapServer().getPort() + "/c=france,ou=system\n\n" +
+    
+                "dn: c=america,ou=Countries,ou=system\n" +
+                "objectClass: top\n" +
+                "objectClass: referral\n" +
+                "objectClass: extensibleObject\n" +
+                "c: america\n" +
+                "ref: ldap://localhost:" + getLdapServer().getPort() + "/c=usa,ou=system\n\n";
+    
+        LdifReader reader = new LdifReader( new StringReader( ldif ) );
+    
+        while ( reader.hasNext() )
+        {
+            LdifEntry entry = reader.next();
+            getLdapServer().getDirectoryService().getAdminSession().add(
+                new DefaultEntry( getLdapServer().getDirectoryService().getSchemaManager(), entry.getEntry() ) );
+        }
     }
-    catch ( ReferralException e )
+    
+    
+    @Test
+    public void testSearchBaseIsReferral() throws Exception
     {
-        assertEquals( "ldap://fermi:10389/cn=alex%20karasulu,ou=users,ou=system??base", e.getReferralInfo() );
-        assertTrue( e.skipReferral() );
-        assertEquals( "ldap://hertz:10389/cn=alex%20karasulu,ou=users,dc=example,dc=com??base", e.getReferralInfo() );
-        assertTrue( e.skipReferral() );
-        assertEquals( "ldap://maxwell:10389/cn=alex%20karasulu,ou=users,ou=system??base", e.getReferralInfo() );
-        assertFalse( e.skipReferral() );
-    }
-}
-
-
-@Test
-public void testSearchBaseAncestorIsReferral() throws Exception
-{
-    DirContext ctx = getWiredContextThrowOnRefferal( getLdapServer() );
-    SearchControls controls = new SearchControls();
-    controls.setSearchScope( SearchControls.OBJECT_SCOPE );
+        DirContext ctx = getWiredContextThrowOnRefferal( getLdapServer() );
+        SearchControls controls = new SearchControls();
+        controls.setSearchScope( SearchControls.SUBTREE_SCOPE );
 
-    try
-    {
-        ctx.search( "cn=alex karasulu,ou=apache,ou=RemoteUsers,ou=system", "(objectClass=*)", controls );
+        try
+        {
+            ctx.search( "ou=RemoteUsers,ou=system", "(objectClass=*)", controls );
+            fail( "should never get here" );
+        }
+        catch ( ReferralException e )
+        {
+            assertEquals( "ldap://fermi:10389/ou=users,ou=system??sub", e.getReferralInfo() );
+            assertTrue( e.skipReferral() );
+            assertEquals( "ldap://hertz:10389/ou=users,dc=example,dc=com??sub", e.getReferralInfo() );
+            assertTrue( e.skipReferral() );
+            assertEquals( "ldap://maxwell:10389/ou=users,ou=system??sub", e.getReferralInfo() );
+            assertFalse( e.skipReferral() );
+        }
+        finally
+        {
+            ctx.close();
+        }
     }
-    catch ( ReferralException e )
+    
+    
+    @Test
+    public void testSearchBaseParentIsReferral() throws Exception
     {
-        assertEquals( "ldap://fermi:10389/cn=alex%20karasulu,ou=apache,ou=users,ou=system??base", e.getReferralInfo() );
-        assertTrue( e.skipReferral() );
-        assertEquals( "ldap://hertz:10389/cn=alex%20karasulu,ou=apache,ou=users,dc=example,dc=com??base", e
-            .getReferralInfo() );
-        assertTrue( e.skipReferral() );
-        assertEquals( "ldap://maxwell:10389/cn=alex%20karasulu,ou=apache,ou=users,ou=system??base", e
-            .getReferralInfo() );
-        assertFalse( e.skipReferral() );
+        DirContext ctx = getWiredContextThrowOnRefferal( getLdapServer() );
+        SearchControls controls = new SearchControls();
+        controls.setSearchScope( SearchControls.OBJECT_SCOPE );
+    
+        try
+        {
+            ctx.search( "cn=alex karasulu,ou=RemoteUsers,ou=system", "(objectClass=*)", controls );
+        }
+        catch ( ReferralException e )
+        {
+            assertEquals( "ldap://fermi:10389/cn=alex%20karasulu,ou=users,ou=system??base", e.getReferralInfo() );
+            assertTrue( e.skipReferral() );
+            assertEquals( "ldap://hertz:10389/cn=alex%20karasulu,ou=users,dc=example,dc=com??base", e.getReferralInfo() );
+            assertTrue( e.skipReferral() );
+            assertEquals( "ldap://maxwell:10389/cn=alex%20karasulu,ou=users,ou=system??base", e.getReferralInfo() );
+            assertFalse( e.skipReferral() );
+        }
+        finally
+        {
+            ctx.close();
+        }
     }
-}
-
-
-@Test
-public void testSearchContinuations() throws Exception
-{
-    DirContext ctx = getWiredContext( getLdapServer() );
-
-    SearchControls controls = new SearchControls();
-    controls.setSearchScope( SearchControls.SUBTREE_SCOPE );
-    NamingEnumeration<SearchResult> list = ctx.search( "ou=system", "(objectClass=*)", controls );
-    Map<String, SearchResult> results = new HashMap<String, SearchResult>();
-    while ( list.hasMore() )
+    
+    
+    @Test
+    public void testSearchBaseAncestorIsReferral() throws Exception
     {
-        SearchResult result = list.next();
-        results.put( result.getName(), result );
+        DirContext ctx = getWiredContextThrowOnRefferal( getLdapServer() );
+        SearchControls controls = new SearchControls();
+        controls.setSearchScope( SearchControls.OBJECT_SCOPE );
+    
+        try
+        {
+            ctx.search( "cn=alex karasulu,ou=apache,ou=RemoteUsers,ou=system", "(objectClass=*)", controls );
+        }
+        catch ( ReferralException e )
+        {
+            assertEquals( "ldap://fermi:10389/cn=alex%20karasulu,ou=apache,ou=users,ou=system??base", e.getReferralInfo() );
+            assertTrue( e.skipReferral() );
+            assertEquals( "ldap://hertz:10389/cn=alex%20karasulu,ou=apache,ou=users,dc=example,dc=com??base", e
+                .getReferralInfo() );
+            assertTrue( e.skipReferral() );
+            assertEquals( "ldap://maxwell:10389/cn=alex%20karasulu,ou=apache,ou=users,ou=system??base", e
+                .getReferralInfo() );
+            assertFalse( e.skipReferral() );
+        }
+        finally
+        {
+            ctx.close();
+        }
     }
-
-    assertNotNull( results.get( "ou=users" ) );
-
-    // -------------------------------------------------------------------
-    // Now we will throw exceptions when searching for referrals 
-    // -------------------------------------------------------------------
-
-    ctx.addToEnvironment( Context.REFERRAL, "throw" );
-    list = ctx.search( "ou=system", "(objectClass=*)", controls );
-    results = new HashMap<String, SearchResult>();
-
-    try
+    
+    
+    @Test
+    public void testSearchContinuations() throws Exception
     {
+        DirContext ctx = getWiredContext( getLdapServer() );
+    
+        SearchControls controls = new SearchControls();
+        controls.setSearchScope( SearchControls.SUBTREE_SCOPE );
+        NamingEnumeration<SearchResult> list = ctx.search( "ou=system", "(objectClass=*)", controls );
+        Map<String, SearchResult> results = new HashMap<String, SearchResult>();
         while ( list.hasMore() )
         {
             SearchResult result = list.next();
             results.put( result.getName(), result );
         }
-    }
-    catch ( ReferralException e )
-    {
-        // As we use the uuidIndex the order of search continuations returned by
-        // the server is not deterministic. So we collect all referrals first into
-        // an hashset and check afterwards if the expected URLs are included.
-        Set<Object> s = new HashSet<Object>();
-        s.add( e.getReferralInfo() );
-        while ( e.skipReferral() )
+    
+        assertNotNull( results.get( "ou=users" ) );
+    
+        // -------------------------------------------------------------------
+        // Now we will throw exceptions when searching for referrals 
+        // -------------------------------------------------------------------
+    
+        ctx.addToEnvironment( Context.REFERRAL, "throw" );
+        list = ctx.search( "ou=system", "(objectClass=*)", controls );
+        results = new HashMap<String, SearchResult>();
+    
+        try
         {
-            try
+            while ( list.hasMore() )
             {
-                Context ctx2 = e.getReferralContext();
-                ctx2.list( "" );
+                SearchResult result = list.next();
+                results.put( result.getName(), result );
             }
-            catch ( NamingException ne )
+        }
+        catch ( ReferralException e )
+        {
+            // As we use the uuidIndex the order of search continuations returned by
+            // the server is not deterministic. So we collect all referrals first into
+            // an hashset and check afterwards if the expected URLs are included.
+            Set<Object> s = new HashSet<Object>();
+            s.add( e.getReferralInfo() );
+            
+            while ( e.skipReferral() )
             {
-                if ( ne instanceof ReferralException )
+                try
                 {
-                    e = ( ReferralException ) ne;
-                    s.add( e.getReferralInfo() );
+                    Context ctx2 = e.getReferralContext();
+                    ctx2.list( "" );
                 }
-                else
+                catch ( NamingException ne )
                 {
-                    break;
+                    if ( ne instanceof ReferralException )
+                    {
+                        e = ( ReferralException ) ne;
+                        s.add( e.getReferralInfo() );
+                    }
+                    else
+                    {
+                        break;
+                    }
                 }
             }
+    
+            assertEquals( 5, s.size() );
+            assertTrue( s.contains( "ldap://fermi:10389/ou=users,ou=system??sub" ) );
+            assertTrue( s.contains( "ldap://hertz:10389/ou=users,dc=example,dc=com??sub" ) );
+            assertTrue( s.contains( "ldap://maxwell:10389/ou=users,ou=system??sub" ) );
         }
-
-        assertEquals( 5, s.size() );
-        assertTrue( s.contains( "ldap://fermi:10389/ou=users,ou=system??sub" ) );
-        assertTrue( s.contains( "ldap://hertz:10389/ou=users,dc=example,dc=com??sub" ) );
-        assertTrue( s.contains( "ldap://maxwell:10389/ou=users,ou=system??sub" ) );
-    }
-
-    assertNull( results.get( "ou=remoteusers" ) );
-
-    // try again but this time with single level scope
-
-    controls.setSearchScope( SearchControls.ONELEVEL_SCOPE );
-    list = ctx.search( "ou=system", "(objectClass=*)", controls );
-    results = new HashMap<String, SearchResult>();
-
-    try
-    {
-        while ( list.hasMore() )
+    
+        assertNull( results.get( "ou=remoteusers" ) );
+        list.close();
+    
+        // try again but this time with single level scope
+    
+        controls.setSearchScope( SearchControls.ONELEVEL_SCOPE );
+        list = ctx.search( "ou=system", "(objectClass=*)", controls );
+        results = new HashMap<String, SearchResult>();
+    
+        try
         {
-            SearchResult result = list.next();
-            results.put( result.getName(), result );
+            while ( list.hasMore() )
+            {
+                SearchResult result = list.next();
+                results.put( result.getName(), result );
+            }
+        }
+        catch ( ReferralException e )
+        {
+            assertEquals( "ldap://fermi:10389/ou=users,ou=system??base", e.getReferralInfo() );
+            assertTrue( e.skipReferral() );
+            assertEquals( "ldap://hertz:10389/ou=users,dc=example,dc=com??base", e.getReferralInfo() );
+            assertTrue( e.skipReferral() );
+            assertEquals( "ldap://maxwell:10389/ou=users,ou=system??base", e.getReferralInfo() );
+        }
+        
+        list.close();
+        ctx.close();
+
+        assertNull( results.get( "ou=remoteusers" ) );
+    }
+    
+    
+    /**
+     * Test of an search operation with a referral
+     *
+     * search for "cn=alex karasulu" on "c=america, ou=system"
+     * we should get a referral URL thrown, which point to
+     * "c=usa, ou=system", and ask for a subtree search
+     */
+    @Test
+    public void testSearchWithReferralThrow() throws Exception
+    {
+        DirContext ctx = getWiredContextThrowOnRefferal( getLdapServer() );
+    
+        try
+        {
+            SearchControls controls = new SearchControls();
+            controls.setSearchScope( SearchControls.SUBTREE_SCOPE );
+            ctx.search( "c=america,ou=Countries,ou=system", "(cn=alex karasulu)", controls );
+            fail( "Should fail here throwing a ReferralException" );
+        }
+        catch ( ReferralException re )
+        {
+            String referral = ( String ) re.getReferralInfo();
+            assertEquals( "ldap://localhost:" + getLdapServer().getPort() + "/c=usa,ou=system??sub", referral );
+        }
+        finally
+        {
+            ctx.close();
         }
     }
-    catch ( ReferralException e )
-    {
-        assertEquals( "ldap://fermi:10389/ou=users,ou=system??base", e.getReferralInfo() );
-        assertTrue( e.skipReferral() );
-        assertEquals( "ldap://hertz:10389/ou=users,dc=example,dc=com??base", e.getReferralInfo() );
-        assertTrue( e.skipReferral() );
-        assertEquals( "ldap://maxwell:10389/ou=users,ou=system??base", e.getReferralInfo() );
-    }
-
-    assertNull( results.get( "ou=remoteusers" ) );
-}
-
-
-/**
- * Test of an search operation with a referral
- *
- * search for "cn=alex karasulu" on "c=america, ou=system"
- * we should get a referral URL thrown, which point to
- * "c=usa, ou=system", and ask for a subtree search
- */
-@Test
-public void testSearchWithReferralThrow() throws Exception
-{
-    DirContext ctx = getWiredContextThrowOnRefferal( getLdapServer() );
-
-    try
+    
+    
+    /**
+     * Test of an search operation with a referral
+     *
+     * search for "cn=alex karasulu" on "c=america, ou=system"
+     * we should get a referral URL thrown, which point to
+     * "c=usa, ou=system", and ask for a subtree search
+     */
+    @Test
+    public void testSearchBaseWithReferralThrow() throws Exception
     {
+        DirContext ctx = getWiredContextThrowOnRefferal( getLdapServer() );
+    
         SearchControls controls = new SearchControls();
-        controls.setSearchScope( SearchControls.SUBTREE_SCOPE );
-        ctx.search( "c=america,ou=Countries,ou=system", "(cn=alex karasulu)", controls );
-        fail( "Should fail here throwing a ReferralException" );
-    }
-    catch ( ReferralException re )
-    {
-        String referral = ( String ) re.getReferralInfo();
-        assertEquals( "ldap://localhost:" + getLdapServer().getPort() + "/c=usa,ou=system??sub", referral );
-    }
-}
-
-
-/**
- * Test of an search operation with a referral
- *
- * search for "cn=alex karasulu" on "c=america, ou=system"
- * we should get a referral URL thrown, which point to
- * "c=usa, ou=system", and ask for a subtree search
- */
-@Test
-public void testSearchBaseWithReferralThrow() throws Exception
-{
-    DirContext ctx = getWiredContextThrowOnRefferal( getLdapServer() );
-
-    SearchControls controls = new SearchControls();
-    controls.setSearchScope( SearchControls.OBJECT_SCOPE );
-
-    try
-    {
-        ctx.search( "c=america,ou=Countries,ou=system", "(cn=alex karasulu)", controls );
-        fail( "Should fail here throwing a ReferralException" );
-    }
-    catch ( ReferralException re )
-    {
-        String referral = ( String ) re.getReferralInfo();
-        assertEquals( "ldap://localhost:" + getLdapServer().getPort() + "/c=usa,ou=system??base", referral );
-    }
-}
-
-
-/**
- * Test of an search operation with a referral after the entry
- * has been renamed.
- *
- * search for "cn=alex karasulu" on "c=usa, ou=system"
- * we should get a referral URL thrown, which point to
- * "c=usa, ou=system", and ask for a subtree search
- */
-@Test
-public void testSearchBaseWithReferralThrowAfterRename() throws Exception
-{
-    DirContext ctx = getWiredContextThrowOnRefferal( getLdapServer() );
-
-    SearchControls controls = new SearchControls();
-    controls.setSearchScope( SearchControls.OBJECT_SCOPE );
-
-    try
-    {
-        ctx.search( "c=america,ou=Countries,ou=system", "(cn=alex karasulu)", controls );
-        fail( "Should fail here throwing a ReferralException" );
-    }
-    catch ( ReferralException re )
-    {
-        String referral = ( String ) re.getReferralInfo();
-        assertEquals( "ldap://localhost:" + getLdapServer().getPort() + "/c=usa,ou=system??base", referral );
-    }
-
-    ( ( LdapContext ) ctx ).setRequestControls( new javax.naming.ldap.Control[]
-        { new ManageReferralControl() } );
-
-    // Now let's move the entry
-    ctx.rename( "c=america,ou=Countries,ou=system", "c=USA,ou=Countries,ou=system" );
-
-    controls.setSearchScope( SearchControls.OBJECT_SCOPE );
-
-    ( ( LdapContext ) ctx ).setRequestControls( new javax.naming.ldap.Control[]
-        {} );
-
-    try
-    {
-        ctx.search( "c=usa,ou=Countries,ou=system", "(cn=alex karasulu)", controls );
-        fail( "Should fail here throwing a ReferralException" );
+        controls.setSearchScope( SearchControls.OBJECT_SCOPE );
+    
+        try
+        {
+            ctx.search( "c=america,ou=Countries,ou=system", "(cn=alex karasulu)", controls );
+            fail( "Should fail here throwing a ReferralException" );
+        }
+        catch ( ReferralException re )
+        {
+            String referral = ( String ) re.getReferralInfo();
+            assertEquals( "ldap://localhost:" + getLdapServer().getPort() + "/c=usa,ou=system??base", referral );
+        }
+        finally
+        {
+            ctx.close();
+        }
     }
-    catch ( ReferralException re )
+    
+    
+    /**
+     * Test of an search operation with a referral after the entry
+     * has been renamed.
+     *
+     * search for "cn=alex karasulu" on "c=usa, ou=system"
+     * we should get a referral URL thrown, which point to
+     * "c=usa, ou=system", and ask for a subtree search
+     */
+    @Test
+    public void testSearchBaseWithReferralThrowAfterRename() throws Exception
     {
-        String referral = ( String ) re.getReferralInfo();
-        assertEquals( "ldap://localhost:" + getLdapServer().getPort() + "/c=usa,ou=system??base", referral );
+        DirContext ctx = getWiredContextThrowOnRefferal( getLdapServer() );
+    
+        SearchControls controls = new SearchControls();
+        controls.setSearchScope( SearchControls.OBJECT_SCOPE );
+    
+        try
+        {
+            ctx.search( "c=america,ou=Countries,ou=system", "(cn=alex karasulu)", controls );
+            fail( "Should fail here throwing a ReferralException" );
+        }
+        catch ( ReferralException re )
+        {
+            String referral = ( String ) re.getReferralInfo();
+            assertEquals( "ldap://localhost:" + getLdapServer().getPort() + "/c=usa,ou=system??base", referral );
+        }
+    
+        ( ( LdapContext ) ctx ).setRequestControls( new javax.naming.ldap.Control[]
+            { new ManageReferralControl() } );
+    
+        // Now let's move the entry
+        ctx.rename( "c=america,ou=Countries,ou=system", "c=USA,ou=Countries,ou=system" );
+    
+        controls.setSearchScope( SearchControls.OBJECT_SCOPE );
+    
+        ( ( LdapContext ) ctx ).setRequestControls( new javax.naming.ldap.Control[]
+            {} );
+    
+        try
+        {
+            ctx.search( "c=usa,ou=Countries,ou=system", "(cn=alex karasulu)", controls );
+            fail( "Should fail here throwing a ReferralException" );
+        }
+        catch ( ReferralException re )
+        {
+            String referral = ( String ) re.getReferralInfo();
+            assertEquals( "ldap://localhost:" + getLdapServer().getPort() + "/c=usa,ou=system??base", referral );
+        }
+        finally
+        {
+            ctx.close();
+        }
     }
-}
 }
\ No newline at end of file

Modified: directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/search/SearchIT.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/search/SearchIT.java?rev=1332268&r1=1332267&r2=1332268&view=diff
==============================================================================
--- directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/search/SearchIT.java (original)
+++ directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/search/SearchIT.java Mon Apr 30 15:59:22 2012
@@ -835,7 +835,9 @@ public class SearchIT extends AbstractLd
         {
             SearchResult sr = enm.next();
             assertNotNull( sr );
-            assertEquals( "Name in namespace", nameInNamespace, sr.getNameInNamespace() );
+            Dn expectedDn = new Dn( nameInNamespace ).getParent().add( mixedRdn );
+            
+            assertEquals( "Name in namespace", expectedDn, sr.getNameInNamespace() );
         }
         else
         {

Modified: directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/search/SearchPerfIT.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/search/SearchPerfIT.java?rev=1332268&r1=1332267&r2=1332268&view=diff
==============================================================================
--- directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/search/SearchPerfIT.java (original)
+++ directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/search/SearchPerfIT.java Mon Apr 30 15:59:22 2012
@@ -6,16 +6,16 @@
  *  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. 
- *  
+ *  under the License.
+ * 
  */
 package org.apache.directory.server.operations.search;
 
@@ -23,6 +23,7 @@ package org.apache.directory.server.oper
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.fail;
 
+import org.apache.directory.ldap.client.api.EntryCursorImpl;
 import org.apache.directory.ldap.client.api.LdapConnection;
 import org.apache.directory.ldap.client.api.LdapNetworkConnection;
 import org.apache.directory.server.annotations.CreateLdapServer;
@@ -31,7 +32,11 @@ import org.apache.directory.server.core.
 import org.apache.directory.server.core.integ.FrameworkRunner;
 import org.apache.directory.shared.ldap.model.cursor.EntryCursor;
 import org.apache.directory.shared.ldap.model.exception.LdapException;
+import org.apache.directory.shared.ldap.model.message.AliasDerefMode;
+import org.apache.directory.shared.ldap.model.message.SearchRequest;
+import org.apache.directory.shared.ldap.model.message.SearchRequestImpl;
 import org.apache.directory.shared.ldap.model.message.SearchScope;
+import org.apache.directory.shared.ldap.model.name.Dn;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 
@@ -52,10 +57,8 @@ public class SearchPerfIT extends Abstra
      * test a search request perf.
      */
     @Test
-    public void testSearchRequestPerf() throws Exception
+    public void testSearchRequestObjectScopePerf() throws Exception
     {
-        //getLdapServer().getDirectoryService().getInterceptorChain().addFirst( new TimerInterceptor( "Start" ) );
-        //getLdapServer().getDirectoryService().getInterceptorChain().addLast( new TimerInterceptor( "End" ) );
         LdapConnection connection = new LdapNetworkConnection( "localhost", getLdapServer().getPort() );
 
         try
@@ -90,27 +93,251 @@ public class SearchPerfIT extends Abstra
                 cursor.close();
             }
 
+            Dn dn = new Dn( getService().getSchemaManager(), "uid=admin,ou=system" );
+
+            SearchRequest searchRequest = new SearchRequestImpl();
+
+            searchRequest.setBase( dn );
+            searchRequest.setFilter( "(ObjectClass=*)" );
+            searchRequest.setScope( SearchScope.OBJECT );
+            searchRequest.addAttributes( "*" );
+            searchRequest.setDerefAliases( AliasDerefMode.DEREF_ALWAYS );
+
             long t0 = System.currentTimeMillis();
+            long t00 = 0L;
+            long tt0 = System.currentTimeMillis();
             int nbIterations = 200000;
 
             for ( int j = 0; j < nbIterations; j++ )
             {
                 if ( j % 10000 == 0 )
                 {
-                    System.out.println( j );
+                    long tt1 = System.currentTimeMillis();
+                    
+                    System.out.println( j + ", " + ( tt1 - tt0 ) );
+                    tt0 = tt1;
+                }
+                
+                if ( j == 50000 )
+                {
+                    t00 = System.currentTimeMillis();
                 }
 
-                cursor = connection.search( "uid=admin,ou=system", "(ObjectClass=*)", SearchScope.OBJECT, "*" );
+                cursor = new EntryCursorImpl( connection.search( searchRequest ) );
+
+                while ( cursor.next() )
+                {
+                    cursor.get();
+                }
+                
+                cursor.close();
+            }
+
+            long t1 = System.currentTimeMillis();
+
+            Long deltaWarmed = ( t1 - t00 );
+            System.out.println( "Delta : " + deltaWarmed + "( " + ( ( ( nbIterations - 50000 ) * 1000 ) / deltaWarmed )
+                + " per s ) /" + ( t1 - t0 ) );
+        }
+        catch ( LdapException e )
+        {
+            e.printStackTrace();
+            fail( "Should not have caught exception." );
+        }
+        finally
+        {
+            connection.unBind();
+            connection.close();
+        }
+    }
+
+
+    /**
+     * test a search request perf.
+     */
+    @Test
+    public void testSearchRequestOneLevelScopePerf() throws Exception
+    {
+        LdapConnection connection = new LdapNetworkConnection( "localhost", getLdapServer().getPort() );
+
+        try
+        {
+            // Use the client API as JNDI cannot be used to do a search without
+            // first binding. (hmmm, even client API won't allow searching without binding)
+            connection.bind( "uid=admin,ou=system", "secret" );
+
+            // Searches for all the entries in ou=system
+            EntryCursor cursor = connection.search( "ou=system", "(ObjectClass=*)",
+                SearchScope.ONELEVEL, "*" );
+
+            int i = 0;
+
+            while ( cursor.next() )
+            {
+                cursor.get();
+                ++i;
+            }
+
+            cursor.close();
+            assertEquals( 5, i );
+
+            for ( int j = 0; j < 10000; j++ )
+            {
+                cursor = connection.search( "ou=system", "(ObjectClass=*)", SearchScope.ONELEVEL, "*" );
+
+                while ( cursor.next() )
+                {
+                    cursor.get();
+                }
+
+                cursor.close();
+            }
+
+            Dn dn = new Dn( getService().getSchemaManager(), "uid=admin,ou=system" );
+
+            SearchRequest searchRequest = new SearchRequestImpl();
+
+            searchRequest.setBase( dn );
+            searchRequest.setFilter( "(ObjectClass=*)" );
+            searchRequest.setScope( SearchScope.ONELEVEL );
+            searchRequest.addAttributes( "*" );
+            searchRequest.setDerefAliases( AliasDerefMode.DEREF_ALWAYS );
+
+            long t0 = System.currentTimeMillis();
+            long t00 = 0L;
+            long tt0 = System.currentTimeMillis();
+            int nbIterations = 200000;
+
+            for ( int j = 0; j < nbIterations; j++ )
+            {
+                if ( j % 10000 == 0 )
+                {
+                    long tt1 = System.currentTimeMillis();
+                    
+                    System.out.println( j + ", " + ( tt1 - tt0 ) );
+                    tt0 = tt1;
+                }
+                
+                if ( j == 50000 )
+                {
+                    t00 = System.currentTimeMillis();
+                }
+
+                cursor = new EntryCursorImpl( connection.search( searchRequest ) );
+
+                while ( cursor.next() )
+                {
+                    cursor.get();
+                }
+                
+                cursor.close();
+            }
+
+            long t1 = System.currentTimeMillis();
+
+            Long deltaWarmed = ( t1 - t00 );
+            System.out.println( "Delta : " + deltaWarmed + "( " + ( ( ( nbIterations - 50000 ) * 1000 ) / deltaWarmed )
+                + " per s ) /" + ( t1 - t0 ) );
+        }
+        catch ( LdapException e )
+        {
+            e.printStackTrace();
+            fail( "Should not have caught exception." );
+        }
+        finally
+        {
+            connection.unBind();
+            connection.close();
+        }
+    }
+
+
+    /**
+     * test a search request perf.
+     */
+    @Test
+    public void testSearchRequestSubtreeLevelScopePerf() throws Exception
+    {
+        LdapConnection connection = new LdapNetworkConnection( "localhost", getLdapServer().getPort() );
+        connection.setTimeOut( 0 );
+
+        try
+        {
+            // Use the client API as JNDI cannot be used to do a search without
+            // first binding. (hmmm, even client API won't allow searching without binding)
+            connection.bind( "uid=admin,ou=system", "secret" );
+
+            // Searches for all the entries in ou=system
+            EntryCursor cursor = connection.search( "ou=system", "(ObjectClass=*)",
+                SearchScope.SUBTREE, "*" );
+
+            int i = 0;
+
+            while ( cursor.next() )
+            {
+                cursor.get();
+                ++i;
+            }
+
+            cursor.close();
+            assertEquals( 10, i );
+
+            for ( int j = 0; j < 10000; j++ )
+            {
+                cursor = connection.search( "ou=system", "(ObjectClass=*)", SearchScope.SUBTREE, "*" );
+
+                while ( cursor.next() )
+                {
+                    cursor.get();
+                }
+
+                cursor.close();
+            }
+
+            Dn dn = new Dn( getService().getSchemaManager(), "uid=admin,ou=system" );
+
+            SearchRequest searchRequest = new SearchRequestImpl();
+
+            searchRequest.setBase( dn );
+            searchRequest.setFilter( "(ObjectClass=*)" );
+            searchRequest.setScope( SearchScope.SUBTREE );
+            searchRequest.addAttributes( "*" );
+            searchRequest.setDerefAliases( AliasDerefMode.DEREF_ALWAYS );
+
+            long t0 = System.currentTimeMillis();
+            long t00 = 0L;
+            long tt0 = System.currentTimeMillis();
+            int nbIterations = 200000;
+
+            for ( int j = 0; j < nbIterations; j++ )
+            {
+                if ( j % 10000 == 0 )
+                {
+                    long tt1 = System.currentTimeMillis();
+                    
+                    System.out.println( j + ", " + ( tt1 - tt0 ) );
+                    tt0 = tt1;
+                }
+                
+                if ( j == 50000 )
+                {
+                    t00 = System.currentTimeMillis();
+                }
+
+                cursor = new EntryCursorImpl( connection.search( searchRequest ) );
+
                 while ( cursor.next() )
                 {
+                    cursor.get();
                 }
+                
                 cursor.close();
             }
 
             long t1 = System.currentTimeMillis();
 
-            Long deltaWarmed = ( t1 - t0 );
-            System.out.println( "Delta : " + deltaWarmed + "( " + ( ( nbIterations * 1000 ) / deltaWarmed )
+            Long deltaWarmed = ( t1 - t00 );
+            System.out.println( "Delta : " + deltaWarmed + "( " + ( ( ( nbIterations - 50000 ) * 1000 ) / deltaWarmed )
                 + " per s ) /" + ( t1 - t0 ) );
         }
         catch ( LdapException e )

Propchange: directory/apacheds/trunk/server-jndi/
------------------------------------------------------------------------------
  Merged /directory/apacheds/branches/index-work/server-jndi:r1324715-1332211

Propchange: directory/apacheds/trunk/server-replication/
------------------------------------------------------------------------------
  Merged /directory/apacheds/branches/index-work/server-replication:r1324715-1332211

Propchange: directory/apacheds/trunk/server-tools/
------------------------------------------------------------------------------
  Merged /directory/apacheds/branches/index-work/server-tools:r1324715-1332211

Propchange: directory/apacheds/trunk/service/
------------------------------------------------------------------------------
  Merged /directory/apacheds/branches/index-work/service:r1324715-1332211

Propchange: directory/apacheds/trunk/service-builder/
------------------------------------------------------------------------------
  Merged /directory/apacheds/branches/index-work/service-builder:r1324715-1332211

Propchange: directory/apacheds/trunk/test-framework/
------------------------------------------------------------------------------
  Merged /directory/apacheds/branches/index-work/test-framework:r1324715-1332211

Propchange: directory/apacheds/trunk/xdbm-partition/
------------------------------------------------------------------------------
  Merged /directory/apacheds/branches/index-work/xdbm-partition:r1324715-1332211

Modified: directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/AbstractBTreePartition.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/AbstractBTreePartition.java?rev=1332268&r1=1332267&r2=1332268&view=diff
==============================================================================
--- directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/AbstractBTreePartition.java (original)
+++ directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/AbstractBTreePartition.java Mon Apr 30 15:59:22 2012
@@ -23,24 +23,20 @@ package org.apache.directory.server.core
 import java.io.IOException;
 import java.io.OutputStream;
 import java.net.URI;
-import java.util.ArrayList;
+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.atomic.AtomicBoolean;
 
-import javax.naming.directory.SearchControls;
-
 import org.apache.directory.server.constants.ApacheSchemaConstants;
 import org.apache.directory.server.core.api.entry.ClonedServerEntry;
 import org.apache.directory.server.core.api.filtering.BaseEntryFilteringCursor;
 import org.apache.directory.server.core.api.filtering.EntryFilteringCursor;
 import org.apache.directory.server.core.api.interceptor.context.AddOperationContext;
 import org.apache.directory.server.core.api.interceptor.context.DeleteOperationContext;
-import org.apache.directory.server.core.api.interceptor.context.GetRootDseOperationContext;
 import org.apache.directory.server.core.api.interceptor.context.HasEntryOperationContext;
 import org.apache.directory.server.core.api.interceptor.context.ListOperationContext;
 import org.apache.directory.server.core.api.interceptor.context.LookupOperationContext;
@@ -60,14 +56,11 @@ import org.apache.directory.server.xdbm.
 import org.apache.directory.server.xdbm.IndexNotFoundException;
 import org.apache.directory.server.xdbm.MasterTable;
 import org.apache.directory.server.xdbm.ParentIdAndRdn;
-import org.apache.directory.server.xdbm.ReverseIndexEntry;
 import org.apache.directory.server.xdbm.Store;
 import org.apache.directory.server.xdbm.search.Optimizer;
 import org.apache.directory.server.xdbm.search.SearchEngine;
 import org.apache.directory.server.xdbm.search.impl.ChildrenCursor;
-import org.apache.directory.server.xdbm.search.impl.OneLevelScopeCursor;
 import org.apache.directory.shared.ldap.model.constants.SchemaConstants;
-import org.apache.directory.shared.ldap.model.cursor.Cursor;
 import org.apache.directory.shared.ldap.model.entry.Attribute;
 import org.apache.directory.shared.ldap.model.entry.Entry;
 import org.apache.directory.shared.ldap.model.entry.Modification;
@@ -84,6 +77,7 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.model.filter.ExprNode;
 import org.apache.directory.shared.ldap.model.message.AliasDerefMode;
 import org.apache.directory.shared.ldap.model.message.ResultCodeEnum;
+import org.apache.directory.shared.ldap.model.message.SearchScope;
 import org.apache.directory.shared.ldap.model.name.Ava;
 import org.apache.directory.shared.ldap.model.name.Dn;
 import org.apache.directory.shared.ldap.model.name.Rdn;
@@ -150,9 +144,6 @@ public abstract class AbstractBTreeParti
     /** a system index on objectClass attribute*/
     protected Index<String, Entry, ID> objectClassIdx;
 
-    /** a system index on the entries of descendants of root Dn */
-    protected Index<ID, Entry, ID> subLevelIdx;
-
     /** the attribute presence index */
     protected Index<String, Entry, ID> presenceIdx;
 
@@ -180,8 +171,8 @@ public abstract class AbstractBTreeParti
     private static final boolean NO_REVERSE = Boolean.FALSE;
     private static final boolean WITH_REVERSE = Boolean.TRUE;
     
-    private static final boolean ADD_CHILD = true;
-    private static final boolean REMOVE_CHILD = false;
+    protected static final boolean ADD_CHILD = true;
+    protected static final boolean REMOVE_CHILD = false;
 
     // ------------------------------------------------------------------------
     // C O N S T R U C T O R S
@@ -296,12 +287,6 @@ public abstract class AbstractBTreeParti
             addIndex( index );
         }
 
-        if ( getSubLevelIndex() == null )
-        {
-            Index<ID, Entry, ID> index = createSystemIndex( ApacheSchemaConstants.APACHE_SUB_LEVEL_AT_OID, partitionPath, WITH_REVERSE );
-            addIndex( index );
-        }
-
         if ( getRdnIndex() == null )
         {
             Index<ParentIdAndRdn<ID>, Entry, ID> index = createSystemIndex( ApacheSchemaConstants.APACHE_RDN_AT_OID, partitionPath, WITH_REVERSE );
@@ -355,7 +340,6 @@ public abstract class AbstractBTreeParti
         // set index shortcuts
         rdnIdx = ( Index<ParentIdAndRdn<ID>, Entry, ID> ) systemIndices.get( ApacheSchemaConstants.APACHE_RDN_AT_OID );
         presenceIdx = ( Index<String, Entry, ID> ) systemIndices.get( ApacheSchemaConstants.APACHE_PRESENCE_AT_OID );
-        subLevelIdx = ( Index<ID, Entry, ID> ) systemIndices.get( ApacheSchemaConstants.APACHE_SUB_LEVEL_AT_OID );
         aliasIdx = ( Index<String, Entry, ID> ) systemIndices.get( ApacheSchemaConstants.APACHE_ALIAS_AT_OID );
         oneAliasIdx = ( Index<ID, Entry, ID> ) systemIndices.get( ApacheSchemaConstants.APACHE_ONE_ALIAS_AT_OID );
         subAliasIdx = ( Index<ID, Entry, ID> ) systemIndices.get( ApacheSchemaConstants.APACHE_SUB_ALIAS_AT_OID );
@@ -550,13 +534,13 @@ public abstract class AbstractBTreeParti
     }
     
     
-    private void dumpRdnIdx( ID id, String tabs ) throws Exception
+    public void dumpRdnIdx( ID id, String tabs ) throws Exception
     {
         // Start with the root
         IndexCursor<ParentIdAndRdn<ID>,Entry,ID> cursor = rdnIdx.forwardCursor();
         
         IndexEntry<ParentIdAndRdn<ID>, ID> startingPos = new ForwardIndexEntry<ParentIdAndRdn<ID>, ID>();
-        startingPos.setValue( new ParentIdAndRdn( id, (Rdn[]) null ) );
+        startingPos.setKey( new ParentIdAndRdn( id, (Rdn[]) null ) );
         cursor.before( startingPos );
         
         while ( cursor.next() )
@@ -575,7 +559,7 @@ public abstract class AbstractBTreeParti
         IndexCursor<ParentIdAndRdn<ID>,Entry,ID> cursor = rdnIdx.forwardCursor();
         
         IndexEntry<ParentIdAndRdn<ID>, ID> startingPos = new ForwardIndexEntry<ParentIdAndRdn<ID>, ID>();
-        startingPos.setValue( new ParentIdAndRdn( id, (Rdn[]) null ) );
+        startingPos.setKey( new ParentIdAndRdn( id, (Rdn[]) null ) );
         cursor.before( startingPos );
         int countChildren = 0;
         
@@ -586,7 +570,7 @@ public abstract class AbstractBTreeParti
             countChildren++;
             
             // And now, the children
-            int nbChildren = entry.getValue().getNbChildren();
+            int nbChildren = entry.getKey().getNbChildren();
             
             if ( nbChildren > 0 )
             {
@@ -683,18 +667,6 @@ public abstract class AbstractBTreeParti
                 addAliasIndices( id, entryDn, aliasAttr.getString() );
             }
 
-            // Update the SubLevel index
-            ID tempId = parentId;
-
-            while ( ( tempId != null ) && ( !tempId.equals( getRootId() ) ) && ( !tempId.equals( getSuffixId() ) ) )
-            {
-                subLevelIdx.add( tempId, id );
-                tempId = getParentId( tempId );
-            }
-
-            // making entry an ancestor/descendent of itself in sublevel index
-            subLevelIdx.add( id, id );
-
             // Update the EntryCsn index
             Attribute entryCsn = entry.get( ENTRY_CSN_AT );
 
@@ -794,7 +766,7 @@ public abstract class AbstractBTreeParti
     }
     
     
-    private void updateRdnIdx( ID parentId, boolean addRemove, int nbDescendant ) throws Exception
+    protected void updateRdnIdx( ID parentId, boolean addRemove, int nbDescendant ) throws Exception
     {
         boolean isFirst = true;
         
@@ -831,6 +803,8 @@ public abstract class AbstractBTreeParti
             }
 
             // Inject the modified element into the index
+            // we first need to drop it so that the key can be replaced
+            rdnIdx.drop( parentId );
             rdnIdx.add( parent, parentId );
             
             parentId = parent.getParentId();
@@ -879,7 +853,6 @@ public abstract class AbstractBTreeParti
             
             dumpRdnIdx();
 
-            subLevelIdx.drop( id );
             entryCsnIdx.drop( entry.get( ENTRY_CSN_AT ).getString(), id );
             entryUuidIdx.drop( entry.get( ENTRY_UUID_AT ).getString(), id );
 
@@ -950,7 +923,7 @@ public abstract class AbstractBTreeParti
             IndexCursor<ParentIdAndRdn<ID>,Entry, ID> cursor = rdnIdx.forwardCursor();
             
             IndexEntry<ParentIdAndRdn<ID>, ID> startingPos = new ForwardIndexEntry<ParentIdAndRdn<ID>, ID>();
-            startingPos.setValue( new ParentIdAndRdn( id, (Rdn[]) null ) );
+            startingPos.setKey( new ParentIdAndRdn( id, (Rdn[]) null ) );
             cursor.before( startingPos );
 
             dumpRdnIdx();
@@ -974,13 +947,13 @@ public abstract class AbstractBTreeParti
     {
         try
         {
-            SearchControls searchCtls = searchContext.getSearchControls();
+            SearchScope scope = searchContext.getScope();
             IndexCursor<ID, Entry, ID> underlying;
             Dn dn = searchContext.getDn();
             AliasDerefMode derefMode = searchContext.getAliasDerefMode();
             ExprNode filter = searchContext.getFilter();
 
-            underlying = searchEngine.cursor( dn, derefMode, filter, searchCtls );
+            underlying = searchEngine.cursor( dn, derefMode, filter, scope );
 
             return new BaseEntryFilteringCursor( new EntryCursorAdaptor<ID>( this, underlying ), searchContext );
         }
@@ -1011,7 +984,7 @@ public abstract class AbstractBTreeParti
             return null;
         }
 
-        Entry entry = lookup( id );
+        Entry entry = lookup( id, lookupContext.getDn() );
 
         // Remove all the attributes if the NO_ATTRIBUTE flag is set and there is no requested attribute
         if ( lookupContext.hasNoAttribute()
@@ -1124,6 +1097,36 @@ public abstract class AbstractBTreeParti
     }
 
 
+    /**
+     * Get back an entry knowing its ID
+     *
+     * @param id The Entry ID we want to get back
+     * @return The found Entry, or null if not found
+     * @throws Exception If the lookup failed for any reason (except a not found entry)
+     */
+    public Entry lookup( ID id, Dn dn ) throws LdapException
+    {
+        try
+        {
+            Entry entry = master.get( id );
+
+            if ( entry != null )
+            {
+                // We have to store the DN in this entry
+                entry.setDn( dn );
+
+                return new ClonedServerEntry( entry );
+            }
+
+            return null;
+        }
+        catch ( Exception e )
+        {
+            throw new LdapOperationErrorException( e.getMessage(), e );
+        }
+    }
+
+
     //---------------------------------------------------------------------------------------------
     // The Modify operation
     //---------------------------------------------------------------------------------------------
@@ -1526,12 +1529,6 @@ public abstract class AbstractBTreeParti
          */
         dropMovedAliasIndices( oldDn );
 
-        /*
-         * Drop the old parent child relationship and add the new one
-         * Set the new parent id for the child replacing the old parent id
-         */
-        updateSubLevelIndex( entryId, oldParentId, newParentId );
-
         // Update the Rdn index
         // First drop the old entry
         ParentIdAndRdn<ID> movedEntry = rdnIdx.reverseLookup( entryId );
@@ -1711,12 +1708,6 @@ public abstract class AbstractBTreeParti
         dropMovedAliasIndices( oldDn );
 
         /*
-         * Drop the old parent child relationship and add the new one
-         * Set the new parent id for the child replacing the old parent id
-         */
-        updateSubLevelIndex( entryId, oldParentId, newParentId );
-
-        /*
          * Update the Rdn index
          */
         // First drop the old entry
@@ -1910,9 +1901,18 @@ public abstract class AbstractBTreeParti
          * No need to calculate the new Dn.
          */
         ID parentId = getParentId( oldId );
+        
+        // Get the old parentIdAndRdn to get the nb of children and descendant
+        ParentIdAndRdn<ID> parentIdAndRdn = rdnIdx.reverseLookup( oldId );
+        
+        // Now we can drop it
         rdnIdx.drop( oldId );
-        ParentIdAndRdn<ID> key = new ParentIdAndRdn<ID>( parentId, newRdn );
-        rdnIdx.add( key, oldId );
+        
+        // Update the descendants
+        parentIdAndRdn.setParentId( parentId );
+        parentIdAndRdn.setRdns( newRdn );
+
+        rdnIdx.add( parentIdAndRdn, oldId );
 
         if ( isSyncOnWrite.get() )
         {
@@ -1944,7 +1944,7 @@ public abstract class AbstractBTreeParti
         {
             ID id = getEntryId( entryContext.getDn() );
 
-            Entry entry = lookup( id );
+            Entry entry = lookup( id, entryContext.getDn() );
 
             return entry != null;
         }
@@ -1973,69 +1973,6 @@ public abstract class AbstractBTreeParti
     }
 
 
-    /**
-     * Updates the SubLevel Index as part of a move operation.
-     *
-     * @param entryId child id to be moved
-     * @param oldParentId old parent's id
-     * @param newParentId new parent's id
-     * @throws Exception
-     */
-    private void updateSubLevelIndex( ID entryId, ID oldParentId, ID newParentId ) throws Exception
-    {
-        ID tempId = oldParentId;
-        List<ID> parentIds = new ArrayList<ID>();
-
-        // find all the parents of the oldParentId
-        while ( ( tempId != null ) && !tempId.equals( getRootId() ) && !tempId.equals( getSuffixId() ) )
-        {
-            parentIds.add( tempId );
-            tempId = getParentId( tempId );
-        }
-
-        // find all the children of the childId
-        Cursor<IndexEntry<ID, ID>> cursor = subLevelIdx.forwardCursor( entryId );
-
-        List<ID> childIds = new ArrayList<ID>();
-        childIds.add( entryId );
-
-        while ( cursor.next() )
-        {
-            childIds.add( cursor.get().getId() );
-        }
-
-        cursor.close();
-
-        // detach the childId and all its children from oldParentId and all it parents excluding the root
-        for ( ID pid : parentIds )
-        {
-            for ( ID cid : childIds )
-            {
-                subLevelIdx.drop( pid, cid );
-            }
-        }
-
-        parentIds.clear();
-        tempId = newParentId;
-
-        // find all the parents of the newParentId
-        while ( ( tempId != null ) && !tempId.equals( getRootId() ) && !tempId.equals( getSuffixId() ) )
-        {
-            parentIds.add( tempId );
-            tempId = getParentId( tempId );
-        }
-
-        // attach the childId and all its children to newParentId and all it parents excluding the root
-        for ( ID id : parentIds )
-        {
-            for ( ID cid : childIds )
-            {
-                subLevelIdx.add( id, cid );
-            }
-        }
-    }
-
-
     // ------------------------------------------------------------------------
     // Index and master table Operations
     // ------------------------------------------------------------------------
@@ -2051,8 +1988,9 @@ public abstract class AbstractBTreeParti
         ID parentId = id;
         ID rootId = getRootId();
 
-        StringBuilder upName = new StringBuilder();
-        boolean isFirst = true;
+        // Create an array of 10 rdns, just in case. We will extend it if needed
+        Rdn[] rdnArray = new Rdn[10];
+        int pos = 0;
 
         do
         {
@@ -2061,23 +1999,22 @@ public abstract class AbstractBTreeParti
 
             for ( Rdn rdn : rdns )
             {
-                if ( isFirst )
-                {
-                    isFirst = false;
-                }
-                else
+                if ( ( pos > 0 ) && (pos % 10 == 0 ) )
                 {
-                    upName.append( ',' );
+                    // extend the array
+                    Rdn[] newRdnArray = new Rdn[pos + 10];
+                    System.arraycopy( rdnArray, 0, newRdnArray, 0, pos );
+                    rdnArray = newRdnArray;
                 }
-
-                upName.append( rdn.getName() );
+                
+                rdnArray[pos++]= rdn;
             }
 
             parentId = cur.getParentId();
         }
         while ( !parentId.equals( rootId ) );
 
-        Dn dn = new Dn( schemaManager, upName.toString() );
+        Dn dn = new Dn( schemaManager, Arrays.copyOf( rdnArray, pos ) );
 
         return dn;
     }
@@ -2343,16 +2280,6 @@ public abstract class AbstractBTreeParti
      * {@inheritDoc}
      */
     @SuppressWarnings("unchecked")
-    public Index<ID, Entry, ID> getSubLevelIndex()
-    {
-        return ( Index<ID, Entry, ID> ) systemIndices.get( ApacheSchemaConstants.APACHE_SUB_LEVEL_AT_OID );
-    }
-
-
-    /**
-     * {@inheritDoc}
-     */
-    @SuppressWarnings("unchecked")
     public Index<String, Entry, ID> getAliasIndex()
     {
         return ( Index<String, Entry, ID> ) systemIndices.get( ApacheSchemaConstants.APACHE_ALIAS_AT_OID );

Modified: directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/IndexEnumeration.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/IndexEnumeration.java?rev=1332268&r1=1332267&r2=1332268&view=diff
==============================================================================
--- directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/IndexEnumeration.java (original)
+++ directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/IndexEnumeration.java Mon Apr 30 15:59:22 2012
@@ -170,7 +170,7 @@ public class IndexEnumeration<T> impleme
             // If regex is null just transfer into prefetched from tmp record
             // but if it is not then use it to match.  Successful match shorts
             // while loop.
-            if ( null == re || re.matcher( ( String ) tmp.getValue() ).matches() )
+            if ( null == re || re.matcher( ( String ) tmp.getKey() ).matches() )
             {
                 prefetched.copy( tmp );
                 return;

Modified: directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/AbstractIndexEntry.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/AbstractIndexEntry.java?rev=1332268&r1=1332267&r2=1332268&view=diff
==============================================================================
--- directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/AbstractIndexEntry.java (original)
+++ directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/AbstractIndexEntry.java Mon Apr 30 15:59:22 2012
@@ -28,10 +28,10 @@ import org.apache.directory.shared.ldap.
  * Abstract class managing the object for index entries.
  *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
- * @param <V> The value stored in the Tuple, associated key for the object
+ * @param <K> The key stored in the Tuple, associated key for the object
  * @param <ID> The ID of the object
  */
-public abstract class AbstractIndexEntry<V, ID> implements IndexEntry<V, ID>
+public abstract class AbstractIndexEntry<K, ID> implements IndexEntry<K, ID>
 {
     /** The referenced Entry if loaded from the store */
     private Entry entry;
@@ -51,13 +51,13 @@ public abstract class AbstractIndexEntry
     /**
      * {@inheritDoc}
      */
-    public abstract V getValue();
+    public abstract K getKey();
 
 
     /**
      * {@inheritDoc}
      */
-    public abstract void setValue( V value );
+    public abstract void setKey( K value );
 
 
     /**
@@ -108,7 +108,7 @@ public abstract class AbstractIndexEntry
     /**
      * {@inheritDoc}
      */
-    public void copy( IndexEntry<V, ID> entry )
+    public void copy( IndexEntry<K, ID> entry )
     {
         this.entry = entry.getEntry();
     }

Modified: directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/ForwardIndexEntry.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/ForwardIndexEntry.java?rev=1332268&r1=1332267&r2=1332268&view=diff
==============================================================================
--- directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/ForwardIndexEntry.java (original)
+++ directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/ForwardIndexEntry.java Mon Apr 30 15:59:22 2012
@@ -29,13 +29,13 @@ import org.apache.directory.shared.ldap.
  * indexed Entry if one has already been loaded.
  * 
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
- * @param <V> The value stored in the Tuple, associated key for the object
+ * @param <V> The key stored in the Tuple, associated key for the object
  * @param <ID> The ID of the object
  */
-public class ForwardIndexEntry<V, ID> extends AbstractIndexEntry<V, ID>
+public class ForwardIndexEntry<K, ID> extends AbstractIndexEntry<K, ID>
 {
     /** The underlying Tuple */
-    private final Tuple<V, ID> tuple = new Tuple<V, ID>();
+    private final Tuple<K, ID> tuple = new Tuple<K, ID>();
 
 
     /**
@@ -55,7 +55,7 @@ public class ForwardIndexEntry<V, ID> ex
      * @param tuple the tuple for the ForwardIndexEntry
      * @param entry the resuscitated Entry if any
      */
-    public void setTuple( Tuple<V, ID> tuple, Entry entry )
+    public void setTuple( Tuple<K, ID> tuple, Entry entry )
     {
         setEntry( entry );
         this.tuple.setKey( tuple.getKey() );
@@ -75,7 +75,7 @@ public class ForwardIndexEntry<V, ID> ex
     /**
      * {@inheritDoc}
      */
-    public V getValue()
+    public K getKey()
     {
         return tuple.getKey();
     }
@@ -93,7 +93,7 @@ public class ForwardIndexEntry<V, ID> ex
     /**
      * {@inheritDoc}
      */
-    public void setValue( V value )
+    public void setKey( K value )
     {
         tuple.setKey( value );
     }
@@ -102,7 +102,7 @@ public class ForwardIndexEntry<V, ID> ex
     /**
      * {@inheritDoc}
      */
-    public Tuple<V, ID> getTuple()
+    public Tuple<K, ID> getTuple()
     {
         return tuple;
     }
@@ -122,10 +122,10 @@ public class ForwardIndexEntry<V, ID> ex
     /**
      * {@inheritDoc}
      */
-    public void copy( IndexEntry<V, ID> entry )
+    public void copy( IndexEntry<K, ID> entry )
     {
         super.copy( entry );
-        tuple.setKey( entry.getValue() );
+        tuple.setKey( entry.getKey() );
         tuple.setValue( entry.getId() );
     }
 

Modified: directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/IndexEntry.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/IndexEntry.java?rev=1332268&r1=1332267&r2=1332268&view=diff
==============================================================================
--- directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/IndexEntry.java (original)
+++ directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/IndexEntry.java Mon Apr 30 15:59:22 2012
@@ -26,29 +26,29 @@ import org.apache.directory.shared.ldap.
 
 /**
  * Interface for index entries. An index entry associate an Entry with 
- * a value (the key) and the Entry ID in the table where it's stored. The Entry
+ * a key and the Entry ID in the table where it's stored. The Entry
  * may be present in this instance once we read it from the table.
  *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @param <V> The value stored in the Tuple, associated key for the object
  * @param <ID> The ID of the object
  */
-public interface IndexEntry<V, ID>
+public interface IndexEntry<K, ID>
 {
     /**
-     * Gets the value referred to by this IndexEntry.
+     * Gets the key referred to by this IndexEntry.
      *
-     * @return the value of the Entry referred to
+     * @return the key of the Entry referred to
      */
-    V getValue();
+    K getKey();
 
 
     /**
-     * Sets the value referred to by this IndexEntry.
+     * Sets the key referred to by this IndexEntry.
      *
-     * @param value the value of the Entry referred to
+     * @param key the key of the Entry referred to
      */
-    void setValue( V value );
+    void setKey( K key );
 
 
     /**
@@ -102,5 +102,5 @@ public interface IndexEntry<V, ID>
      *
      * @param entry the entry to copy fields of
      */
-    void copy( IndexEntry<V, ID> entry );
+    void copy( IndexEntry<K, ID> entry );
 }

Modified: directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/ParentIdAndRdn.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/ParentIdAndRdn.java?rev=1332268&r1=1332267&r2=1332268&view=diff
==============================================================================
--- directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/ParentIdAndRdn.java (original)
+++ directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/ParentIdAndRdn.java Mon Apr 30 15:59:22 2012
@@ -125,7 +125,7 @@ public class ParentIdAndRdn<ID extends C
      * 
      * @param rdns the new Rdn
      */
-    public void setRdns( Rdn[] rdns )
+    public void setRdns( Rdn... rdns )
     {
         this.rdns = rdns;
     }
@@ -226,6 +226,8 @@ public class ParentIdAndRdn<ID extends C
         {
             return val;
         }
+        
+        // The ID is the same, check the RDNs now
 
         val = rdns.length - that.rdns.length;
 
@@ -234,47 +236,27 @@ public class ParentIdAndRdn<ID extends C
             return val;
         }
         
-        StringBuilder sb = new StringBuilder();
-        boolean isFirst = true;
-        
-        for ( Rdn rdn : rdns )
+        if ( rdns.length == 1 )
         {
-            if ( isFirst )
-            {
-                sb.append( ',' );
-            }
-            else
-            {
-                isFirst = false;
-            }
+            // Special case : we only have one rdn.
+            val = rdns[0].getNormName().compareTo( that.rdns[0].getNormName() );
             
-            sb.append( rdn.getNormName() );
+            return val;
         }
-        
-        String thisString = sb.toString();
-        
-        isFirst = true;
-        sb = new StringBuilder();
-
-        for ( Rdn rdn : that.rdns )
+        else
         {
-            if ( isFirst )
-            {
-                sb.append( ',' );
-            }
-            else
+            for ( int i = 0; i < rdns.length; i++ )
             {
-                isFirst = false;
+                val = rdns[i].getNormName().compareTo( that.rdns[i].getNormName() );
+            
+                if ( val != 0 )
+                {
+                    return val;
+                }
             }
             
-            sb.append( rdn.getNormName() );
+            return 0;
         }
-        
-        String thatString = sb.toString();
-        
-        val = ( thisString.compareTo( thatString ) );
-        
-        return val;
     }
 
 



Mime
View raw message