directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From seelm...@apache.org
Subject svn commit: r936075 - in /directory/apacheds/trunk/jdbm-store/src: main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmStore.java test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmStoreTest.java
Date Tue, 20 Apr 2010 21:55:33 GMT
Author: seelmann
Date: Tue Apr 20 21:55:33 2010
New Revision: 936075

URL: http://svn.apache.org/viewvc?rev=936075&view=rev
Log:
Fixed building of DN when suffix size > 1

Modified:
    directory/apacheds/trunk/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmStore.java
    directory/apacheds/trunk/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmStoreTest.java

Modified: directory/apacheds/trunk/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmStore.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmStore.java?rev=936075&r1=936074&r2=936075&view=diff
==============================================================================
--- directory/apacheds/trunk/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmStore.java
(original)
+++ directory/apacheds/trunk/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmStore.java
Tue Apr 20 21:55:33 2010
@@ -141,6 +141,7 @@ public class JdbmStore<E> implements Sto
     /** A pointer on the schemaManager */
     private SchemaManager schemaManager;
 
+    private DN contextEntryDn;
     private String suffixDn;
     private int cacheSize = DEFAULT_CACHE_SIZE;
     private String name;
@@ -981,7 +982,7 @@ public class JdbmStore<E> implements Sto
         return buildEntryDn( id ).getNormName();
     }
 
-    
+
     /**
      * builds the DN of the entry identified by the given id
      *
@@ -992,21 +993,39 @@ public class JdbmStore<E> implements Sto
     private DN buildEntryDn( Long id ) throws Exception
     {
         DN dn = new DN();
-        
-        // form the DN
-        RDN curRdn = rdnIdx.reverseLookup( id );
 
-        dn.addNormalizedInOrder( curRdn );
-        
-        while( curRdn._getParentId() != 0 )
+        long parentId = id.longValue();
+        do
         {
-            curRdn = rdnIdx.reverseLookup( curRdn._getParentId() );
-            dn.addNormalizedInOrder( curRdn );
+            RDN curRdn = rdnIdx.reverseLookup( parentId );
+            parentId = curRdn._getParentId();
+            if ( parentId == 0 )
+            {
+                // we reached the suffix, add the context entry DN
+                // we do this because the suffix can consist 
+                // of multiple RDNs, e.g. ec=example,dc=com
+                if ( contextEntryDn == null )
+                {
+                    contextEntryDn = new DN( curRdn.getName() );
+                    contextEntryDn.normalize( schemaManager.getNormalizerMapping() );
+                }
+                for ( RDN rdn : contextEntryDn )
+                {
+                    dn.addNormalizedInOrder( rdn );
+                }
+            }
+            else
+            {
+                // not the suffix, add the RDN to the DN
+                dn.addNormalizedInOrder( curRdn );
+            }
         }
+        while ( parentId != 0 );
 
         return dn;
     }
 
+
     /**
      * 
      * contructs a normalized DN using the RDN index. This is useful

Modified: directory/apacheds/trunk/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmStoreTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmStoreTest.java?rev=936075&r1=936074&r2=936075&view=diff
==============================================================================
--- directory/apacheds/trunk/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmStoreTest.java
(original)
+++ directory/apacheds/trunk/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmStoreTest.java
Tue Apr 20 21:55:33 2010
@@ -136,7 +136,7 @@ public class JdbmStoreTest
         store.setSyncOnWrite( false );
         store.addIndex( new JdbmIndex( SchemaConstants.OU_AT_OID ) );
         store.addIndex( new JdbmIndex( SchemaConstants.UID_AT_OID ) );
-
+        
         StoreUtils.loadExampleData( store, schemaManager );
         LOG.debug( "Created new store" );
     }
@@ -161,6 +161,48 @@ public class JdbmStoreTest
     }
 
 
+    /**
+     * Tests a suffix with two name components: dc=example,dc=com.
+     * When reading this entry back from the store the DN must
+     * consist of two RDNs.
+     */
+    @Test
+    public void testTwoComponentSuffix() throws Exception
+    {
+        // setup the working directory for the 2nd store
+        File wkdir2 = File.createTempFile( getClass().getSimpleName(), "db2" );
+        wkdir2.delete();
+        wkdir2 = new File( wkdir2.getParentFile(), getClass().getSimpleName() );
+        wkdir2.mkdirs();
+
+        // initialize the 2nd store
+        JdbmStore<ServerEntry> store2 = new JdbmStore<ServerEntry>();
+        store2.setName( "example2" );
+        store2.setCacheSize( 10 );
+        store2.setWorkingDirectory( wkdir2 );
+        store2.setSyncOnWrite( false );
+        store2.addIndex( new JdbmIndex( SchemaConstants.OU_AT_OID ) );
+        store2.addIndex( new JdbmIndex( SchemaConstants.UID_AT_OID ) );
+        store2.setSuffixDn( "dc=example,dc=com" );
+        store2.init( schemaManager );
+
+        // inject context entry
+        DN suffixDn = new DN( "dc=example,dc=com" );
+        suffixDn.normalize( schemaManager.getNormalizerMapping() );
+        DefaultServerEntry entry = new DefaultServerEntry( schemaManager, suffixDn );
+        entry.add( "objectClass", "top", "domain" );
+        entry.add( "dc", "example" );
+        entry.add( SchemaConstants.ENTRY_CSN_AT, new CsnFactory( 0 ).newInstance().toString()
);
+        entry.add( SchemaConstants.ENTRY_UUID_AT, UUID.randomUUID().toString() );
+        store2.add( entry );
+
+        // lookup the context entry
+        Long id = store2.getEntryId( suffixDn );
+        ServerEntry lookup = store2.lookup( id );
+        assertEquals( 2, lookup.getDn().getRdns().size() );
+    }
+
+
     @Test
     public void testSimplePropertiesUnlocked() throws Exception
     {



Mime
View raw message