directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1175950 - in /directory/apacheds/trunk/jdbm/src/main/java/jdbm: btree/BPage.java recman/BaseRecordManager.java recman/PhysicalRowIdManager.java recman/SnapshotRecordManager.java
Date Mon, 26 Sep 2011 16:51:25 GMT
Author: elecharny
Date: Mon Sep 26 16:51:25 2011
New Revision: 1175950

URL: http://svn.apache.org/viewvc?rev=1175950&view=rev
Log:
o Added some Javadoc
o Minor refactoring (mainly java cleanup and style correction)

Modified:
    directory/apacheds/trunk/jdbm/src/main/java/jdbm/btree/BPage.java
    directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/BaseRecordManager.java
    directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/PhysicalRowIdManager.java
    directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/SnapshotRecordManager.java

Modified: directory/apacheds/trunk/jdbm/src/main/java/jdbm/btree/BPage.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/jdbm/src/main/java/jdbm/btree/BPage.java?rev=1175950&r1=1175949&r2=1175950&view=diff
==============================================================================
--- directory/apacheds/trunk/jdbm/src/main/java/jdbm/btree/BPage.java (original)
+++ directory/apacheds/trunk/jdbm/src/main/java/jdbm/btree/BPage.java Mon Sep 26 16:51:25
2011
@@ -67,7 +67,7 @@ import org.apache.directory.server.i18n.
 /**
  * Page of a Btree.
  * <p>
- * The page contains a number of key-value pairs.  Keys are ordered to allow
+ * The page contains a number of key-value pairs. Keys are ordered to allow
  * dichotomic search.
  * <p>
  * If the page is a leaf page, the keys and values are user-defined and

Modified: directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/BaseRecordManager.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/BaseRecordManager.java?rev=1175950&r1=1175949&r2=1175950&view=diff
==============================================================================
--- directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/BaseRecordManager.java (original)
+++ directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/BaseRecordManager.java Mon Sep
26 16:51:25 2011
@@ -61,6 +61,8 @@ import jdbm.helper.DefaultSerializer;
 import jdbm.helper.Serializer;
 
 import org.apache.directory.server.i18n.I18n;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  *  This class manages records, which are uninterpreted blobs of data. The
@@ -86,6 +88,9 @@ import org.apache.directory.server.i18n.
  */
 public final class BaseRecordManager implements RecordManager
 {
+    /** A logger for this class */
+    private static final Logger LOG = LoggerFactory.getLogger( BaseRecordManager.class.getSimpleName()
);
+    
     /** Underlying record recordFile. */
     private RecordFile recordFile;
 
@@ -230,6 +235,7 @@ public final class BaseRecordManager imp
     public TransactionManager getTransactionManager() throws IOException
     {
         checkIfClosed();
+        
         return recordFile.getTxnMgr();
     }
 
@@ -300,10 +306,7 @@ public final class BaseRecordManager imp
         physRowId = physMgr.insert( data, 0, data.length );
         recid = logMgr.insert( physRowId ).toLong();
      
-        if ( DEBUG ) 
-        {
-            System.out.println( "BaseRecordManager.insert() recid " + recid + " length "
+ data.length ) ;
-        }
+        LOG.debug( "BaseRecordManager.insert() recid {} length {}", recid, data.length )
;
         
         return recid;
     }
@@ -325,13 +328,10 @@ public final class BaseRecordManager imp
             throw new IllegalArgumentException( I18n.err( I18n.ERR_536, recid ) );
         }
 
-        if ( DEBUG ) 
-        {
-            System.out.println( "BaseRecordManager.delete() recid " + recid ) ;
-        }
+        LOG.debug( "BaseRecordManager.delete() recid {}", recid ) ;
 
         
-        element = this.beginIO(recid, IOType.WRITE_IO);
+        element = beginIO( recid, IOType.WRITE_IO );
         
         try
         {
@@ -342,7 +342,7 @@ public final class BaseRecordManager imp
         }
         finally
         {
-            this.endIO(recid, element, IOType.WRITE_IO);
+            this.endIO( recid, element, IOType.WRITE_IO );
         }
     }
 
@@ -379,7 +379,7 @@ public final class BaseRecordManager imp
             throw new IllegalArgumentException( I18n.err( I18n.ERR_536, recid ) );
         }
 
-        element = this.beginIO(recid, IOType.WRITE_IO);
+        element = this.beginIO( recid, IOType.WRITE_IO );
          
         try
         {
@@ -388,10 +388,7 @@ public final class BaseRecordManager imp
 
             byte[] data = serializer.serialize( obj );
             
-            if ( DEBUG ) 
-            {
-                System.out.println( "BaseRecordManager.update() recid " + recid + " length
" + data.length ) ;
-            }
+            LOG.debug( "BaseRecordManager.update() recid {} length {}", recid, data.length
) ;
             
             Location newRecid = physMgr.update( physRecid, data, 0, data.length );
             
@@ -402,7 +399,7 @@ public final class BaseRecordManager imp
          }
          finally
          {
-             this.endIO(recid, element, IOType.WRITE_IO);
+             endIO( recid, element, IOType.WRITE_IO );
          } 
     }
     
