directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1143218 - in /directory: apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/AbstractStore.java shared/trunk/ldap/model/src/test/java/org/apache/directory/shared/ldap/model/name/DnParserTest.java
Date Tue, 05 Jul 2011 22:35:26 GMT
Author: elecharny
Date: Tue Jul  5 22:35:26 2011
New Revision: 1143218

URL: http://svn.apache.org/viewvc?rev=1143218&view=rev
Log:
o Improved the getEntryId() method
o Added a test for the Dn.get( i ) method

Modified:
    directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/AbstractStore.java
    directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/shared/ldap/model/name/DnParserTest.java

Modified: directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/AbstractStore.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/AbstractStore.java?rev=1143218&r1=1143217&r2=1143218&view=diff
==============================================================================
--- directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/AbstractStore.java
(original)
+++ directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/AbstractStore.java
Tue Jul  5 22:35:26 2011
@@ -760,34 +760,35 @@ public abstract class AbstractStore<E, I
      */
     public ID getEntryId( Dn dn ) throws Exception
     {
+        if ( Dn.isNullOrEmpty( dn ) )
+        {
+            return getRootId();
+        }
+
         // Just to be sure that the Dn is normalized
         if ( !dn.isSchemaAware() )
         {
             dn.apply( schemaManager );
         }
 
-        int dnSize = dn.size();
-        int i = suffixDn.size();
-
-        ParentIdAndRdn<ID> currentRdn = new ParentIdAndRdn<ID>( getRootId(),
suffixDn.getRdns() );
+        ParentIdAndRdn<ID> suffixKey = new ParentIdAndRdn<ID>( getRootId(), suffixDn.getRdns()
);
 
-        // Check into the Rdn index
-        ID curEntryId = rdnIdx.forwardLookup( currentRdn );
+        // Check into the Rdn index, starting with the partition Suffix
+        ID currentId = rdnIdx.forwardLookup( suffixKey );
 
-        while ( i < dnSize )
+        for ( int i = dn.size() - suffixDn.size(); i > 0; i-- )
         {
-            currentRdn = new ParentIdAndRdn<ID>( curEntryId, dn.getRdn( dnSize - 1
- i ) );
-            curEntryId = rdnIdx.forwardLookup( currentRdn );
+            Rdn rdn = dn.getRdn( i - 1 );
+            ParentIdAndRdn<ID> currentRdn = new ParentIdAndRdn<ID>( currentId,
rdn );
+            currentId = rdnIdx.forwardLookup( currentRdn );
 
-            if ( curEntryId == null )
+            if ( currentId == null )
             {
                 break;
             }
-            
-            i++;
         }
 
-        return curEntryId;
+        return currentId;
     }
 
 
@@ -859,11 +860,6 @@ public abstract class AbstractStore<E, I
     @SuppressWarnings("unchecked")
     public synchronized void add( Entry entry ) throws Exception
     {
-        if ( entry instanceof ClonedServerEntry )
-        {
-            throw new Exception( I18n.err( I18n.ERR_215 ) );
-        }
-
         Dn entryDn = entry.getDn();
 
         if ( checkHasEntryDuringAdd )
@@ -878,7 +874,6 @@ public abstract class AbstractStore<E, I
         }
 
         ID parentId;
-        ID id = master.getNextId( entry );
 
         //
         // Suffix entry cannot have a parent since it is the root so it is
@@ -912,6 +907,8 @@ public abstract class AbstractStore<E, I
             throw new LdapNoSuchObjectException( I18n.err( I18n.ERR_216, parentDn ) );
         }
 
+        ID id = master.getNextId( entry );
+
         rdnIdx.add( key, id );
 
         Attribute objectClass = entry.get( OBJECT_CLASS_AT );

Modified: directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/shared/ldap/model/name/DnParserTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/shared/ldap/model/name/DnParserTest.java?rev=1143218&r1=1143217&r2=1143218&view=diff
==============================================================================
--- directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/shared/ldap/model/name/DnParserTest.java
(original)
+++ directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/shared/ldap/model/name/DnParserTest.java
Tue Jul  5 22:35:26 2011
@@ -594,4 +594,18 @@ public class DnParserTest
             return;
         }
     }
+    
+    
+    /**
+     * Test the Dn.get( int ) method
+     */
+    @Test
+    public void testGetRdnN() throws Exception
+    {
+        Dn dn = new Dn( "cn=test,dc=example,dc=org" );
+        
+        assertEquals( "cn=test", dn.getRdn( 0 ).getName() );
+        assertEquals( "dc=example", dn.getRdn( 1 ).getName() );
+        assertEquals( "dc=org", dn.getRdn( 2 ).getName() );
+    }
 }



Mime
View raw message