directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kayyag...@apache.org
Subject svn commit: r999582 - /directory/apacheds/trunk/ldif-partition/src/main/java/org/apache/directory/server/core/partition/ldif/SingleFileLdifPartition.java
Date Tue, 21 Sep 2010 19:59:03 GMT
Author: kayyagari
Date: Tue Sep 21 19:59:02 2010
New Revision: 999582

URL: http://svn.apache.org/viewvc?rev=999582&view=rev
Log:
o implemented delete operation

Modified:
    directory/apacheds/trunk/ldif-partition/src/main/java/org/apache/directory/server/core/partition/ldif/SingleFileLdifPartition.java

Modified: directory/apacheds/trunk/ldif-partition/src/main/java/org/apache/directory/server/core/partition/ldif/SingleFileLdifPartition.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/ldif-partition/src/main/java/org/apache/directory/server/core/partition/ldif/SingleFileLdifPartition.java?rev=999582&r1=999581&r2=999582&view=diff
==============================================================================
--- directory/apacheds/trunk/ldif-partition/src/main/java/org/apache/directory/server/core/partition/ldif/SingleFileLdifPartition.java
(original)
+++ directory/apacheds/trunk/ldif-partition/src/main/java/org/apache/directory/server/core/partition/ldif/SingleFileLdifPartition.java
Tue Sep 21 19:59:02 2010
@@ -355,9 +355,54 @@ public class SingleFileLdifPartition ext
 
 
     @Override
-    public void delete( Long id ) throws LdapException
+    public synchronized void delete( Long id ) throws LdapException
     {
         wrappedPartition.delete( id );
+
+        try
+        {
+            EntryOffset entryOffset = offsetMap.get( id );
+
+            // check if the entry to be removed is present at the end of file
+            if ( entryOffset.getEnd() == ldifFile.length() )
+            {
+                ldifFile.setLength( entryOffset.getStart() );
+                // check if entry is the context entry
+                if ( entryOffset.getStart() == 0 )
+                {
+                    contextEntry = null;
+                }
+            }
+            else
+            {
+                FileChannel tmpBufChannel = tempBufFile.getChannel();
+                FileChannel mainChannel = ldifFile.getChannel();
+
+                // clear the buffer
+                tempBufFile.setLength( 0 );
+
+                long count = ( ldifFile.length() - entryOffset.getEnd() );
+
+                mainChannel.transferTo( entryOffset.getEnd(), count, tmpBufChannel );
+                ldifFile.setLength( entryOffset.getStart() );
+
+                Set<EntryOffset> belowParentOffsets = greaterThan( entryOffset );
+
+                long diff = entryOffset.length();
+                diff -= (2 * diff); // this offset change should always be negative
+                
+                for ( EntryOffset o : belowParentOffsets )
+                {
+                    o.changeOffsetsBy( diff );
+                }
+
+                tmpBufChannel.transferTo( 0, tmpBufChannel.size(), mainChannel );
+            }
+        }
+        catch( IOException e )
+        {
+            throw new LdapException( e );
+        }
     }
 
 
@@ -379,7 +424,7 @@ public class SingleFileLdifPartition ext
                 return e;
             }
         }
-        
+
         // if non exists
         return null;
     }
@@ -458,7 +503,7 @@ public class SingleFileLdifPartition ext
                 // erase file
                 ldifFile.setLength( 0 );
             }
-            
+
             ldifFile.seek( pos );
 
             ldifFile.write( StringTools.getBytesUtf8( ldif + "\n" ) );



Mime
View raw message