jdbm
Interface RecordManager

All Known Implementing Classes:
BaseRecordManager, CacheRecordManager, RecordManagerImpl

public interface RecordManager

An interface to manages records, which are objects serialized to byte[] on background.

The set of record operations is simple: fetch, insert, update and delete. Each record is identified using a "rowid" and contains a byte[] data block serialized to object. Rowids are returned on inserts and you can store them 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.

RecordManager is responsible for handling transactions. JDBM2 supports only single transaction for data store. See commit and roolback methods for more details.

RecordManader is also factory for primary Maps.

Author:
Jan Kotek, Alex Boisvert, Cees de Groot

Field Summary
static long NULL_RECID
          Recid indicating no record (e.g.
 
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.
 java.lang.Object fetch(long recid)
          Fetches a record using standard java object serialization.
<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.
<K,V> PrimaryHashMap<K,V>
hashMap(java.lang.String name)
          Creates or load existing Primary Hash Map which persists data into DB.
<K,V> PrimaryHashMap<K,V>
hashMap(java.lang.String name, Serializer<K> keySerializer)
          Creates or load existing Primary Hash Map which persists data into DB.
<K,V> PrimaryHashMap<K,V>
hashMap(java.lang.String name, Serializer<K> keySerializer, Serializer<V> valueSerializer)
          Creates or load existing Primary Hash Map which persists data into DB.
<A> long
insert(A obj, Serializer<A> serializer)
          Inserts a new record using a custom serializer.
 long insert(java.lang.Object obj)
          Inserts a new record using standard java object serialization.
 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.
<V> PrimaryStoreMap<java.lang.Long,V>
storeMap(java.lang.String name)
          Creates or load existing Primary StoreMap which persists data into DB.
<V> PrimaryStoreMap<java.lang.Long,V>
storeMap(java.lang.String name, Serializer<V> valueSerializer)
          Creates or load existing StoreMap which persists data into DB.
<K extends java.lang.Comparable,V>
PrimaryTreeMap<K,V>
treeMap(java.lang.String name)
          Creates or load existing Primary TreeMap which persists data into DB.
<K,V> PrimaryTreeMap<K,V>
treeMap(java.lang.String name, java.util.Comparator<K> keyComparator)
          Creates or load existing TreeMap which persists data into DB.
<K,V> PrimaryTreeMap<K,V>
treeMap(java.lang.String name, java.util.Comparator<K> keyComparator, Serializer<V> valueSerializer)
          Creates or load existing TreeMap which persists data into DB.
<K,V> PrimaryTreeMap<K,V>
treeMap(java.lang.String name, java.util.Comparator<K> keyComparator, Serializer<V> valueSerializer, Serializer<K> keySerializer)
          Creates or load existing TreeMap which persists data into DB.
<K extends java.lang.Comparable,V>
PrimaryTreeMap<K,V>
treeMap(java.lang.String name, Serializer<V> valueSerializer)
          Creates or load existing TreeMap which persists data into DB.
<K extends java.lang.Comparable,V>
PrimaryTreeMap<K,V>
treeMap(java.lang.String name, Serializer<V> valueSerializer, Serializer<K> keySerializer)
          Creates or load existing TreeMap which persists data into DB.
<A> void
update(long recid, A obj, Serializer<A> serializer)
          Updates a record using a custom serializer.
 void update(long recid, java.lang.Object obj)
          Updates a record using standard java object serialization.
 

Field Detail

NULL_RECID

static final long NULL_RECID
Recid indicating no record (e.g. null)

See Also:
Constant Field Values
Method Detail

insert

long insert(java.lang.Object obj)
            throws java.io.IOException
Inserts a new record using standard java object serialization.

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

<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

void delete(long recid)
            throws java.io.IOException
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

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

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 or given recid does not exists.

update

<A> void update(long recid,
                A obj,
                Serializer<A> serializer)
            throws java.io.IOException
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

java.lang.Object fetch(long recid)
                       throws java.io.IOException
Fetches a record using standard java object serialization. If given recid does not exist, IOException will be thrown before/during commit (cache).

Parameters:
recid - the recid for the record that must be fetched.
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

<A> A fetch(long recid,
            Serializer<A> serializer)
        throws java.io.IOException
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

<A> A fetch(long recid,
            Serializer<A> serializer,
            boolean disableCache)
        throws java.io.IOException
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.

close

void close()
           throws java.io.IOException
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.

clearCache

void clearCache()
                throws java.io.IOException
Empty cache. This may be usefull if you need to release memory.

Throws:
java.io.IOException

defrag

void defrag()
            throws java.io.IOException
Defragments storage, so it consumes less space. This commits any uncommited data.

Throws:
java.io.IOException

commit

void commit()
            throws java.io.IOException
Commit (make persistent) all changes since beginning of transaction. JDBM supports only single transaction.

Throws:
java.io.IOException

rollback

void rollback()
              throws java.io.IOException
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

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. Named objects are used to store Map views and other well known objects.

Throws:
java.io.IOException

setNamedObject

void setNamedObject(java.lang.String name,
                    long recid)
                    throws java.io.IOException
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

hashMap

<K,V> PrimaryHashMap<K,V> hashMap(java.lang.String name)
Creates or load existing Primary Hash Map which persists data into DB.

Type Parameters:
K - Key type
V - Value type
Parameters:
name - record name
Returns:

hashMap

<K,V> PrimaryHashMap<K,V> hashMap(java.lang.String name,
                                  Serializer<K> keySerializer)
Creates or load existing Primary Hash Map which persists data into DB. This method uses custom serializer for keys.

Type Parameters:
K - Key type
V - Value type
Parameters:
name - record name
keySerializer - serializer to be used for Keys
Returns:

hashMap

<K,V> PrimaryHashMap<K,V> hashMap(java.lang.String name,
                                  Serializer<K> keySerializer,
                                  Serializer<V> valueSerializer)
Creates or load existing Primary Hash Map which persists data into DB. Map will use custom serializers for Keys and Values. Leave keySerializer null to use default serializer for keys

Type Parameters:
K - Key type
V - Value type
Parameters:
name - record name
keySerializer - serializer to be used for Keys, leave null to use default serializer
valueSerializer - serializer to be used for Values
Returns:

treeMap

<K extends java.lang.Comparable,V> PrimaryTreeMap<K,V> treeMap(java.lang.String name)
Creates or load existing Primary TreeMap which persists data into DB.

Type Parameters:
K - Key type
V - Value type
Parameters:
name - record name
Returns:

treeMap

<K extends java.lang.Comparable,V> PrimaryTreeMap<K,V> treeMap(java.lang.String name,
                                                               Serializer<V> valueSerializer)
Creates or load existing TreeMap which persists data into DB.

Type Parameters:
K - Key type
V - Value type
Parameters:
name - record name
valueSerializer - Serializer used for values. This may reduce disk space usage.
Returns:

treeMap

<K extends java.lang.Comparable,V> PrimaryTreeMap<K,V> treeMap(java.lang.String name,
                                                               Serializer<V> valueSerializer,
                                                               Serializer<K> keySerializer)
Creates or load existing TreeMap which persists data into DB.

Type Parameters:
K - Key type
V - Value type
Parameters:
name - record name
valueSerializer - Serializer used for values. This may reduce disk space usage.
keySerializer - Serializer used for keys. This may reduce disk space usage.
Returns:

treeMap

<K,V> PrimaryTreeMap<K,V> treeMap(java.lang.String name,
                                  java.util.Comparator<K> keyComparator)
Creates or load existing TreeMap which persists data into DB.

Type Parameters:
K - Key type
V - Value type
Parameters:
name - record name
keyComparator - Comparator used to sort keys
Returns:

treeMap

<K,V> PrimaryTreeMap<K,V> treeMap(java.lang.String name,
                                  java.util.Comparator<K> keyComparator,
                                  Serializer<V> valueSerializer)
Creates or load existing TreeMap which persists data into DB.

Type Parameters:
K - Key type
V - Value type
Parameters:
name - record name
keyComparator - Comparator used to sort keys
valueSerializer - Serializer used for values. This may reduce disk space usage
Returns:

treeMap

<K,V> PrimaryTreeMap<K,V> treeMap(java.lang.String name,
                                  java.util.Comparator<K> keyComparator,
                                  Serializer<V> valueSerializer,
                                  Serializer<K> keySerializer)
Creates or load existing TreeMap which persists data into DB.

Type Parameters:
K - Key type
V - Value type
Parameters:
name - record name
keyComparator - Comparator used to sort keys
valueSerializer - Serializer used for values. This may reduce disk space usage
keySerializer - Serializer used for keys. This may reduce disk space usage *
Returns:

storeMap

<V> PrimaryStoreMap<java.lang.Long,V> storeMap(java.lang.String name,
                                               Serializer<V> valueSerializer)
Creates or load existing StoreMap which persists data into DB.

Type Parameters:
V - Value type
Parameters:
name - record name
valueSerializer - Serializer used for values. This may reduce disk space usage
Returns:
map

storeMap

<V> PrimaryStoreMap<java.lang.Long,V> storeMap(java.lang.String name)
Creates or load existing Primary StoreMap which persists data into DB.

Type Parameters:
V - Value type
Parameters:
name - record name
Returns:
map


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