directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kayyag...@apache.org
Subject svn commit: r816870 - in /directory/apacheds/branches/apacheds-schema/ldif-partition/src: main/java/org/apache/directory/server/core/partition/ldif/LdifPartition.java test/java/org/apache/directory/server/core/partition/LdifPartitionTest.java
Date Sat, 19 Sep 2009 08:41:17 GMT
Author: kayyagari
Date: Sat Sep 19 08:41:16 2009
New Revision: 816870

URL: http://svn.apache.org/viewvc?rev=816870&view=rev
Log:
o updated the entryMoved() method to handle rename and moveAndRename operations
o added test cases for rename and moveAndRename operations

Modified:
    directory/apacheds/branches/apacheds-schema/ldif-partition/src/main/java/org/apache/directory/server/core/partition/ldif/LdifPartition.java
    directory/apacheds/branches/apacheds-schema/ldif-partition/src/test/java/org/apache/directory/server/core/partition/LdifPartitionTest.java

Modified: directory/apacheds/branches/apacheds-schema/ldif-partition/src/main/java/org/apache/directory/server/core/partition/ldif/LdifPartition.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-schema/ldif-partition/src/main/java/org/apache/directory/server/core/partition/ldif/LdifPartition.java?rev=816870&r1=816869&r2=816870&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-schema/ldif-partition/src/main/java/org/apache/directory/server/core/partition/ldif/LdifPartition.java
(original)
+++ directory/apacheds/branches/apacheds-schema/ldif-partition/src/main/java/org/apache/directory/server/core/partition/ldif/LdifPartition.java
Sat Sep 19 08:41:16 2009
@@ -343,7 +343,7 @@
 
         wrappedPartition.move( moveContext );
 
-        entryMoved( oldDn, id );
+        entryMoved( oldDn, id, true );
     }
 
 
@@ -358,7 +358,7 @@
 
         wrappedPartition.moveAndRename( moveAndRenameContext );
 
-        entryMoved( oldDn, id );
+        entryMoved( oldDn, id, moveAndRenameContext.getDelOldDn() );
     }
 
 
@@ -373,7 +373,7 @@
 
         wrappedPartition.rename( renameContext );
 
-        entryMoved( oldDn, id );
+        entryMoved( oldDn, id, renameContext.getDelOldDn() );
     }
 
 
@@ -384,9 +384,10 @@
      *
      * @param oldEntryDn the moved entry's old DN
      * @param entryId the moved entry's master table ID
+     * @param deleteOldEntry a flag to tell whether to delete the old entry files
      * @throws Exception
      */
-    private void entryMoved( LdapDN oldEntryDn, Long entryId ) throws Exception
+    private void entryMoved( LdapDN oldEntryDn, Long entryId, boolean deleteOldEntry ) throws
Exception
     {
         // First, add the new entry
         add( lookup( entryId ) );
@@ -407,16 +408,19 @@
 
         cursor.close();
         
-        // And delete the old entry's LDIF file
-        File file = getFile( oldEntryDn, DELETE );
-        boolean deleted = deleteFile( file );
-        LOG.warn( "move operation: deleted file {} {}", file.getAbsoluteFile(), deleted );
-        
-        // and the associated directory
-        String dirName = file.getAbsolutePath();
-        dirName = dirName.substring( 0, dirName.indexOf( CONF_FILE_EXTN ) );
-        deleted = deleteFile( new File(  dirName ) );
-        LOG.warn( "move operation: deleted dir {} {}", dirName, deleted );
+        if( deleteOldEntry )
+        {
+            // And delete the old entry's LDIF file
+            File file = getFile( oldEntryDn, DELETE );
+            boolean deleted = deleteFile( file );
+            LOG.warn( "move operation: deleted file {} {}", file.getAbsoluteFile(), deleted
);
+            
+            // and the associated directory
+            String dirName = file.getAbsolutePath();
+            dirName = dirName.substring( 0, dirName.indexOf( CONF_FILE_EXTN ) );
+            deleted = deleteFile( new File(  dirName ) );
+            LOG.warn( "move operation: deleted dir {} {}", dirName, deleted );
+        }
     }
 
 

Modified: directory/apacheds/branches/apacheds-schema/ldif-partition/src/test/java/org/apache/directory/server/core/partition/LdifPartitionTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-schema/ldif-partition/src/test/java/org/apache/directory/server/core/partition/LdifPartitionTest.java?rev=816870&r1=816869&r2=816870&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-schema/ldif-partition/src/test/java/org/apache/directory/server/core/partition/LdifPartitionTest.java
(original)
+++ directory/apacheds/branches/apacheds-schema/ldif-partition/src/test/java/org/apache/directory/server/core/partition/LdifPartitionTest.java
Sat Sep 19 08:41:16 2009
@@ -44,7 +44,9 @@
 import org.apache.directory.server.core.filtering.EntryFilteringCursor;
 import org.apache.directory.server.core.interceptor.context.AddOperationContext;
 import org.apache.directory.server.core.interceptor.context.DeleteOperationContext;
