jdbm.recman
Class CacheRecordManager

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

public class CacheRecordManager
extends RecordManagerImpl

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
NULL_RECID
 
Constructor Summary
CacheRecordManager(RecordManager recman, int maxRecords, boolean softCache)
          Construct a CacheRecordManager wrapping another RecordManager and using a given cache policy.
 
Method Summary
 void clearCache()
          Empty cache.
 void close()
          Closes the record manager and release resources.
 void commit()
          Commit (make persistent) all changes since beginning of transaction.
 void defrag()
          Defragments storage, so it consumes less space.
 void delete(long recid)
          Deletes a record.
<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.
 RecordManager getRecordManager()
          Get the underlying Record Manager.
<A> long
insert(A obj, Serializer<A> 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.
<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
 

Constructor Detail

CacheRecordManager

public CacheRecordManager(RecordManager recman,
                          int maxRecords,
                          boolean softCache)
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.

insert

public <A> long insert(A obj,
                       Serializer<A> serializer)
            throws java.io.IOException
Description copied from interface: RecordManager
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.

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.

delete

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

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 <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.

close

public void close()
           throws java.io.IOException
Description copied from interface: RecordManager
Closes the record manager and release resources. Record manager can not be used after it was closed

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

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

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

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