directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: r907807 - in /directory/apacheds/trunk/jdbm/src/main/java/jdbm: RecordManager.java recman/FileHeader.java recman/PageManager.java
Date Mon, 08 Feb 2010 21:33:54 GMT
Author: akarasulu
Date: Mon Feb  8 21:33:54 2010
New Revision: 907807

URL: http://svn.apache.org/viewvc?rev=907807&view=rev
Log:
formatting

Modified:
    directory/apacheds/trunk/jdbm/src/main/java/jdbm/RecordManager.java
    directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/FileHeader.java
    directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/PageManager.java

Modified: directory/apacheds/trunk/jdbm/src/main/java/jdbm/RecordManager.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/jdbm/src/main/java/jdbm/RecordManager.java?rev=907807&r1=907806&r2=907807&view=diff
==============================================================================
--- directory/apacheds/trunk/jdbm/src/main/java/jdbm/RecordManager.java (original)
+++ directory/apacheds/trunk/jdbm/src/main/java/jdbm/RecordManager.java Mon Feb  8 21:33:54
2010
@@ -45,12 +45,13 @@
  *
  * $Id: RecordManager.java,v 1.3 2005/06/25 23:12:31 doomdark Exp $
  */
-
 package jdbm;
 
+
 import java.io.IOException;
 import jdbm.helper.Serializer;
 
+
 /**
  *  An interface to manages records, which are uninterpreted blobs of data.
  *  <p>
@@ -66,11 +67,10 @@
  */
 public interface RecordManager
 {
-
     /**
      * Reserved slot for name directory.
      */
-    public static final int NAME_DIRECTORY_ROOT = 0;
+    int NAME_DIRECTORY_ROOT = 0;
 
 
     /**
@@ -80,8 +80,7 @@
      *  @return the rowid for the new record.
      *  @throws IOException when one of the underlying I/O operations fails.
      */
-    public abstract long insert( Object obj )
-        throws IOException;
+    long insert( Object obj ) throws IOException;
 
     
     /**
@@ -92,8 +91,7 @@
      *  @return the rowid for the new record.
      *  @throws IOException when one of the underlying I/O operations fails.
      */
-    public abstract long insert( Object obj, Serializer serializer )
-        throws IOException;
+    long insert( Object obj, Serializer serializer ) throws IOException;
 
 
     /**
@@ -102,8 +100,7 @@
      *  @param recid the rowid for the record that should be deleted.
      *  @throws IOException when one of the underlying I/O operations fails.
      */
-    public abstract void delete( long recid )
-        throws IOException;
+    void delete( long recid ) throws IOException;
 
 
     /**
@@ -113,8 +110,7 @@
      *  @param obj the new object for the record.
      *  @throws IOException when one of the underlying I/O operations fails.
      */
-    public abstract void update( long recid, Object obj )
-        throws IOException;
+    void update( long recid, Object obj ) throws IOException;
 
 
     /**
@@ -125,8 +121,7 @@
      *  @param serializer a custom serializer
      *  @throws IOException when one of the underlying I/O operations fails.
      */
-    public abstract void update( long recid, Object obj, Serializer serializer )
-        throws IOException;
+    void update( long recid, Object obj, Serializer serializer ) throws IOException;
 
     
     /**
@@ -136,8 +131,7 @@
      *  @return the object contained in the record.
      *  @throws IOException when one of the underlying I/O operations fails.
      */
-    public abstract Object fetch( long recid )
-        throws IOException;
+    Object fetch( long recid ) throws IOException;
 
 
     /**
@@ -148,8 +142,7 @@
      *  @return the object contained in the record.
      *  @throws IOException when one of the underlying I/O operations fails.
      */
-    public abstract Object fetch( long recid, Serializer serializer )
-        throws IOException;
+    Object fetch( long recid, Serializer serializer ) throws IOException;
 
 
     /**
@@ -157,8 +150,7 @@
      *
      *  @throws IOException when one of the underlying I/O operations fails.
      */
-    public abstract void close()
-        throws IOException;
+    void close() throws IOException;
 
 
     /**
@@ -167,7 +159,7 @@
      *  other rowids. Root rowids are useful for bootstrapping access to
      *  a set of data.
      */
-    public abstract int getRootCount();
+    int getRootCount();
 
 
     /**
@@ -175,8 +167,7 @@
      *
      *  @see #getRootCount
      */
-    public abstract long getRoot( int id )
-        throws IOException;
+    long getRoot( int id ) throws IOException;
 
 
     /**
@@ -184,39 +175,31 @@
      *
      *  @see #getRootCount
      */
-    public abstract void setRoot( int id, long rowid )
-        throws IOException;
+    void setRoot( int id, long rowid ) throws IOException;
 
 
     /**
      * Commit (make persistent) all changes since beginning of transaction.
      */
-    public abstract void commit()
-        throws IOException;
+    void commit() throws IOException;
 
 
     /**
      * Rollback (cancel) all changes since beginning of transaction.
      */
-    public abstract void rollback()
-        throws IOException;
-
-
+    void rollback() throws IOException;
 
 
     /**
      * Obtain the record id of a named object. Returns 0 if named object
      * doesn't exist.
      */
-    public abstract long getNamedObject( String name )
-        throws IOException;
+    long getNamedObject( String name ) throws IOException;
 
 
     /**
      * Set the record id of a named object.
      */
-    public abstract void setNamedObject( String name, long recid )
-        throws IOException;
-
+    void setNamedObject( String name, long recid ) throws IOException;
 }
 

