directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From seelm...@apache.org
Subject svn commit: r939508 - in /directory/apacheds/trunk: jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/ jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/ xdbm-base/src/main/java/org/ap...
Date Thu, 29 Apr 2010 23:12:59 GMT
Author: seelmann
Date: Thu Apr 29 23:12:59 2010
New Revision: 939508

URL: http://svn.apache.org/viewvc?rev=939508&view=rev
Log:
Allow multiple RDNs for the context entry

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/JdbmRdnIndexTest.java
    directory/apacheds/trunk/xdbm-base/src/main/java/org/apache/directory/server/xdbm/ParentIdAndRdn.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=939508&r1=939507&r2=939508&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
Thu Apr 29 23:12:59 2010
@@ -322,7 +322,7 @@ public class JdbmStore<E> extends Abstra
         int dnSize = dn.size();
         int i = suffixDn.size();
 
-        ParentIdAndRdn<Long> key = new ParentIdAndRdn<Long>( 0L, suffixDn.getRdn()
);
+        ParentIdAndRdn<Long> key = new ParentIdAndRdn<Long>( 0L, suffixDn.getRdns()
);
 
         Long curEntryId = rdnIdx.forwardLookup( key );
 
@@ -362,33 +362,16 @@ public class JdbmStore<E> extends Abstra
         DN dn = new DN();
 
         long parentId = id.longValue();
-        
+
         do
         {
             ParentIdAndRdn<Long> cur = rdnIdx.reverseLookup( parentId );
-            RDN curRdn = cur.getRdn();
-            parentId = cur.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. dc=example,dc=com
-                if ( contextEntryDn == null )
-                {
-                    contextEntryDn = new DN( curRdn.getName() );
-                    contextEntryDn.normalize( schemaManager.getNormalizerMapping() );
-                }
-                
-                for ( RDN rdn : contextEntryDn )
-                {
-                    dn.addNormalizedInOrder( rdn );
-                }
-            }
-            else
+            RDN[] rdns = cur.getRdns();
+            for ( RDN rdn : rdns )
             {
-                // not the suffix, add the RDN to the DN
-                dn.addNormalizedInOrder( curRdn );
+                dn.addNormalizedInOrder( rdn );
             }
+            parentId = cur.getParentId();
         }
         while ( parentId != 0 );
 
@@ -415,13 +398,13 @@ public class JdbmStore<E> extends Abstra
         int dnSize = normDN.size();
         int i = suffixDn.size();
 
-        ParentIdAndRdn<Long> key = new ParentIdAndRdn<Long>(0L, suffixDn.getRdn());
+        ParentIdAndRdn<Long> key = new ParentIdAndRdn<Long>( 0L, suffixDn.getRdns()
);
 
         Long curEntryId = rdnIdx.forwardLookup( key );
 
         for ( ; i < dnSize; i++ )
         {
-            key = new ParentIdAndRdn<Long>(curEntryId, normDN.getRdn( i ));
+            key = new ParentIdAndRdn<Long>( curEntryId, normDN.getRdn( i ) );
             curEntryId = rdnIdx.forwardLookup( key );
         }
 
@@ -677,20 +660,18 @@ public class JdbmStore<E> extends Abstra
         //
         DN entryDn = entry.getDn();
         DN parentDn = null;
-        RDN rdn = null;
+        ParentIdAndRdn<Long> key = null;
 
-        if ( entryDn.getNormName().equals( suffixDn.getNormName() ) )
+        if ( entryDn.equals( suffixDn ) )
         {
             parentId = 0L;
-            rdn = new RDN( suffixDn.getNormName() );
-            rdn.setUpName( entryDn.getName() );
+            key = new ParentIdAndRdn<Long>( parentId, suffixDn.getRdns() );
         }
         else
         {
-            rdn = entryDn.getRdn();
-            parentDn = ( DN ) entryDn.clone();
-            parentDn.remove( parentDn.size() - 1 );
+            parentDn = entryDn.getParent();
             parentId = getEntryId( parentDn );
+            key = new ParentIdAndRdn<Long>( parentId, entryDn.getRdn() );
         }
 
         // don't keep going if we cannot find the parent Id
@@ -699,7 +680,6 @@ public class JdbmStore<E> extends Abstra
             throw new LdapNoSuchObjectException( I18n.err( I18n.ERR_216, parentDn ) );
         }
 
-        ParentIdAndRdn<Long> key = new ParentIdAndRdn<Long>( parentId, rdn );
         rdnIdx.add( key, id );
 
         EntryAttribute objectClass = entry.get( OBJECT_CLASS_AT );

Modified: directory/apacheds/trunk/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmRdnIndexTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmRdnIndexTest.java?rev=939508&r1=939507&r2=939508&view=diff
==============================================================================
--- directory/apacheds/trunk/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmRdnIndexTest.java
(original)
+++ directory/apacheds/trunk/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmRdnIndexTest.java
Thu Apr 29 23:12:59 2010
@@ -345,19 +345,19 @@ public class JdbmRdnIndexTest
         cursor.next();
         IndexEntry<ParentIdAndRdn<Long>, Long, Long> e1 = cursor.get();
         assertEquals( 0, ( long ) e1.getId() );
-        assertEquals( "cn=key", e1.getValue().getRdn().getName() );
+        assertEquals( "cn=key", e1.getValue().getRdns()[0].getName() );
         assertEquals( 0, e1.getValue().getParentId().longValue() );
 
         cursor.next();
         IndexEntry<ParentIdAndRdn<Long>, Long, Long> e2 = cursor.get();
         assertEquals( 1, ( long ) e2.getId() );
