directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1301718 - in /directory: apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/ apacheds/trunk/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/ shared/trunk/integ/src/test/java/org/apache/directory/shar...
Date Fri, 16 Mar 2012 19:47:27 GMT
Author: elecharny
Date: Fri Mar 16 19:47:27 2012
New Revision: 1301718

URL: http://svn.apache.org/viewvc?rev=1301718&view=rev
Log:
o The AVAs in a RDN are now order if the RDN is schemaAware, in order to be able to compare
cn=doe+gn=john with gn=john+cn=doe
o The ParanetIdAndRdn now uses the RDN normalized name in order to speed up the comparison
method.
o Added some tests

Modified:
    directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/ParentIdAndRdn.java
    directory/apacheds/trunk/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/ParentIdAndRdnTest.java
    directory/shared/trunk/integ/src/test/java/org/apache/directory/shared/ldap/model/name/RdnTest.java
    directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/name/Dn.java

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=1301718&r1=1301717&r2=1301718&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
Fri Mar 16 19:47:27 2012
@@ -27,7 +27,6 @@ import java.io.ObjectOutput;
 import java.util.Arrays;
 import java.util.List;
 
-import org.apache.directory.shared.ldap.model.name.Ava;
 import org.apache.directory.shared.ldap.model.name.Rdn;
 
 
@@ -190,90 +189,51 @@ public class ParentIdAndRdn<ID extends C
         {
             return val;
         }
+
+        StringBuilder sb = new StringBuilder();
+        boolean isFirst = true;
         
-        // Handle the special case where we only have one RDN
-        // But we may have more than one Ava.
-        if ( rdns.length == 1 )
+        for ( Rdn rdn : rdns )
         {
-            Rdn thisRdn = rdns[0];
-            Rdn thatRdn = that.rdns[0];
-            
-            // Check the AVAs now
-            // If we only have one, no need to create an Array
-            if ( thisRdn.size() == 1 )
+            if ( isFirst )
             {
-                if ( thatRdn.size() > 1 )
-                {
-                    return -1;
-                }
-                
-                Ava thisAva = thisRdn.getAva();
-                
-                val = thisAva.compareTo( thatRdn.getAva() );
-                
-                if ( val != 0 )
-                {
-                    return val;
-                }
+                sb.append( ',' );
             }
             else
             {
-                if ( thisRdn.size() > thatRdn.size() )
-                {
-                    return 1;
-                }
-                else if ( thatRdn.size() > thisRdn.size() )
-                {
-                    return -1;
-                }
-                
-                Ava[] thisAvas = new Ava[thisRdn.size()];
-                int pos = 0;
-                
-                for ( Ava ava : thisRdn )
-                {
-                    thisAvas[pos++] = ava;
-                }
-                
-                Arrays.sort( thisAvas );
-
-                Ava[] thatAvas = new Ava[thatRdn.size()];
-                pos = 0;
-                
-                for ( Ava ava : thatRdn )
-                {
-                    thatAvas[pos++] = ava;
-                }
-                
-                Arrays.sort( thatAvas );
-                
-                for ( int i = 0; i < thisAvas.length; i++ )
-                {
-                    val = thisAvas[i].compareTo( thatAvas[i] );
-
-                    if ( val != 0 )
-                    {
-                        return val;
-                    }
-                }
+                isFirst = false;
             }
+            
+            sb.append( rdn.getNormName() );
         }
-        else
+        
+        String thisString = sb.toString();
+        
+        isFirst = true;
+        sb = new StringBuilder();
+
+        for ( Rdn rdn : that.rdns )
         {
-            // if we have more than one RDN, then it's a context entry.
-            // Atm, do a string comparison
-            for ( int i = 0; i < rdns.length; i++ )
+            if ( isFirst )
             {
-                val = rdns[i].getNormName().compareTo( that.rdns[i].getNormName() );
-                
-                if ( val != 0 )
-                {
-                    return val;
-                }
+                sb.append( ',' );
+            }
+            else
+            {
+                isFirst = false;
             }
+            
+            sb.append( rdn.getNormName() );
         }
         
-        val = this.getParentId().compareTo( that.getParentId() );
+        String thatString = sb.toString();
+        
+        val = ( thisString.compareTo( thatString ) );
+        
+        if ( val == 0 )
+        {
+            val = this.getParentId().compareTo( that.getParentId() );
+        }
 
         return val;
     }

