com.cdegroot.db.recman
Class RecordManager

java.lang.Object
  |
  +--com.cdegroot.db.recman.RecordManager

public final class RecordManager
extends Object

This class manages records, which are uninterpreted blobs of data. The set of operations is simple and straightforward: you communicate with the class using long "rowids" and byte[] data blocks. Rowids are returned on inserts and you can stash them away someplace safe to be able to get back to them. Data blocks can be as long as you wish, and may have lengths different from the original when updating.

Operations are synchronized, so that only one of them will happen concurrently even if you hammer away from multiple threads. Operations are made atomic by keeping a transaction log which is recovered after a crash, so the operations specified by this interface all have ACID properties.

You identify a file by just the name. The package attaches .db for the database file, and .lg for the transaction log. The transaction log is synchronized regularly and then restarted, so don't worry if you see the size going up and down.


Constructor Summary
RecordManager(String filename)
          Creates a record manager for the indicated file
 
Method Summary
 void close()
          Closes the record manager.
 void delete(long recid)
          Deletes a record.
 void disableTransactions()
          Switches off transactioning for the record manager.
 byte[] fetch(long recid)
          Fetches a record.
 long getRoot(int id)
          Returns the indicated root rowid.
 int getRootCount()
          Returns the number of slots available for "root" rowids.
 long insert(byte[] data)
          Inserts a new record.
 void setRoot(int id, long rowid)
          Sets the indicated root rowid.
 void update(long recid, byte[] data)
          Updates a record.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RecordManager

public RecordManager(String filename)
              throws IOException
Creates a record manager for the indicated file
Throws:
IOException - when the file cannot be opened or is not a valid file content-wise.
Method Detail

disableTransactions

public void disableTransactions()
Switches off transactioning for the record manager. This means that a) a transaction log is not kept, and b) writes aren't synch'ed after every update. This is useful when batch inserting into a new database.

Only call this method directly after opening the file, otherwise the results will be undefined.


close

public void close()
           throws IOException
Closes the record manager.
Throws:
IOException - when one of the underlying I/O operations fails.

insert

public long insert(byte[] data)
            throws IOException
Inserts a new record.
Parameters:
data - the data for the new record.
Throws:
IOException - when one of the underlying I/O operations fails.

delete

public void delete(long recid)
            throws IOException
Deletes a record.
Parameters:
rowid - the rowid for the record that should be deleted.
Throws:
IOException - when one of the underlying I/O operations fails.

update

public void update(long recid,
                   byte[] data)
            throws IOException
Updates a record.
Parameters:
recid - the recid for the record that is to be updated.
data - the new data for the record.
Throws:
IOException - when one of the underlying I/O operations fails.

fetch

public byte[] fetch(long recid)
             throws IOException
Fetches a record.
Parameters:
recid - the recid for the record that must be fetched.
Throws:
IOException - when one of the underlying I/O operations fails.

getRootCount

public int getRootCount()
Returns the number of slots available for "root" rowids. These slots can be used to store special rowids, like rowids that point to other rowids. Root rowids are useful for bootstrapping access to a set of data.

getRoot

public long getRoot(int id)
             throws IOException
Returns the indicated root rowid.
See Also:
getRootCount

setRoot

public void setRoot(int id,
                    long rowid)
             throws IOException
Sets the indicated root rowid.
See Also:
getRootCount

Homepage

(C) Copyright 2000, Cees de Groot