jdbm.recman
Class RecordFile

java.lang.Object
  extended byjdbm.recman.RecordFile

public final class RecordFile
extends java.lang.Object

This class represents a random access file as a set of fixed size records. Each record has a physical record number, and records are cached in order to improve access. The set of dirty records on the in-use list constitutes a transaction. Later on, we will send these records to some recovery thingy.


Field Summary
static int BLOCK_SIZE
          The length of a single block.
(package private) static byte[] cleanData
          A block of clean data to wipe clean pages.
(package private) static java.lang.String extension
          The extension of a record file
(package private)  TransactionManager txnMgr
           
 
Constructor Summary
(package private) RecordFile(java.lang.String fileName)
          Creates a new object on the indicated filename.
 
Method Summary
(package private)  void close()
          Commits and closes file.
(package private)  void commit()
          Commits the current transaction by flushing all dirty buffers to disk.
(package private)  void disableTransactions()
          Disables transactions: doesn't sync and doesn't use the transaction manager.
(package private)  void discard(BlockIo block)
          Discards a block (will not write the block even if it's dirty)
(package private)  void forceClose()
          Force closing the file and underlying transaction manager.
(package private)  BlockIo get(long blockid)
          Gets a block from the file.
(package private)  java.lang.String getFileName()
          Returns the file name.
(package private)  void release(BlockIo block)
          Releases a block.
(package private)  void release(long blockid, boolean isDirty)
          Releases a block.
(package private)  void releaseFromTransaction(BlockIo node, boolean recycle)
          Releases a node from the transaction list, if it was sitting there.
(package private)  void rollback()
          Rollback the current transaction by discarding all dirty buffers
(package private)  void sync()
          Synchronizes the file.
(package private)  void synch(BlockIo node)
          Synchs a node to disk.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

txnMgr

final TransactionManager txnMgr

BLOCK_SIZE

public static final int BLOCK_SIZE
The length of a single block.

See Also:
Constant Field Values

extension

static final java.lang.String extension
The extension of a record file

See Also:
Constant Field Values

cleanData

static final byte[] cleanData
A block of clean data to wipe clean pages.

Constructor Detail

RecordFile

RecordFile(java.lang.String fileName)
     throws java.io.IOException
Creates a new object on the indicated filename. The file is opened in read/write mode.

Parameters:
fileName - the name of the file to open or create, without an extension.
Throws:
java.io.IOException - whenever the creation of the underlying RandomAccessFile throws it.
Method Detail

getFileName

java.lang.String getFileName()
Returns the file name.


disableTransactions

void disableTransactions()
Disables transactions: doesn't sync and doesn't use the transaction manager.


get

BlockIo get(long blockid)
      throws java.io.IOException
Gets a block from the file. The returned byte array is the in-memory copy of the record, and thus can be written (and subsequently released with a dirty flag in order to write the block back).

Parameters:
blockid - The record number to retrieve.
Throws:
java.io.IOException

release

void release(long blockid,
             boolean isDirty)
       throws java.io.IOException
Releases a block.

Parameters:
blockid - The record number to release.
isDirty - If true, the block was modified since the get().
Throws:
java.io.IOException

release

void release(BlockIo block)
Releases a block.

Parameters:
block - The block to release.

discard

void discard(BlockIo block)
Discards a block (will not write the block even if it's dirty)

Parameters:
block - The block to discard.

commit

void commit()
      throws java.io.IOException
Commits the current transaction by flushing all dirty buffers to disk.

Throws:
java.io.IOException

rollback

void rollback()
        throws java.io.IOException
Rollback the current transaction by discarding all dirty buffers

Throws:
java.io.IOException

close

void close()
     throws java.io.IOException
Commits and closes file.

Throws:
java.io.IOException

forceClose

void forceClose()
          throws java.io.IOException
Force closing the file and underlying transaction manager. Used for testing purposed only.

Throws:
java.io.IOException

synch

void synch(BlockIo node)
     throws java.io.IOException
Synchs a node to disk. This is called by the transaction manager's synchronization code.

Throws:
java.io.IOException

releaseFromTransaction

void releaseFromTransaction(BlockIo node,
                            boolean recycle)
                      throws java.io.IOException
Releases a node from the transaction list, if it was sitting there.

Throws:
java.io.IOException

sync

void sync()
    throws java.io.IOException
Synchronizes the file.

Throws:
java.io.IOException


Cees de Groot (C) 2000-2001. All rights reserved http://jdbm.sourceforge.net