Modified: directory/apacheds/trunk/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/ParentIdAndRdnTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/ParentIdAndRdnTest.java?rev=1301718&r1=1301717&r2=1301718&view=diff
==============================================================================
--- directory/apacheds/trunk/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/ParentIdAndRdnTest.java
(original)
+++ directory/apacheds/trunk/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/ParentIdAndRdnTest.java
Fri Mar 16 19:47:27 2012
@@ -128,7 +128,7 @@ public class ParentIdAndRdnTest
         // Sixth rdn
         assertEquals( 0, rdn6.compareTo( rdn7 ) );
         assertEquals( 0, rdn7.compareTo( rdn6 ) );
-        assertEquals( -1, rdn1.compareTo( rdn6 ) );
-        assertEquals( -1, rdn1.compareTo( rdn7 ) );
+        assertEquals( -14, rdn1.compareTo( rdn6 ) );
+        assertEquals( -14, rdn1.compareTo( rdn7 ) );
     }
 }

Modified: directory/shared/trunk/integ/src/test/java/org/apache/directory/shared/ldap/model/name/RdnTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/integ/src/test/java/org/apache/directory/shared/ldap/model/name/RdnTest.java?rev=1301718&r1=1301717&r2=1301718&view=diff
==============================================================================
--- directory/shared/trunk/integ/src/test/java/org/apache/directory/shared/ldap/model/name/RdnTest.java
(original)
+++ directory/shared/trunk/integ/src/test/java/org/apache/directory/shared/ldap/model/name/RdnTest.java
Fri Mar 16 19:47:27 2012
@@ -158,4 +158,15 @@ public class RdnTest
         
         assertEquals( null, errors );
     }
+    
+    
+    @Test
+    public void testRdnMultipleAvas() throws Exception
+    {
+        Rdn rdn1 = new Rdn( schemaManager, "cn=doe+gn=john" );
+        Rdn rdn2 = new Rdn( schemaManager, "gn=john+cn=doe" );
+        
+        assertEquals( rdn1, rdn2 );
+        assertEquals( rdn1.getNormName(), rdn2.getNormName() );
+    }
 }

Modified: directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/name/Dn.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/name/Dn.java?rev=1301718&r1=1301717&r2=1301718&view=diff
==============================================================================
--- directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/name/Dn.java
(original)
+++ directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/name/Dn.java
Fri Mar 16 19:47:27 2012
@@ -27,9 +27,12 @@ import java.io.ObjectInput;
 import java.io.ObjectOutput;
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
+import java.util.TreeSet;
 
 import org.apache.commons.collections.list.UnmodifiableList;
 import org.apache.directory.shared.i18n.I18n;
@@ -1115,7 +1118,7 @@ public class Dn implements Iterable<Rdn>
 
     /**
      * Transform a Rdn by changing the value to its OID counterpart and
-     * normalizing the value accordingly to its type.
+     * normalizing the value accordingly to its type. We also sort the AVAs
      *
      * @param rdn The Rdn to modify.
      * @param SchemaManager The schema manager
@@ -1128,12 +1131,32 @@ public class Dn implements Iterable<Rdn>
         // ATAVs
         Rdn rdnCopy = rdn.clone();
         rdn.clear();
-
-        for ( Ava val : rdnCopy )
+        
+        if ( rdnCopy.size() < 2 )
         {
-            Ava newAtav = atavOidToName( val, schemaManager );
+            Ava newAtav = atavOidToName( rdnCopy.getAva(), schemaManager );
             rdn.addAVA( schemaManager, newAtav );
         }
+        else
+        {
+            Set<String> sortedOids = new TreeSet<String>();
+            Map<String, Ava> avas = new HashMap<String, Ava>();
+
+            // Sort the OIDs
+            for ( Ava val : rdnCopy )
+            {
+                Ava newAtav = atavOidToName( val, schemaManager );
+                String oid = newAtav.getAttributeType().getOid();
+                sortedOids.add( oid );
+                avas.put( oid, newAtav );
+            }
+            
+            // And create the Rdn
+            for ( String oid : sortedOids )
+            {
+                rdn.addAVA( schemaManager, avas.get( oid ) );
+            }
+        }
     }
 
 



Mime
View raw message