| java.lang.Object jdbm.recman.BaseRecordManager
BaseRecordManager | final public class BaseRecordManager implements RecordManager(Code) | | 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.
author: Alex Boisvert author: Cees de Groot version: $Id: BaseRecordManager.java,v 1.8 2005/06/25 23:12:32 doomdark Exp $ |
Field Summary | |
final public static boolean | DEBUG | final public static int | NAME_DIRECTORY_ROOT Reserved slot for name directory. |
Method Summary | |
public synchronized void | close() Closes the record manager. | public synchronized void | commit() Commit (make persistent) all changes since beginning of transaction. | public synchronized void | delete(long recid) Deletes a record. | public synchronized void | disableTransactions() Switches off transactioning for the record manager. | public Object | fetch(long recid) Fetches a record using standard java object serialization.
Parameters: recid - the recid for the record that must be fetched. | public synchronized Object | fetch(long recid, Serializer serializer) Fetches a record using a custom serializer. | public long | getNamedObject(String name) Obtain the record id of a named object. | public synchronized long | getRoot(int id) Returns the indicated root rowid. | public int | getRootCount() Returns the number of slots available for "root" rowids. | public synchronized TransactionManager | getTransactionManager() | public long | insert(Object obj) Inserts a new record using standard java object serialization.
Parameters: obj - the object for the new record. | public synchronized long | insert(Object obj, Serializer serializer) Inserts a new record using a custom serializer. | public synchronized void | rollback() Rollback (cancel) all changes since beginning of transaction. | public void | setNamedObject(String name, long recid) Set the record id of a named object. | public synchronized void | setRoot(int id, long rowid) Sets the indicated root rowid. | public void | update(long recid, Object obj) Updates a record using standard java object serialization. | public synchronized void | update(long recid, Object obj, Serializer serializer) Updates a record using a custom serializer. |
DEBUG | final public static boolean DEBUG(Code) | | Static debugging flag
|
NAME_DIRECTORY_ROOT | final public static int NAME_DIRECTORY_ROOT(Code) | | Reserved slot for name directory.
|
BaseRecordManager | public BaseRecordManager(String filename) throws IOException(Code) | | Creates a record manager for the indicated file
throws: IOException - when the file cannot be opened or is nota valid file content-wise. |
close | public synchronized void close() throws IOException(Code) | | Closes the record manager.
throws: IOException - when one of the underlying I/O operations fails. |
commit | public synchronized void commit() throws IOException(Code) | | Commit (make persistent) all changes since beginning of transaction.
|
delete | public synchronized void delete(long recid) throws IOException(Code) | | Deletes a record.
Parameters: recid - the rowid for the record that should be deleted. throws: IOException - when one of the underlying I/O operations fails. |
disableTransactions | public synchronized void disableTransactions()(Code) | | 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.
|
fetch | public Object fetch(long recid) throws IOException(Code) | | Fetches a record using standard java object serialization.
Parameters: recid - the recid for the record that must be fetched. the object contained in the record. throws: IOException - when one of the underlying I/O operations fails. |
fetch | public synchronized Object fetch(long recid, Serializer serializer) throws IOException(Code) | | Fetches a record using a custom serializer.
Parameters: recid - the recid for the record that must be fetched. Parameters: serializer - a custom serializer the object contained in the record. throws: IOException - when one of the underlying I/O operations fails. |
getNamedObject | public long getNamedObject(String name) throws IOException(Code) | | Obtain the record id of a named object. Returns 0 if named object
doesn't exist.
|
getRootCount | public int getRootCount()(Code) | | 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.
|
getTransactionManager | public synchronized TransactionManager getTransactionManager()(Code) | | Get the underlying Transaction Manager
|
insert | public long insert(Object obj) throws IOException(Code) | | Inserts a new record using standard java object serialization.
Parameters: obj - the object for the new record. the rowid for the new record. throws: IOException - when one of the underlying I/O operations fails. |
insert | public synchronized long insert(Object obj, Serializer serializer) throws IOException(Code) | | Inserts a new record using a custom serializer.
Parameters: obj - the object for the new record. Parameters: serializer - a custom serializer the rowid for the new record. throws: IOException - when one of the underlying I/O operations fails. |
rollback | public synchronized void rollback() throws IOException(Code) | | Rollback (cancel) all changes since beginning of transaction.
|
setNamedObject | public void setNamedObject(String name, long recid) throws IOException(Code) | | Set the record id of a named object.
|
update | public void update(long recid, Object obj) throws IOException(Code) | | Updates a record using standard java object serialization.
Parameters: recid - the recid for the record that is to be updated. Parameters: obj - the new object for the record. throws: IOException - when one of the underlying I/O operations fails. |
update | public synchronized void update(long recid, Object obj, Serializer serializer) throws IOException(Code) | | Updates a record using a custom serializer.
Parameters: recid - the recid for the record that is to be updated. Parameters: obj - the new object for the record. Parameters: serializer - a custom serializer throws: IOException - when one of the underlying I/O operations fails. |
|
|