-        assertEquals( "cn=key1", e2.getValue().getRdn().getName() );
+        assertEquals( "cn=key1", e2.getValue().getRdns()[0].getName() );
         assertEquals( 1, e2.getValue().getParentId().longValue() );
         
         cursor.next();
         IndexEntry<ParentIdAndRdn<Long>, Long, Long> e3 = cursor.get();
         assertEquals( 2, ( long ) e3.getId() );
-        assertEquals( "cn=key2", e3.getValue().getRdn().getName() );
+        assertEquals( "cn=key2", e3.getValue().getRdns()[0].getName() );
         assertEquals( 2, e3.getValue().getParentId().longValue() );
     }
 

Modified: directory/apacheds/trunk/xdbm-base/src/main/java/org/apache/directory/server/xdbm/ParentIdAndRdn.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/xdbm-base/src/main/java/org/apache/directory/server/xdbm/ParentIdAndRdn.java?rev=939508&r1=939507&r2=939508&view=diff
==============================================================================
--- directory/apacheds/trunk/xdbm-base/src/main/java/org/apache/directory/server/xdbm/ParentIdAndRdn.java
(original)
+++ directory/apacheds/trunk/xdbm-base/src/main/java/org/apache/directory/server/xdbm/ParentIdAndRdn.java
Thu Apr 29 23:12:59 2010
@@ -24,6 +24,8 @@ import java.io.Externalizable;
 import java.io.IOException;
 import java.io.ObjectInput;
 import java.io.ObjectOutput;
+import java.util.Arrays;
+import java.util.List;
 
 import org.apache.directory.shared.ldap.name.RDN;
 
@@ -38,7 +40,7 @@ public class ParentIdAndRdn<ID extends C
 {
 
     protected ID parentId;
-    protected RDN rdn;
+    protected RDN[] rdns;
 
 
     /**
@@ -53,12 +55,25 @@ public class ParentIdAndRdn<ID extends C
      * Creates a new instance of ParentIdAndRdn.
      *
      * @param parentId the parent ID
-     * @param rdn the RDN
+     * @param rdns the RDNs
      */
-    public ParentIdAndRdn( ID parentId, RDN rdn )
+    public ParentIdAndRdn( ID parentId, RDN... rdns )
     {
         this.parentId = parentId;
-        this.rdn = rdn;
+        this.rdns = rdns;
+    }
+
+
+    /**
+     * Creates a new instance of ParentIdAndRdn.
+     *
+     * @param parentId the parent ID
+     * @param rdns the RDNs
+     */
+    public ParentIdAndRdn( ID parentId, List<RDN> rdns )
+    {
+        this.parentId = parentId;
+        this.rdns = rdns.toArray( new RDN[rdns.size()] );
     }
 
 
@@ -85,13 +100,13 @@ public class ParentIdAndRdn<ID extends C
 
 
     /**
-     * Gets the RDN.
+     * Gets the RDNs.
      * 
-     * @return the RDN
+     * @return the RDNs
      */
-    public RDN getRdn()
+    public RDN[] getRdns()
     {
-        return rdn;
+        return rdns;
     }
 
 
@@ -100,9 +115,9 @@ public class ParentIdAndRdn<ID extends C
      * 
      * @param rdn the new RDN
      */
-    public void setRdn( RDN rdn )
+    public void setRdns( RDN[] rdns )
     {
-        this.rdn = rdn;
+        this.rdns = rdns;
     }
 
 
@@ -112,7 +127,7 @@ public class ParentIdAndRdn<ID extends C
         final int prime = 31;
         int result = 1;
         result = prime * result + ( ( parentId == null ) ? 0 : parentId.hashCode() );
-        result = prime * result + ( ( rdn == null ) ? 0 : rdn.hashCode() );
+        result = prime * result + Arrays.hashCode( rdns );
         return result;
     }
 
@@ -132,12 +147,22 @@ public class ParentIdAndRdn<ID extends C
 
     public int compareTo( ParentIdAndRdn<ID> o )
     {
-        int val = this.getRdn().compareTo( o.getRdn() );
-        if ( val == 0 )
+        int val = this.rdns.length - o.rdns.length;
+        if ( val != 0 )
+        {
+            return val;
+        }
+
+        for ( int i = 0; i < this.rdns.length; i++ )
         {
-            val = this.getParentId().compareTo( o.getParentId() );
+            val = this.rdns[i].compareTo( o.rdns[i] );
+            if ( val != 0 )
+            {
+                return val;
+            }
         }
 
+        val = this.getParentId().compareTo( o.getParentId() );
         return val;
     }
 
@@ -145,7 +170,11 @@ public class ParentIdAndRdn<ID extends C
     public void writeExternal( ObjectOutput out ) throws IOException
     {
         out.writeObject( parentId );
-        out.writeObject( rdn );
+        out.writeInt( rdns.length );
+        for ( RDN rdn : rdns )
+        {
+            out.writeObject( rdn );
+        }
     }
 
 
@@ -153,6 +182,11 @@ public class ParentIdAndRdn<ID extends C
     public void readExternal( ObjectInput in ) throws IOException, ClassNotFoundException
     {
         parentId = ( ID ) in.readObject();
-        rdn = ( RDN ) in.readObject();
+        int size = in.readInt();
+        rdns = new RDN[size];
+        for ( int i = 0; i < size; i++ )
+        {
+            rdns[i] = ( RDN ) in.readObject();
+        }
     }
 }



Mime
View raw message