directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r721222 - /directory/shared/branches/shared-mina2/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifRevertor.java
Date Thu, 27 Nov 2008 16:16:50 GMT
Author: elecharny
Date: Thu Nov 27 08:16:49 2008
New Revision: 721222

URL: http://svn.apache.org/viewvc?rev=721222&view=rev
Log:
Last cleaning done on the rename revertor. The method is now just 200 lines long instead of
more than 400 before the cleaning...

Modified:
    directory/shared/branches/shared-mina2/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifRevertor.java

Modified: directory/shared/branches/shared-mina2/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifRevertor.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-mina2/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifRevertor.java?rev=721222&r1=721221&r2=721222&view=diff
==============================================================================
--- directory/shared/branches/shared-mina2/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifRevertor.java
(original)
+++ directory/shared/branches/shared-mina2/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifRevertor.java
Thu Nov 27 08:16:49 2008
@@ -322,8 +322,15 @@
     /**
      * A helper method to generate the modified attribute after a rename.
      */
-    private static LdifEntry generateModify( LdifEntry restored, Entry entry, Rdn oldRdn,
Rdn newRdn )
+    private static LdifEntry generateModify( LdapDN parentDn, Entry entry, Rdn oldRdn, Rdn
newRdn )
     {
+        LdifEntry restored = new LdifEntry();
+        restored.setChangeType( ChangeType.Modify );
+        
+        // We have to use the parent DN, the entry has already
+        // been renamed
+        restored.setDn( parentDn );
+
         for ( AttributeTypeAndValue ava:newRdn )
         {
             // No need to add something which has already been added
@@ -346,6 +353,23 @@
     
     
     /**
+     * A helper method which generates a reverted entry
+     */
+    private static LdifEntry generateReverted( LdapDN newDn, Rdn oldRdn, boolean deleteOldRdn
)
+    {
+        LdifEntry reverted = new LdifEntry();
+        reverted.setChangeType( ChangeType.ModRdn );
+        reverted.setDn( newDn );
+        reverted.setNewRdn( oldRdn.getUpName() );
+        
+        // Delete the newRDN values
+        reverted.setDeleteOldRdn( deleteOldRdn );
+        
+        return reverted;
+    }
+    
+    
+    /**
      * Revert a DN to it's previous version by removing the first RDN and adding the given
RDN.
      * It's a rename operation. The biggest issue is that we have many corner cases, depending

      * on the RDNs we are manipulating, and on the content of the initial entry.
@@ -456,23 +480,12 @@
                         // Some of the new RDN AVAs existed in the entry
                         // We have to restore them, but we also have to remove
                         // the new values
-                        reverted.setChangeType( ChangeType.ModRdn );
-                        reverted.setDn( newDn );
-                        reverted.setNewRdn( oldRdn.getUpName() );
-                        
-                        // Delete the newRDN values
-                        reverted.setDeleteOldRdn( KEEP_OLD_RDN );
+                        reverted = generateReverted( newDn, oldRdn, KEEP_OLD_RDN );
                         
                         entries.add( reverted );
                         
                         // Now, restore the initial values
-                        LdifEntry restored = new LdifEntry();
-                        restored.setChangeType( ChangeType.Modify );
-                        
-                        // We have to use the parent DN, the entry has already
-                        // been renamed
-                        restored.setDn( parentDn );
-                        restored = generateModify( restored, entry, oldRdn, newRdn );
+                        LdifEntry restored = generateModify( parentDn, entry, oldRdn, newRdn
);
                         
                         entries.add( restored );
                     }
@@ -480,12 +493,7 @@
                     {
                         // This is the simplest case, we don't have to restore
                         // some existing values (case 8.1 and 9.1)
-                        reverted.setChangeType( ChangeType.ModRdn );
-                        reverted.setDn( newDn );
-                        reverted.setNewRdn( oldRdn.getUpName() );
-                        
-                        // Delete the newRDN values
-                        reverted.setDeleteOldRdn( DELETE_OLD_RDN );
+                        reverted = generateReverted( newDn, oldRdn, DELETE_OLD_RDN );
                         
                         entries.add( reverted );
                     }
@@ -497,34 +505,18 @@
                         // Some of the new RDN AVAs existed in the entry
                         // We have to restore them, but we also have to remove
                         // the new values
-                        reverted.setChangeType( ChangeType.ModRdn );
-                        reverted.setDn( newDn );
-                        reverted.setNewRdn( oldRdn.getUpName() );
-                        
-                        // Delete the newRDN values
-                        reverted.setDeleteOldRdn( KEEP_OLD_RDN );
+                        reverted = generateReverted( newDn, oldRdn, KEEP_OLD_RDN );
                         
                         entries.add( reverted );
                         
-                        // Now, restore the initial values
-                        LdifEntry restored = new LdifEntry();
-                        restored.setChangeType( ChangeType.Modify );
-                        
-                        // We have to use the parent DN, the entry has already
-                        // been renamed
-                        restored.setDn( parentDn );
-                        restored = generateModify( restored, entry, oldRdn, newRdn );
+                        LdifEntry restored = generateModify( parentDn, entry, oldRdn, newRdn
);
                         
                         entries.add( restored );
                     }
                     else
                     {
                         // A much simpler case, as we just have to remove the newRDN
-                        reverted.setChangeType( ChangeType.ModRdn );
-                        reverted.setDn( newDn );
-                        reverted.setNewRdn( oldRdn.getUpName() );
-
-                        reverted.setDeleteOldRdn( DELETE_OLD_RDN );
+                        reverted = generateReverted( newDn, oldRdn, DELETE_OLD_RDN );
 
                         entries.add( reverted );
                     }
@@ -566,11 +558,7 @@
                     {
                         // In this case, we have to reestablish the removed ATAVs
                         // (Cases 12.2 and 13.2)
-                        reverted.setChangeType( ChangeType.ModRdn );
-                        reverted.setDn( newDn );
-                        reverted.setNewRdn( oldRdn.getUpName() );
-    
-                        reverted.setDeleteOldRdn( KEEP_OLD_RDN );
+                        reverted = generateReverted( newDn, oldRdn, KEEP_OLD_RDN );
     
                         entries.add( reverted );
                     }
@@ -579,11 +567,7 @@
                         // We can simply remove all the new RDN atavs, as the
                         // overlapping values will be re-created.
                         // (Cases 12.1 and 13.1)
-                        reverted.setChangeType( ChangeType.ModRdn );
-                        reverted.setDn( newDn );
-                        reverted.setNewRdn( oldRdn.getUpName() );
-    
-                        reverted.setDeleteOldRdn( DELETE_OLD_RDN );
+                        reverted = generateReverted( newDn, oldRdn, DELETE_OLD_RDN );
     
                         entries.add( reverted );
                     }
@@ -595,22 +579,11 @@
                     {
                         // In this case, we have to reestablish the removed ATAVs
                         // (Cases 10.2 and 11.2)
-                        reverted.setChangeType( ChangeType.ModRdn );
-                        reverted.setDn( newDn );
-                        reverted.setNewRdn( oldRdn.getUpName() );
-    
-                        reverted.setDeleteOldRdn( KEEP_OLD_RDN );
+                        reverted = generateReverted( newDn, oldRdn, KEEP_OLD_RDN );
     
                         entries.add( reverted );
                         
-                        // Now, restore the initial values
-                        LdifEntry restored = new LdifEntry();
-                        restored.setChangeType( ChangeType.Modify );
-                        
-                        // We have to use the parent DN, the entry has already
-                        // been renamed
-                        restored.setDn( parentDn );
-                        restored = generateModify( restored, entry, oldRdn, newRdn );
+                        LdifEntry restored = generateModify( parentDn, entry, oldRdn, newRdn
);
                         
                         entries.add( restored );
                     }
@@ -618,11 +591,7 @@
                     {
                         // We are safe ! We can delete all the new Rdn ATAVs
                         // (Cases 10.1 and 11.1)
-                        reverted.setChangeType( ChangeType.ModRdn );
-                        reverted.setDn( newDn );
-                        reverted.setNewRdn( oldRdn.getUpName() );
-    
-                        reverted.setDeleteOldRdn( DELETE_OLD_RDN );
+                        reverted = generateReverted( newDn, oldRdn, DELETE_OLD_RDN );
     
                         entries.add( reverted );
                     }



Mime
View raw message