jdbm.recman

## Class CacheRecordManager

- java.lang.Object
- - jdbm.recman.CacheRecordManager

All Implemented Interfaces:
  RecordManager

    public class CacheRecordManager
    extends Object
    implements RecordManager

A RecordManager wrapping and caching another RecordManager.

Author:
  Alex Boisvert, Cees de Groot

### Field Summary

Fields
`protected CachePolicy<Long,jdbm.recman.CacheRecordManager.CacheEntry>` `cache` Cache for underlying RecordManager
`protected RecordManager` `recordManager` Wrapped RecordManager

### Fields inherited from interface jdbm.RecordManager

`NAME_DIRECTORY_ROOT`

### Constructor Summary

Constructors
Constructor and Description
`CacheRecordManager(RecordManager recordManager, CachePolicy<Long,jdbm.recman.CacheRecordManager.CacheEntry> cache)` Construct a CacheRecordManager wrapping another RecordManager and using a given cache policy.

### Method Summary

Methods
`void` `close()` Closes the record manager.
`void` `commit()` Commit (make persistent) all changes since beginning of transaction.
`void` `delete(long recid)` Deletes a record.
`Object` `fetch(long recid)` Fetches a record using standard Java serialization.
`Object` `fetch(long recid, Serializer serializer)` Fetches a record using a custom serializer.
`CachePolicy<Long,jdbm.recman.CacheRecordManager.CacheEntry>` `getCachePolicy()` Get the underlying cache policy
`long` `getNamedObject(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(Object obj)` Inserts a new record using a custom serializer.
`long` `insert(Object obj, Serializer serializer)` Inserts a new record using a custom serializer.
`void` `rollback()` Rollback (cancel) all changes since beginning of transaction.
`void` `setNamedObject(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, Object obj)` Updates a record using standard Java serialization.
`void` `update(long recid, Object obj, Serializer serializer)` Updates a record using a custom serializer.
`protected void` `updateCacheEntries()` Update all dirty cache objects to the underlying RecordManager.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Field Detail

#### recordManager

    protected RecordManager recordManager

Wrapped RecordManager

#### cache

    protected CachePolicy<Long,jdbm.recman.CacheRecordManager.CacheEntry> cache

Cache for underlying RecordManager

### Constructor Detail

#### CacheRecordManager

    public CacheRecordManager(RecordManager recordManager,
                      CachePolicy<Long,jdbm.recman.CacheRecordManager.CacheEntry> cache)

Construct a CacheRecordManager wrapping another RecordManager and using a given cache policy.

Parameters:
  `recordManager` - 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<Long,jdbm.recman.CacheRecordManager.CacheEntry> getCachePolicy()

Get the underlying cache policy

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

#### insert

    public long insert(Object obj)
                throws 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:
  `IOException` - when one of the underlying I/O operations fails.

#### insert

    public long insert(Object obj,
              Serializer serializer)
                throws 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:
  `IOException` - when one of the underlying I/O operations fails.

#### delete

    public void delete(long recid)
                throws IOException

Deletes a record.

Specified by:
  `delete` in interface `RecordManager`
Parameters:
  `recid` - 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,
              Object obj)
                throws 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:
  `IOException` - when one of the underlying I/O operations fails.

#### update

    public void update(long recid,
              Object obj,
              Serializer serializer)
                throws 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:
  `IOException` - when one of the underlying I/O operations fails.

#### fetch

    public Object fetch(long recid)
                 throws 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:
  `IOException` - when one of the underlying I/O operations fails.

#### fetch

    public Object fetch(long recid,
               Serializer serializer)
                 throws 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:
  `IOException` - when one of the underlying I/O operations fails.

#### close

    public void close()
               throws IOException

Closes the record manager.

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

Specified by:
  `getRootCount` in interface `RecordManager`

#### getRoot

    public long getRoot(int id)
                 throws IOException

Returns the indicated root rowid.

Specified by:
  `getRoot` in interface `RecordManager`
Throws:
  `IOException`
See Also:
  `getRootCount()`

#### setRoot

    public void setRoot(int id,
               long rowid)
                 throws IOException

Sets the indicated root rowid.

Specified by:
  `setRoot` in interface `RecordManager`
Throws:
  `IOException`
See Also:
  `getRootCount()`

#### commit

    public void commit()
                throws IOException

Commit (make persistent) all changes since beginning of transaction.

Specified by:
  `commit` in interface `RecordManager`
Throws:
  `IOException`

#### rollback

    public void rollback()
                  throws IOException

Rollback (cancel) all changes since beginning of transaction.

Specified by:
  `rollback` in interface `RecordManager`
Throws:
  `IOException`

#### getNamedObject

    public long getNamedObject(String name)
                        throws IOException

Obtain the record id of a named object. Returns 0 if named object doesn't exist.

Specified by:
  `getNamedObject` in interface `RecordManager`
Throws:
  `IOException`

#### setNamedObject

    public void setNamedObject(String name,
                      long recid)
                        throws IOException

Set the record id of a named object.

Specified by:
  `setNamedObject` in interface `RecordManager`
Throws:
  `IOException`

#### updateCacheEntries

    protected void updateCacheEntries()
                               throws IOException

Update all dirty cache objects to the underlying RecordManager.

Throws:
  `IOException`