+import org.apache.directory.server.core.interceptor.context.MoveAndRenameOperationContext;
 import org.apache.directory.server.core.interceptor.context.MoveOperationContext;
+import org.apache.directory.server.core.interceptor.context.RenameOperationContext;
 import org.apache.directory.server.core.interceptor.context.SearchOperationContext;
 import org.apache.directory.server.core.partition.ldif.LdifPartition;
 import org.apache.directory.shared.ldap.constants.AuthenticationLevel;
@@ -55,6 +57,7 @@
 import org.apache.directory.shared.ldap.filter.FilterParser;
 import org.apache.directory.shared.ldap.filter.SearchScope;
 import org.apache.directory.shared.ldap.name.LdapDN;
+import org.apache.directory.shared.ldap.name.Rdn;
 import org.apache.directory.shared.ldap.schema.SchemaUtils;
 import org.apache.directory.shared.ldap.schema.ldif.extractor.SchemaLdifExtractor;
 import org.apache.directory.shared.ldap.schema.registries.Registries;
@@ -417,6 +420,116 @@
     }
 
     
+    @Test
+    public void testLdifRenameAndDeleteOldDN() throws Exception
+    {
+        CoreSession session = injectEntries();
+
+        LdapDN childDn1 = new LdapDN( "dc=child1,ou=test,ou=system" );
+        childDn1.normalize( registries.getAttributeTypeRegistry().getNormalizerMapping()
);
+        
+        Rdn newRdn = new Rdn( SchemaConstants.DC_AT + "=" + "renamedChild1" );
+        RenameOperationContext renameOpCtx = new RenameOperationContext( session, childDn1,
newRdn, true );
+        partition.rename( renameOpCtx );
+        
+        assertFalse( new File( wkdir, "ou=test,ou=system/dc=child1" ).exists() );
+        assertFalse( new File( wkdir, "ou=test,ou=system/dc=child1.ldif" ).exists() );
+
+        assertTrue( new File( wkdir, "ou=test,ou=system/dc=renamedchild1" ).exists() );
+        assertTrue( new File( wkdir, "ou=test,ou=system/dc=renamedchild1.ldif" ).exists()
);
+        assertTrue( new File( wkdir, "ou=test,ou=system/dc=renamedchild1/dc=grandchild11"
).exists() );
+        assertTrue( new File( wkdir, "ou=test,ou=system/dc=renamedchild1/dc=grandchild11.ldif"
).exists() );
+        assertFalse( new File( wkdir, "ou=test,ou=system/dc=renamedchild1/dc=grandchild12"
).exists() );
+        assertTrue( new File( wkdir, "ou=test,ou=system/dc=renamedchild1/dc=grandchild12.ldif"
).exists() );
+        assertFalse( new File( wkdir, "ou=test,ou=system/dc=renamedchild1/dc=grandchild11/dc=greatgrandchild111"
).exists() );
+        assertTrue( new File( wkdir, "ou=test,ou=system/dc=renamedchild1/dc=grandchild11/dc=greatgrandchild111.ldif"
).exists() );
+    }
+
+    
+    @Test
+    public void testLdifRenameAndRetainOldDN() throws Exception
+    {
+        CoreSession session = injectEntries();
+
+        LdapDN childDn1 = new LdapDN( "dc=child1,ou=test,ou=system" );
+        childDn1.normalize( registries.getAttributeTypeRegistry().getNormalizerMapping()
);
+        
+        Rdn newRdn = new Rdn( SchemaConstants.DC_AT + "=" + "renamedChild1" );
+        RenameOperationContext renameOpCtx = new RenameOperationContext( session, childDn1,
newRdn, false );
+        partition.rename( renameOpCtx );
+        
+        assertTrue( new File( wkdir, "ou=test,ou=system/dc=child1" ).exists() );
+        assertTrue( new File( wkdir, "ou=test,ou=system/dc=child1.ldif" ).exists() );
+
+        assertTrue( new File( wkdir, "ou=test,ou=system/dc=renamedchild1" ).exists() );
+        assertTrue( new File( wkdir, "ou=test,ou=system/dc=renamedchild1.ldif" ).exists()
);
+        assertTrue( new File( wkdir, "ou=test,ou=system/dc=renamedchild1/dc=grandchild11"
).exists() );
+        assertTrue( new File( wkdir, "ou=test,ou=system/dc=renamedchild1/dc=grandchild11.ldif"
).exists() );
+        assertFalse( new File( wkdir, "ou=test,ou=system/dc=renamedchild1/dc=grandchild12"
).exists() );
+        assertTrue( new File( wkdir, "ou=test,ou=system/dc=renamedchild1/dc=grandchild12.ldif"
).exists() );
+        assertFalse( new File( wkdir, "ou=test,ou=system/dc=renamedchild1/dc=grandchild11/dc=greatgrandchild111"
).exists() );
+        assertTrue( new File( wkdir, "ou=test,ou=system/dc=renamedchild1/dc=grandchild11/dc=greatgrandchild111.ldif"
).exists() );
+    }
+
+    
+    @Test
+    public void testLdifMoveAndRenameWithDeletingOldDN() throws Exception
+    {
+        CoreSession session = injectEntries();
+
+        LdapDN childDn1 = new LdapDN( "dc=child1,ou=test,ou=system" );
+        childDn1.normalize( registries.getAttributeTypeRegistry().getNormalizerMapping()
);
+
+        LdapDN childDn2 = new LdapDN( "dc=child2,ou=test,ou=system" );
+        childDn2.normalize( registries.getAttributeTypeRegistry().getNormalizerMapping()
);
+
+        Rdn newRdn = new Rdn( SchemaConstants.DC_AT + "=" + "movedChild1" );
+        MoveAndRenameOperationContext moveAndRenameOpCtx = new MoveAndRenameOperationContext(
session, childDn1, childDn2, newRdn, true );
+        partition.moveAndRename( moveAndRenameOpCtx );
+        
+        assertFalse( new File( wkdir, "ou=test,ou=system/dc=child1" ).exists() );
+        assertFalse( new File( wkdir, "ou=test,ou=system/dc=child1.ldif" ).exists() );
+
+        assertTrue( new File( wkdir, "ou=test,ou=system/dc=child2/dc=movedchild1" ).exists()
);
+        assertTrue( new File( wkdir, "ou=test,ou=system/dc=child2/dc=movedchild1.ldif" ).exists()
);
+        assertTrue( new File( wkdir, "ou=test,ou=system/dc=child2/dc=movedchild1/dc=grandchild11"
).exists() );
+        assertTrue( new File( wkdir, "ou=test,ou=system/dc=child2/dc=movedchild1/dc=grandchild11.ldif"
).exists() );
+        assertFalse( new File( wkdir, "ou=test,ou=system/dc=child2/dc=movedchild1/dc=grandchild12"
).exists() );
+        assertTrue( new File( wkdir, "ou=test,ou=system/dc=child2/dc=movedchild1/dc=grandchild12.ldif"
).exists() );
+        assertFalse( new File( wkdir, "ou=test,ou=system/dc=child2/dc=movedchild1/dc=grandchild11/dc=greatgrandchild111"
).exists() );
+        assertTrue( new File( wkdir, "ou=test,ou=system/dc=child2/dc=movedchild1/dc=grandchild11/dc=greatgrandchild111.ldif"
).exists() );
+    }
+
+    
+    @Test
+    public void testLdifMoveAndRenameRetainingOldDN() throws Exception
+    {
+        CoreSession session = injectEntries();
+
+        LdapDN childDn1 = new LdapDN( "dc=child1,ou=test,ou=system" );
+        childDn1.normalize( registries.getAttributeTypeRegistry().getNormalizerMapping()
);
+
+        LdapDN childDn2 = new LdapDN( "dc=child2,ou=test,ou=system" );
+        childDn2.normalize( registries.getAttributeTypeRegistry().getNormalizerMapping()
);
+
+        Rdn newRdn = new Rdn( SchemaConstants.DC_AT + "=" + "movedChild1" );
+        MoveAndRenameOperationContext moveAndRenameOpCtx = new MoveAndRenameOperationContext(
session, childDn1, childDn2, newRdn, false );
+        partition.moveAndRename( moveAndRenameOpCtx );
+        
+        assertTrue( new File( wkdir, "ou=test,ou=system/dc=child1" ).exists() );
+        assertTrue( new File( wkdir, "ou=test,ou=system/dc=child1.ldif" ).exists() );
+
+        assertTrue( new File( wkdir, "ou=test,ou=system/dc=child2/dc=movedchild1" ).exists()
);
+        assertTrue( new File( wkdir, "ou=test,ou=system/dc=child2/dc=movedchild1.ldif" ).exists()
);
+        assertTrue( new File( wkdir, "ou=test,ou=system/dc=child2/dc=movedchild1/dc=grandchild11"
).exists() );
+        assertTrue( new File( wkdir, "ou=test,ou=system/dc=child2/dc=movedchild1/dc=grandchild11.ldif"
).exists() );
+        assertFalse( new File( wkdir, "ou=test,ou=system/dc=child2/dc=movedchild1/dc=grandchild12"
).exists() );
+        assertTrue( new File( wkdir, "ou=test,ou=system/dc=child2/dc=movedchild1/dc=grandchild12.ldif"
).exists() );
+        assertFalse( new File( wkdir, "ou=test,ou=system/dc=child2/dc=movedchild1/dc=grandchild11/dc=greatgrandchild111"
).exists() );
+        assertTrue( new File( wkdir, "ou=test,ou=system/dc=child2/dc=movedchild1/dc=grandchild11/dc=greatgrandchild111.ldif"
).exists() );
+    }
+
+    
     private CoreSession injectEntries() throws Exception
     {
         LdapDN adminDn = new LdapDN( "uid=admin,ou=system" ).normalize( registries.getAttributeTypeRegistry().getNormalizerMapping()
);



Mime
View raw message