jdbm.recman
Class CacheRecordManager

java.lang.Object
  extended by jdbm.recman.CacheRecordManager
All Implemented Interfaces:
RecordManager

public class CacheRecordManager
extends java.lang.Object
implements RecordManager

A RecordManager wrapping and caching another RecordManager.

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

Field Summary
 
Fields inherited from interface jdbm.RecordManager
NAME_DIRECTORY_ROOT
 
Constructor Summary
CacheRecordManager(RecordManager recman, CachePolicy cache)
          Construct a CacheRecordManager wrapping another RecordManager and using a given cache policy.
 
Method Summary
 void close()
          Closes the record manager.
 void commit()
          Commit (make persistent) all changes since beginning of transaction.
 void delete(long recid)
          Deletes a record.
 java.lang.Object fetch(long recid)
          Fetches a record using standard Java serialization.
 java.lang.Object fetch(long recid, Serializer serializer)
          Fetches a record using a custom serializer.
 CachePolicy getCachePolicy()
          Get the underlying cache policy
 long getNamedObject(java.lang.String name)
          Obtain the record id of a named object.
 RecordManager getRecordManager()
          Get the underlying Record Manager.
 long getRoot(int id)
          Returns the indicated root rowid.
 int getRootCount()
          Returns the number of slots available for "root" rowids.
 long insert(java.lang.Object obj)
          Inserts a new record using a custom serializer.
 long insert(java.lang.Object obj, Serializer serializer)
          Inserts a new record using a custom serializer.
 void rollback()
          Rollback (cancel) all changes since beginning of transaction.
 void setNamedObject(java.lang.String name, long recid)
          Set the record id of a named object.
 void setRoot(int id, long rowid)
          Sets the indicated root rowid.
 void update(long recid, java.lang.Object obj)
          Updates a record using standard Java serialization.
 void update(long recid, java.lang.Object obj, Serializer serializer)
          Updates a record using a custom serializer.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CacheRecordManager

public CacheRecordManager(RecordManager recman,
                          CachePolicy cache)
Construct a CacheRecordManager wrapping another RecordManager and using a given cache policy.

Parameters:
recman - Wrapped RecordManager
cache - Cache policy
Method Detail

getRecordManager

public RecordManager getRecordManager()
Get the underlying Record Manager.

Returns:
underlying RecordManager or null if CacheRecordManager has been closed.

getCachePolicy

public CachePolicy getCachePolicy()
Get the underlying cache policy

Returns:
underlying CachePolicy or null if CacheRecordManager has been closed.

insert

public long insert(java.lang.Object obj)
            throws java.io.IOException
Inserts a new record using a custom serializer.

Specified by:
insert in interface RecordManager
Parameters:
obj - the object for the new record.
Returns:
the rowid for the new record.
Throws:
java.io.IOException - when one of the underlying I/O operations fails.

insert

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

Specified by:
insert in interface RecordManager
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 recid)
            throws java.io.IOException
Deletes a record.

Specified by:
delete in interface RecordManager
Parameters:
recid - the rowid for the record that should be deleted.
Throws:
java.io.IOException - when one of the underlying I/O operations fails.

update

public void update(long recid,
                   java.lang.Object obj)
            throws java.io.IOException
Updates a record using standard Java serialization.

Specified by:
update in interface RecordManager
Parameters:
recid - the recid for the record that is to be updated.
obj - the new object for the record.
Throws:
java.io.IOException - when one of the underlying I/O operations fails.

update

public void update(long recid,
                   java.lang.Object obj,
                   Serializer serializer)
            throws java.io.IOException
Updates a record using a custom serializer.

Specified by:
update in interface RecordManager
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 java.lang.Object fetch(long recid)
                       throws java.io.IOException
Fetches a record using standard Java serialization.

Specified by:
fetch in interface RecordManager
Parameters:
recid - the recid for the record that must be fetched.
Returns:
the object contained in the record.
Throws:
java.io.IOException - when one of the underlying I/O operations fails.

fetch

public java.lang.Object fetch(long recid,
                              Serializer serializer)
                       throws java.io.IOException
Fetches a record using a custom serializer.

Specified by:
fetch in interface RecordManager
Parameters:
recid - the recid for the record that must be fetched.
serializer - a custom serializer
Returns:
the object contained in the record.
Throws:
java.io.IOException - when one of the underlying I/O operations fails.

close

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

Specified by:
close in interface RecordManager
Throws:
java.io.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.

Specified by:
getRootCount in interface RecordManager

getRoot

public long getRoot(int id)
             throws java.io.IOException
Returns the indicated root rowid.

Specified by:
getRoot in interface RecordManager
Throws:
java.io.IOException
See Also:
getRootCount()

setRoot

public void setRoot(int id,
                    long rowid)
             throws java.io.IOException
Sets the indicated root rowid.

Specified by:
setRoot in interface RecordManager
Throws:
java.io.IOException
See Also:
getRootCount()

commit

public void commit()
            throws java.io.IOException
Commit (make persistent) all changes since beginning of transaction.

Specified by:
commit in interface RecordManager
Throws:
java.io.IOException

rollback

public void rollback()
              throws java.io.IOException
Rollback (cancel) all changes since beginning of transaction.

Specified by:
rollback in interface RecordManager
Throws:
java.io.IOException

getNamedObject

public long getNamedObject(java.lang.String name)
                    throws java.io.IOException
Obtain the record id of a named object. Returns 0 if named object doesn't exist.

Specified by:
getNamedObject in interface RecordManager
Throws:
java.io.IOException

setNamedObject

public void setNamedObject(java.lang.String name,
                           long recid)
                    throws java.io.IOException
Set the record id of a named object.

Specified by:
setNamedObject in interface RecordManager
Throws:
java.io.IOException


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