jdbm.recman
Class BaseRecordManager

java.lang.Object
  extended by jdbm.helper.RecordManagerImpl
      extended by jdbm.recman.BaseRecordManager
All Implemented Interfaces:
RecordManager

public final class BaseRecordManager
extends RecordManagerImpl

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.

Version:
$Id: BaseRecordManager.java,v 1.8 2005/06/25 23:12:32 doomdark Exp $
Author:
Alex Boisvert, Cees de Groot

Field Summary
static boolean DEBUG
          Static debugging flag
static int NAME_DIRECTORY_ROOT
          Reserved slot for name directory.
static int STORE_VERSION_NUMBER_ROOT
          Reserved slot for version number
 
Fields inherited from interface jdbm.RecordManager
NULL_RECID
 
Constructor Summary
BaseRecordManager(java.lang.String filename)
          Creates a record manager for the indicated file
 
Method Summary
 void clearCache()
          Empty cache.
 void close()
          Closes the record manager.
 void commit()
          Commit (make persistent) all changes since beginning of transaction.
 void defrag()
          Defragments storage, so it consumes less space.
 void delete(long logRowId)
          Deletes a record.
 void disableTransactions()
          Switches off transactioning for the record manager.
<A> A
fetch(long recid, Serializer<A> serializer)
          Fetches a record using a custom serializer.
<A> A
fetch(long recid, Serializer<A> serializer, boolean disableCache)
          Fetches a record using a custom serializer and optionaly disabled cache
 long getNamedObject(java.lang.String name)
          Obtain the record id of a named object.
 long getRoot(int id)
           
 int getRootCount()
           
<A> long
insert(A obj, Serializer<A> serializer)
          Inserts a new record using a custom serializer.
 boolean isAppendToEnd()
          if true, new records alwayes saved to end of file and free space is not reclaimed.
 void rollback()
          Rollback (cancel) all changes since beginning of transaction.
 void setAppendToEnd(boolean appendToEnd)
          if true, new records alwayes saved to end of file and free space is not reclaimed.
 void setCompress(boolean b)
          Enable or disable compression of blocks with Deflate algorithm
 void setNamedObject(java.lang.String name, long recid)
          Set the record id of a named object.
 void setRoot(int id, long rowid)
           
<A> void
update(long recid, A obj, Serializer<A> serializer)
          Updates a record using a custom serializer.
 
Methods inherited from class jdbm.helper.RecordManagerImpl
fetch, hashMap, hashMap, hashMap, insert, storeMap, storeMap, treeMap, treeMap, treeMap, treeMap, treeMap, treeMap, update
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEBUG

public static final boolean DEBUG
Static debugging flag

See Also:
Constant Field Values

NAME_DIRECTORY_ROOT

public static final int NAME_DIRECTORY_ROOT
Reserved slot for name directory.

See Also:
Constant Field Values

STORE_VERSION_NUMBER_ROOT

public static final int STORE_VERSION_NUMBER_ROOT
Reserved slot for version number

See Also:
Constant Field Values
Constructor Detail

BaseRecordManager

public BaseRecordManager(java.lang.String filename)
                  throws java.io.IOException
Creates a record manager for the indicated file

Throws:
java.io.IOException - when the file cannot be opened or is not a valid file content-wise.
Method Detail

isAppendToEnd

public boolean isAppendToEnd()
if true, new records alwayes saved to end of file and free space is not reclaimed. This may speed up some operations which involves lot of updates and inserts (batch creation); You need to reopen store to apply effect


setAppendToEnd

public void setAppendToEnd(boolean appendToEnd)
if true, new records alwayes saved to end of file and free space is not reclaimed. This may speed up some operations which involves lot of updates and inserts (batch creation); You need to reopen store to apply effect


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.


setCompress

public void setCompress(boolean b)
Enable or disable compression of blocks with Deflate algorithm

Parameters:
b -

close

public void close()
           throws java.io.IOException
Closes the record manager.

Throws:
java.io.IOException - when one of the underlying I/O operations fails.

insert

public <A> long insert(A obj,
                       Serializer<A> serializer)
            throws java.io.IOException
Inserts a new record using a custom serializer.

Parameters:
obj - the object for the new record.
serializer - a custom serializer
Returns:
the rowid for the new record.
Throws:
java.io.IOException - when one of the underlying I/O operations fails.

delete

public void delete(long logRowId)
            throws java.io.IOException
Description copied from interface: RecordManager
Deletes a record.

Parameters:
logRowId - the rowid for the record that should be deleted.
Throws:
java.io.IOException - when one of the underlying I/O operations fails.

update

public <A> void update(long recid,
                       A obj,
                       Serializer<A> serializer)
            throws java.io.IOException
Description copied from interface: RecordManager
Updates a record using a custom serializer. If given recid does not exist, IOException will be thrown before/during commit (cache).

Parameters:
recid - the recid for the record that is to be updated.
obj - the new object for the record.
serializer - a custom serializer
Throws:
java.io.IOException - when one of the underlying I/O operations fails

fetch

public <A> A fetch(long recid,
                   Serializer<A> serializer)
        throws java.io.IOException
Description copied from interface: RecordManager
Fetches a record using a custom serializer.

Parameters:
recid - the recid for the record that must be fetched.
serializer - a custom serializer
Returns:
the object contained in the record, null if given recid does not exist
Throws:
java.io.IOException - when one of the underlying I/O operations fails.

fetch

public <A> A fetch(long recid,
                   Serializer<A> serializer,
                   boolean disableCache)
        throws java.io.IOException
Description copied from interface: RecordManager
Fetches a record using a custom serializer and optionaly disabled cache

Parameters:
recid - the recid for the record that must be fetched.
serializer - a custom serializer
disableCache - true to disable any caching mechanism
Returns:
the object contained in the record, null if given recid does not exist
Throws:
java.io.IOException - when one of the underlying I/O operations fails.

getRootCount

public int getRootCount()

getRoot

public long getRoot(int id)
             throws java.io.IOException
Throws:
java.io.IOException

setRoot

public void setRoot(int id,
                    long rowid)
             throws java.io.IOException
Throws:
java.io.IOException

getNamedObject

public long getNamedObject(java.lang.String name)
                    throws java.io.IOException
Description copied from interface: RecordManager
Obtain the record id of a named object. Returns 0 if named object doesn't exist. Named objects are used to store Map views and other well known objects.

Throws:
java.io.IOException

setNamedObject

public void setNamedObject(java.lang.String name,
                           long recid)
                    throws java.io.IOException
Description copied from interface: RecordManager
Set the record id of a named object. Named objects are used to store Map views and other well known objects.

Throws:
java.io.IOException

commit

public void commit()
            throws java.io.IOException
Description copied from interface: RecordManager
Commit (make persistent) all changes since beginning of transaction. JDBM supports only single transaction.

Throws:
java.io.IOException

rollback

public void rollback()
              throws java.io.IOException
Description copied from interface: RecordManager
Rollback (cancel) all changes since beginning of transaction. JDBM supports only single transaction. This operations affects all maps created by this RecordManager.

Throws:
java.io.IOException

clearCache

public void clearCache()
                throws java.io.IOException
Description copied from interface: RecordManager
Empty cache. This may be usefull if you need to release memory.

Throws:
java.io.IOException

defrag

public void defrag()
            throws java.io.IOException
Description copied from interface: RecordManager
Defragments storage, so it consumes less space. This commits any uncommited data.

Throws:
java.io.IOException


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