simpledb.file
Class FileMgr

java.lang.Object
  extended by simpledb.file.FileMgr

public class FileMgr
extends java.lang.Object

The SimpleDB file manager. The database system stores its data as files within a specified directory. The file manager provides methods for reading the contents of a file block to a Java byte buffer, writing the contents of a byte buffer to a file block, and appending the contents of a byte buffer to the end of a file. These methods are called exclusively by the class Page, and are thus package-private. The class also contains two public methods: Method isNew is called during system initialization by SimpleDB.init(java.lang.String). Method size is called by the log manager and transaction manager to determine the end of the file.

Author:
Edward Sciore

Constructor Summary
FileMgr(java.lang.String dbname)
          Creates a file manager for the specified database.
 
Method Summary
(package private)  Block append(java.lang.String filename, java.nio.ByteBuffer bb)
          Appends the contents of a bytebuffer to the end of the specified file.
 void close()
           
 boolean isNew()
          Returns a boolean indicating whether the file manager had to create a new database directory.
(package private)  void read(Block blk, java.nio.ByteBuffer bb)
          Reads the contents of a disk block into a bytebuffer.
 int size(java.lang.String filename)
          Returns the number of blocks in the specified file.
(package private)  void write(Block blk, java.nio.ByteBuffer bb)
          Writes the contents of a bytebuffer into a disk block.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileMgr

public FileMgr(java.lang.String dbname)
Creates a file manager for the specified database. The database will be stored in a folder of that name in the user's home directory. If the folder does not exist, then a folder containing an empty database is created automatically. Files for all temporary tables (i.e. tables beginning with "temp") are deleted.

Parameters:
dbname - the name of the directory that holds the database
Method Detail

read

void read(Block blk,
          java.nio.ByteBuffer bb)
Reads the contents of a disk block into a bytebuffer.

Parameters:
blk - a reference to a disk block
bb - the bytebuffer

write

void write(Block blk,
           java.nio.ByteBuffer bb)
Writes the contents of a bytebuffer into a disk block.

Parameters:
blk - a reference to a disk block
bb - the bytebuffer

append

Block append(java.lang.String filename,
             java.nio.ByteBuffer bb)
Appends the contents of a bytebuffer to the end of the specified file.

Parameters:
filename - the name of the file
bb - the bytebuffer
Returns:
a reference to the newly-created block.

size

public int size(java.lang.String filename)
Returns the number of blocks in the specified file.

Parameters:
filename - the name of the file
Returns:
the number of blocks in the file

isNew

public boolean isNew()
Returns a boolean indicating whether the file manager had to create a new database directory.

Returns:
true if the database is new

close

public void close()