@@ -446,21 +443,18 @@ public final class BaseRecordManager imp
         {
             byte[] data; 
             
-            data = physMgr.fetch( logMgr.fetch( new Location( recid ) ) );
+            Location location = logMgr.fetch( new Location( recid ) ) ;
+            data = physMgr.fetch( location );
             
-            if ( DEBUG ) 
-            {
-                System.out.println( "BaseRecordManager.fetch() recid " + recid + " length
" + data.length ) ;
-            }
+            LOG.debug( "BaseRecordManager.fetch() recid {} length {}", recid, data.length
) ;
             
             result = serializer.deserialize( data );
         }
         finally
         {
-            this.endIO(recid, element, IOType.READ_IO);
+            endIO(recid, element, IOType.READ_IO);
         }
         
-        
         return result;
     }
 

Modified: directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/PhysicalRowIdManager.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/PhysicalRowIdManager.java?rev=1175950&r1=1175949&r2=1175950&view=diff
==============================================================================
--- directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/PhysicalRowIdManager.java (original)
+++ directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/PhysicalRowIdManager.java Mon
Sep 26 16:51:25 2011
@@ -55,28 +55,37 @@ import java.io.IOException;
  */
 final class PhysicalRowIdManager
 {
-    // The file we're talking to and the associated page manager.
+    /** The file we're talking to and the associated page manager. */
     private RecordFile file;
+    
+    /** The page manager */
     private PageManager pageManager;
-    private FreePhysicalRowIdPageManager freeman;
+    
+    /** The FreePage manager */
+    private FreePhysicalRowIdPageManager freePageManager;
 
     /**
      *  Creates a new rowid manager using the indicated record file.
      *  and page manager.
+     *  @throws IOException If we had an issue while creating the file
      */
     PhysicalRowIdManager( PageManager pageManager ) throws IOException
     {
         this.pageManager = pageManager;
-        this.file = pageManager.getRecordFile();
-        this.freeman = new FreePhysicalRowIdPageManager( pageManager );
+        file = pageManager.getRecordFile();
+        freePageManager = new FreePhysicalRowIdPageManager( pageManager );
     }
+    
 
     /**
      *  Inserts a new record. Returns the new physical rowid.
      */
     Location insert( byte[] data, int start, int length ) throws IOException
     {
+        // Find the location for the added data
         Location retval = alloc( length );
+        
+        // And write it
         write( retval, data, start, length );
         
         return retval;
@@ -181,7 +190,7 @@ final class PhysicalRowIdManager
      */
     private Location alloc( int size ) throws IOException
     {
-        Location retval = freeman.get( size );
+        Location retval = freePageManager.get( size );
         
         if ( retval == null ) 
         {
@@ -323,7 +332,7 @@ final class PhysicalRowIdManager
         file.release( id.getBlock(), true );
 
         // write the rowid to the free list
-        freeman.put( id, hdr.getAvailableSize() );
+        freePageManager.put( id, hdr.getAvailableSize() );
     }
     
 
@@ -342,6 +351,7 @@ final class PhysicalRowIdManager
         if ( length == 0 ) 
         {
             file.release( curs.getBlockId(), true );
+            
             return;
         }
 
@@ -355,11 +365,12 @@ final class PhysicalRowIdManager
             // copy current page's data to return buffer
             int toCopy = RecordFile.BLOCK_SIZE - dataOffset;
 
-            if ( leftToWrite < toCopy ) {
+            if ( leftToWrite < toCopy ) 
+            {
                 toCopy = leftToWrite;
             }
-            System.arraycopy( data, offsetInBuffer, block.getData(), 
-                              dataOffset, toCopy );
+            
+            System.arraycopy( data, offsetInBuffer, block.getData(), dataOffset, toCopy );
 
             // Go to the next block
             leftToWrite -= toCopy;

Modified: directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/SnapshotRecordManager.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/SnapshotRecordManager.java?rev=1175950&r1=1175949&r2=1175950&view=diff
==============================================================================
--- directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/SnapshotRecordManager.java (original)
+++ directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/SnapshotRecordManager.java Mon
Sep 26 16:51:25 2011
@@ -47,16 +47,16 @@ public class SnapshotRecordManager imple
     /** Wrapped RecordManager */
     protected RecordManager recordManager;
     
-    
     /** Per thread action context */
     private static final ThreadLocal < ActionContext > actionContextVar = 
-         new ThreadLocal < ActionContext > () {
+         new ThreadLocal < ActionContext > () 
+         {
              @Override 
              protected ActionContext initialValue()
              {
                  return null;
              }
-     };
+        };
      
     /** Used for keeping track of actions versions */
     ActionVersioning versioning = new ActionVersioning();
@@ -107,7 +107,7 @@ public class SnapshotRecordManager imple
          }
          
          actionContext.beginAction( readOnly, version, whoStarted );
-         this.setCurrentActionContext( actionContext );
+         setCurrentActionContext( actionContext );
          
          return actionContext;
      }
@@ -158,7 +158,7 @@ public class SnapshotRecordManager imple
              assert( false );
          }
          
-         this.unsetCurrentActionContext( actionContext );
+         unsetCurrentActionContext( actionContext );
          
          if ( minVersion != null )
          {
@@ -199,7 +199,7 @@ public class SnapshotRecordManager imple
              assert( false );
          }
          
-         this.unsetCurrentActionContext( actionContext );
+         unsetCurrentActionContext( actionContext );
          
          if ( minVersion != null )
          {
@@ -250,7 +250,7 @@ public class SnapshotRecordManager imple
         
         if ( actionContext == null )
         {
-            actionContext = this.beginAction( false, "insert missing action" );
+            actionContext = beginAction( false, "insert missing action" );
             startedAction = true;
         }
         
@@ -267,7 +267,7 @@ public class SnapshotRecordManager imple
         {
             if ( startedAction )
             {
-                this.abortAction( actionContext );
+                abortAction( actionContext );
                 abortedAction = true;
             }
             
@@ -277,7 +277,7 @@ public class SnapshotRecordManager imple
         {
             if ( startedAction )
             {
-                this.abortAction( actionContext );
+                abortAction( actionContext );
                 abortedAction = true;
             }
             
@@ -287,7 +287,7 @@ public class SnapshotRecordManager imple
         {
             if ( startedAction && !abortedAction )
             {
-                this.endAction ( actionContext );
+                endAction( actionContext );
             }
         }
         
@@ -311,7 +311,7 @@ public class SnapshotRecordManager imple
         
         if ( actionContext == null )
         {
-            actionContext = this.beginAction( false, "delete missing action" );
+            actionContext = beginAction( false, "delete missing action" );
             startedAction = true;
         }
         
@@ -325,7 +325,7 @@ public class SnapshotRecordManager imple
         {
             if ( startedAction )
             {
-                this.abortAction( actionContext );
+                abortAction( actionContext );
                 abortedAction = true;
             }
             
@@ -335,17 +335,17 @@ public class SnapshotRecordManager imple
         {
             if ( startedAction )
             {
-                this.abortAction( actionContext );
+                abortAction( actionContext );
                 abortedAction = true;
             }
             
             throw new IOException( except.getLocalizedMessage() );
-        }       
+        }
         finally
         {
             if ( startedAction && !abortedAction )
             {
-                this.endAction ( actionContext );
+                endAction( actionContext );
             }
         }
     }
@@ -381,7 +381,7 @@ public class SnapshotRecordManager imple
         
         if ( actionContext == null )
         {
-            actionContext = this.beginAction( false, "update missing action" );
+            actionContext = beginAction( false, "update missing action" );
             startedAction = true;
         }
 
@@ -394,7 +394,7 @@ public class SnapshotRecordManager imple
         {
             if ( startedAction )
             {
-                this.abortAction( actionContext );
+                abortAction( actionContext );
                 abortedAction = true;
             }
             
@@ -404,7 +404,7 @@ public class SnapshotRecordManager imple
         {
             if ( startedAction )
             {
-                this.abortAction( actionContext );
+                abortAction( actionContext );
                 abortedAction = true;
             }
             
@@ -414,7 +414,7 @@ public class SnapshotRecordManager imple
         {
             if ( startedAction && !abortedAction )
             {
-                this.endAction ( actionContext );
+                endAction ( actionContext );
             }
         }
     }
@@ -452,7 +452,7 @@ public class SnapshotRecordManager imple
         
         if ( actionContext == null )
         {
-            actionContext = this.beginAction( false, "fetch missing action" );
+            actionContext = beginAction( false, "fetch missing action" );
             startedAction = true;
         }
         
@@ -465,7 +465,7 @@ public class SnapshotRecordManager imple
         {
             if ( startedAction )
             {
-                this.abortAction( actionContext );
+                abortAction( actionContext );
                 abortedAction = true;
             }
             
@@ -475,7 +475,7 @@ public class SnapshotRecordManager imple
         {
             if ( startedAction && !abortedAction )
             {
-                this.endAction ( actionContext );
+                endAction( actionContext );
             }
         }
         
@@ -631,7 +631,7 @@ public class SnapshotRecordManager imple
     {
         StringBuilder sb = new StringBuilder();
         sb.append( "SnapshotRecordManager: " );
-        sb.append( "(lruCache:" ).append( this.versionedCache );
+        sb.append( "(lruCache:" ).append( versionedCache );
         sb.append( ")\n" );
         
         return sb.toString();



Mime
View raw message