Modified: directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/FileHeader.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/FileHeader.java?rev=907807&r1=907806&r2=907807&view=diff
==============================================================================
--- directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/FileHeader.java (original)
+++ directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/FileHeader.java Mon Feb  8 21:33:54
2010
@@ -44,93 +44,115 @@
  *
  * $Id: FileHeader.java,v 1.3 2005/06/25 23:12:32 doomdark Exp $
  */
-
 package jdbm.recman;
 
+
 import org.apache.directory.server.i18n.I18n;
 
+
 /**
- *  This class represents a file header. It is a 1:1 representation of
- *  the data that appears in block 0 of a file.
+ * This class represents a file header. It is a 1:1 representation of
+ * the data that appears in block 0 of a file.
  */
-class FileHeader implements BlockView {
+class FileHeader implements BlockView 
+{
     // offsets
     private static final short O_MAGIC = 0; // short magic
     private static final short O_LISTS = Magic.SZ_SHORT; // long[2*NLISTS]
-    private static final int O_ROOTS = 
-        O_LISTS + (Magic.NLISTS * 2 * Magic.SZ_LONG);
+    private static final int O_ROOTS = O_LISTS + ( Magic.NLISTS * 2 * Magic.SZ_LONG );
 
     // my block
     private BlockIo block;
 
     /** The number of "root" rowids available in the file. */
-    static final int NROOTS = 
-        (RecordFile.BLOCK_SIZE - O_ROOTS) / Magic.SZ_LONG;
+    static final int NROOTS = ( RecordFile.BLOCK_SIZE - O_ROOTS ) / Magic.SZ_LONG;
 
+    
     /**
-     *  Constructs a FileHeader object from a block.
+     * Constructs a FileHeader object from a block.
      *
-     *  @param block The block that contains the file header
-     *  @param isNew If true, the file header is for a new file.
-     *  @throws IOException if the block is too short to keep the file
-     *          header.
+     * @param block The block that contains the file header
+     * @param isNew If true, the file header is for a new file.
+     * @throws IOException if the block is too short to keep the file
+     *         header.
      */
-    FileHeader(BlockIo block, boolean isNew) {
+    FileHeader( BlockIo block, boolean isNew ) 
+    {
         this.block = block;
-        if (isNew)
-            block.writeShort(O_MAGIC, Magic.FILE_HEADER);
-        else if (!magicOk())
-            throw new Error( I18n.err( I18n.ERR_544, block.readShort(O_MAGIC) ) );
-    }
-
-    /** Returns true if the magic corresponds with the fileHeader magic.  */
-    private boolean magicOk() {
-        return block.readShort(O_MAGIC) == Magic.FILE_HEADER;
+        
+        if ( isNew )
+        {
+            block.writeShort( O_MAGIC, Magic.FILE_HEADER );
+        }
+        else if ( block.readShort( O_MAGIC ) != Magic.FILE_HEADER )
+        {
+            throw new Error( I18n.err( I18n.ERR_544, block.readShort( O_MAGIC ) ) );
+        }
     }
 
 
-    /** Returns the offset of the "first" block of the indicated list */
-    private short offsetOfFirst(int list) {
-        return (short) (O_LISTS + (2 * Magic.SZ_LONG * list));
+    /** 
+     * Returns the offset of the "first" block of the indicated list 
+     */
+    private short offsetOfFirst( int list ) 
+    {
+        return ( short ) ( O_LISTS + ( 2 * Magic.SZ_LONG * list ) );
     }
 
-    /** Returns the offset of the "last" block of the indicated list */
-    private short offsetOfLast(int list) {
-        return (short) (offsetOfFirst(list) + Magic.SZ_LONG);
+    
+    /** 
+     * Returns the offset of the "last" block of the indicated list 
+     */
+    private short offsetOfLast( int list ) 
+    {
+        return ( short ) ( offsetOfFirst( list ) + Magic.SZ_LONG );
     }
 
-    /** Returns the offset of the indicated root */
-    private short offsetOfRoot(int root) {
-        return (short) (O_ROOTS + (root * Magic.SZ_LONG));
+    
+    /** 
+     * Returns the offset of the indicated root 
+     */
+    private short offsetOfRoot( int root ) 
+    {
+        return ( short ) ( O_ROOTS + ( root * Magic.SZ_LONG ) );
     }
 
+    
     /**
-     *  Returns the first block of the indicated list
+     * Returns the first block of the indicated list
      */
-    long getFirstOf(int list) {
-        return block.readLong(offsetOfFirst(list));
+    long getFirstOf( int list ) 
+    {
+        return block.readLong( offsetOfFirst( list ) );
     }
     
+    
     /**
-     *  Sets the first block of the indicated list
+     * Sets the first block of the indicated list
      */
-    void setFirstOf(int list, long value) {
-        block.writeLong(offsetOfFirst(list), value);
+    void setFirstOf( int list, long value ) 
+    {
+        block.writeLong( offsetOfFirst( list ), value );
     }
     
+    
     /**
-     *  Returns the last block of the indicated list
+     * Returns the last block of the indicated list
      */
-    long getLastOf(int list) {
-        return block.readLong(offsetOfLast(list));
+    long getLastOf( int list ) 
+    {
+        return block.readLong( offsetOfLast( list ) );
     }
     
+    
     /**
-     *  Sets the last block of the indicated list
+     * Sets the last block of the indicated list
      */
-    void setLastOf(int list, long value) {
-        block.writeLong(offsetOfLast(list), value);
+    void setLastOf( int list, long value ) 
+    {
+        block.writeLong( offsetOfLast( list ), value );
     }
+    
 
     /**
      *  Returns the indicated root rowid. A root rowid is a special rowid
@@ -141,17 +163,20 @@
      *
      *  @see #NROOTS
      */
-    long getRoot(int root) {
-        return block.readLong(offsetOfRoot(root));
+    long getRoot( int root ) 
+    {
+        return block.readLong( offsetOfRoot( root ) );
     }
 
+    
     /**
      *  Sets the indicated root rowid.
      *
      *  @see #getRoot
      *  @see #NROOTS
      */
-    void setRoot(int root, long rowid) {
-        block.writeLong(offsetOfRoot(root), rowid);
+    void setRoot( int root, long rowid ) 
+    {
+        block.writeLong( offsetOfRoot( root ), rowid );
     }
 }

Modified: directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/PageManager.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/PageManager.java?rev=907807&r1=907806&r2=907807&view=diff
==============================================================================
--- directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/PageManager.java (original)
+++ directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/PageManager.java Mon Feb  8 21:33:54
2010
@@ -44,231 +44,295 @@
  *
  * $Id: PageManager.java,v 1.3 2005/06/25 23:12:32 doomdark Exp $
  */
-
 package jdbm.recman;
 
+
 import java.io.*;
 
 import org.apache.directory.server.i18n.I18n;
 
+
 /**
- *  This class manages the linked lists of pages that make up a file.
+ * This class manages the linked lists of pages that make up a file.
  */
-final class PageManager {
+final class PageManager 
+{
     // our record file
     private RecordFile file;
     // header data
     private FileHeader header;
+    // file header containing block
     private BlockIo headerBuf;
+
     
     /**
-     *  Creates a new page manager using the indicated record file.
+     * Creates a new page manager using the indicated record file.
      */
-    PageManager(RecordFile file) throws IOException {
+    PageManager( RecordFile file ) throws IOException 
+    {
         this.file = file;
         
-        // check the file header. If the magic is 0, we assume a new
-        // file. Note that we hold on to the file header node.
-        headerBuf = file.get(0);
-        if (headerBuf.readShort(0) == 0)
-            header = new FileHeader(headerBuf, true);
-        else
-            header = new FileHeader(headerBuf, false);
+        // Note that we hold on to the file header node.
+        headerBuf = file.get( 0 );
+        
+        // Assume file is new if the file header's magic number is 0. 
+        if ( headerBuf.readShort( 0 ) == 0 )
+        {
+            header = new FileHeader( headerBuf, true );
+        }
+        else // header is for existing file
+        {
+            header = new FileHeader( headerBuf, false );
+        }
     }
     
+    
     /**
-     *  Allocates a page of the indicated type. Returns recid of the
-     *  page.
+     * Allocates a page of the indicated type. Returns recid of the page.
      */
-    long allocate(short type) throws IOException {
-        
-        if (type == Magic.FREE_PAGE)
+    long allocate( short type ) throws IOException 
+    {
+        if ( type == Magic.FREE_PAGE )
+        {
             throw new Error( I18n.err( I18n.ERR_548 ) );
+        }
         
-        // do we have something on the free list?
-        long retval = header.getFirstOf(Magic.FREE_PAGE);
         boolean isNew = false;
-        if (retval != 0) {
+        
+        // Do we have something on the free list?
+        long retval = header.getFirstOf( Magic.FREE_PAGE );
+        if ( retval != 0 ) 
+        {
             // yes. Point to it and make the next of that page the
             // new first free page.
-            header.setFirstOf(Magic.FREE_PAGE, getNext(retval));
+            header.setFirstOf( Magic.FREE_PAGE, getNext( retval ) );
         }
-        else {
+        else 
+        {
             // nope. make a new record
-            retval = header.getLastOf(Magic.FREE_PAGE);
-            if (retval == 0)
+            retval = header.getLastOf( Magic.FREE_PAGE );
+
+            if ( retval == 0 )
+            {
                 // very new file - allocate record #1
                 retval = 1;
-            header.setLastOf(Magic.FREE_PAGE, retval + 1);
+            }
+            
+            header.setLastOf( Magic.FREE_PAGE, retval + 1 );
             isNew = true;
         }
         
         // Cool. We have a record, add it to the correct list
-        BlockIo buf = file.get(retval);
-        PageHeader pageHdr = isNew ? new PageHeader(buf, type) 
-            : PageHeader.getView(buf);
-        long oldLast = header.getLastOf(type);
+        BlockIo buf = file.get( retval );
+        PageHeader pageHdr = null;
         
-        // Clean data.
-        System.arraycopy(RecordFile.cleanData, 0, 
-                         buf.getData(), 0, 
-                         RecordFile.BLOCK_SIZE);
-        pageHdr.setType(type);
-        pageHdr.setPrev(oldLast);
-        pageHdr.setNext(0);
+        if ( isNew )
+        {
+            pageHdr = new PageHeader( buf, type );
+        }
+        else
+        {
+            pageHdr = PageHeader.getView( buf );
+        }
         
+        long oldLast = header.getLastOf( type );
+        
+        // Clean data.
+        System.arraycopy( RecordFile.cleanData, 0, buf.getData(), 0, RecordFile.BLOCK_SIZE
);
+        pageHdr.setType( type );
+        pageHdr.setPrev( oldLast );
+        pageHdr.setNext( 0 );
         
-        if (oldLast == 0)
+        if ( oldLast == 0 )
+        {
             // This was the first one of this type
-            header.setFirstOf(type, retval);
-        header.setLastOf(type, retval);
-        file.release(retval, true);
+            header.setFirstOf( type, retval );
+        }
+        
+        header.setLastOf( type, retval );
+        file.release( retval, true );
         
         // If there's a previous, fix up its pointer
-        if (oldLast != 0) {
-            buf = file.get(oldLast);
-            pageHdr = PageHeader.getView(buf);
-            pageHdr.setNext(retval);
-            file.release(oldLast, true);
+        if ( oldLast != 0 ) 
+        {
+            buf = file.get( oldLast );
+            pageHdr = PageHeader.getView( buf );
+            pageHdr.setNext( retval );
+            file.release( oldLast, true );
         }
         
         // remove the view, we have modified the type.
-        buf.setView(null);
+        buf.setView( null );
         
         return retval;
     }
     
+    
     /**
-     *  Frees a page of the indicated type.
+     * Frees a page of the indicated type.
      */
-    void free(short type, long recid) throws IOException {
-        if (type == Magic.FREE_PAGE)
+    void free( short type, long recid ) throws IOException 
+    {
+        if ( type == Magic.FREE_PAGE )
+        {
             throw new Error( I18n.err( I18n.ERR_549 ) );
+        }
+        
         if (recid == 0)
+        {
             throw new Error( I18n.err( I18n.ERR_550 ) );
+        }
         
         // get the page and read next and previous pointers
-        BlockIo buf = file.get(recid);
-        PageHeader pageHdr = PageHeader.getView(buf);
+        BlockIo buf = file.get( recid );
+        PageHeader pageHdr = PageHeader.getView( buf );
         long prev = pageHdr.getPrev();
         long next = pageHdr.getNext();
         
         // put the page at the front of the free list.
-        pageHdr.setType(Magic.FREE_PAGE);
-        pageHdr.setNext(header.getFirstOf(Magic.FREE_PAGE));
-        pageHdr.setPrev(0);
+        pageHdr.setType( Magic.FREE_PAGE );
+        pageHdr.setNext( header.getFirstOf( Magic.FREE_PAGE ) );
+        pageHdr.setPrev( 0 );
         
-        header.setFirstOf(Magic.FREE_PAGE, recid);
-        file.release(recid, true);
+        header.setFirstOf( Magic.FREE_PAGE, recid );
+        file.release( recid, true );
         
         // remove the page from its old list
-        if (prev != 0) {
-            buf = file.get(prev);
-            pageHdr = PageHeader.getView(buf);
-            pageHdr.setNext(next);
-            file.release(prev, true);
+        if ( prev != 0 ) 
+        {
+            buf = file.get( prev );
+            pageHdr = PageHeader.getView( buf );
+            pageHdr.setNext( next );
+            file.release( prev, true );
         }
-        else {
-            header.setFirstOf(type, next);
+        else 
+        {
+            header.setFirstOf( type, next );
         }
-        if (next != 0) {
-            buf = file.get(next);
-            pageHdr = PageHeader.getView(buf);
-            pageHdr.setPrev(prev);
-            file.release(next, true);
+        
+        if ( next != 0 ) 
+        {
+            buf = file.get( next );
+            pageHdr = PageHeader.getView( buf );
+            pageHdr.setPrev( prev );
+            file.release( next, true );
         }
-        else {
-            header.setLastOf(type, prev);
+        else 
+        {
+            header.setLastOf( type, prev );
         }
-        
     }
     
     
     /**
-     *  Returns the page following the indicated block
+     * Returns the page following the indicated block
      */
-    long getNext(long block) throws IOException {
-        try {
-            return PageHeader.getView(file.get(block)).getNext();
-        } finally {
-            file.release(block, false);
+    long getNext( long block ) throws IOException 
+    {
+        try 
+        {
+            return PageHeader.getView( file.get( block ) ).getNext();
+        } 
+        finally 
+        {
+            file.release( block, false );
         }
     }
     
+    
     /**
-     *  Returns the page before the indicated block
+     * Returns the page before the indicated block
      */
-    long getPrev(long block) throws IOException {
-        try {
-            return PageHeader.getView(file.get(block)).getPrev();
-        } finally {
-            file.release(block, false);
+    long getPrev( long block ) throws IOException 
+    {
+        try 
+        {
+            return PageHeader.getView( file.get( block ) ).getPrev();
+        } 
+        finally 
+        {
+            file.release( block, false );
         }
     }
     
+    
     /**
-     *  Returns the first page on the indicated list.
+     * Returns the first page on the indicated list.
      */
-    long getFirst(short type) throws IOException {
-        return header.getFirstOf(type);
+    long getFirst( short type ) throws IOException 
+    {
+        return header.getFirstOf( type );
     }
 
+    
     /**
-     *  Returns the last page on the indicated list.
+     * Returns the last page on the indicated list.
      */
-    long getLast(short type) throws IOException {
-        return header.getLastOf(type);
+    long getLast( short type ) throws IOException 
+    {
+        return header.getLastOf( type );
     }
     
     
     /**
-     *  Commit all pending (in-memory) data by flushing the page manager.
-     *  This forces a flush of all outstanding blocks (this it's an implicit
-     *  {@link RecordFile#commit} as well).
+     * Commit all pending (in-memory) data by flushing the page manager.
+     * This forces a flush of all outstanding blocks (this it's an implicit
+     * {@link RecordFile#commit} as well).
      */
-    void commit() throws IOException {
+    void commit() throws IOException 
+    {
         // write the header out
-        file.release(headerBuf);
+        file.release( headerBuf );
         file.commit();
 
         // and obtain it again
-        headerBuf = file.get(0);
-        header = new FileHeader(headerBuf, false);
+        headerBuf = file.get( 0 );
+        header = new FileHeader( headerBuf, false );
     }
 
+    
     /**
      *  Flushes the page manager. This forces a flush of all outstanding
      *  blocks (this it's an implicit {@link RecordFile#commit} as well).
      */
-    void rollback() throws IOException {
+    void rollback() throws IOException 
+    {
         // release header
-        file.discard(headerBuf);
+        file.discard( headerBuf );
         file.rollback();
         // and obtain it again
-        headerBuf = file.get(0);
-        if (headerBuf.readShort(0) == 0)
-            header = new FileHeader(headerBuf, true);
+        headerBuf = file.get( 0 );
+        
+        if ( headerBuf.readShort( 0 ) == 0 )
+        {
+            header = new FileHeader( headerBuf, true );
+        }
         else
-            header = new FileHeader(headerBuf, false);
+        {
+            header = new FileHeader( headerBuf, false );
+        }
     }
     
+    
     /**
      *  Closes the page manager. This flushes the page manager and releases
      *  the lock on the header.
      */
-    void close() throws IOException {   
-        file.release(headerBuf);
+    void close() throws IOException 
+    {   
+        file.release( headerBuf );
         file.commit();
         headerBuf = null;
         header = null;
         file = null;
     }
     
+    
     /**
      *  Returns the file header.
      */
-    FileHeader getFileHeader() {
+    FileHeader getFileHeader() 
+    {
         return header;
-    }
-    
+    }    
 }



Mime
View raw message