public final class BaseRecordManager extends Object implements RecordManager
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.
| Modifier and Type | Field and Description |
|---|---|
static boolean |
DEBUG
Static debugging flag
|
static int |
NAME_DIRECTORY_ROOT
Reserved slot for name directory.
|
| Constructor and Description |
|---|
BaseRecordManager(String filename)
Creates a record manager for the indicated file
|
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Closes the record manager.
|
void |
commit()
Commit (make persistent) all changes since beginning of transaction.
|
void |
delete(long recid)
Deletes a record.
|
void |
disableTransactions()
Switches off transactions for the record manager.
|
Object |
fetch(long recid)
Fetches a record using standard java object serialization.
|
Object |
fetch(long recid,
Serializer serializer)
Fetches a record using a custom serializer.
|
long |
getNamedObject(String name)
Obtain the record id of a named object.
|
long |
getRoot(int id)
Returns the indicated root rowid.
|
int |
getRootCount()
Returns the number of slots available for "root" rowids.
|
TransactionManager |
getTransactionManager()
Get the underlying Transaction Manager
|
long |
insert(Object obj)
Inserts a new record using standard java object serialization.
|
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 object serialization.
|
void |
update(long recid,
Object obj,
Serializer serializer)
Updates a record using a custom serializer.
|
public static final int NAME_DIRECTORY_ROOT
public static final boolean DEBUG
public BaseRecordManager(String filename) throws IOException
IOException - when the file cannot be opened or is not
a valid file content-wise.public TransactionManager getTransactionManager() throws IOException
IOExceptionpublic void disableTransactions()
Only call this method directly after opening the file, otherwise the results will be undefined.
public void close()
throws IOException
close in interface RecordManagerIOException - when one of the underlying I/O operations fails.public long insert(Object obj) throws IOException
insert in interface RecordManagerobj - the object for the new record.IOException - when one of the underlying I/O operations fails.public long insert(Object obj, Serializer serializer) throws IOException
insert in interface RecordManagerobj - the object for the new record.serializer - a custom serializerIOException - when one of the underlying I/O operations fails.public void delete(long recid)
throws IOException
delete in interface RecordManagerrecid - the rowid for the record that should be deleted.IOException - when one of the underlying I/O operations fails.public void update(long recid,
Object obj)
throws IOException
update in interface RecordManagerrecid - the recid for the record that is to be updated.obj - the new object for the record.IOException - when one of the underlying I/O operations fails.public void update(long recid,
Object obj,
Serializer serializer)
throws IOException
update in interface RecordManagerrecid - the recid for the record that is to be updated.obj - the new object for the record.serializer - a custom serializerIOException - when one of the underlying I/O operations fails.public Object fetch(long recid) throws IOException
fetch in interface RecordManagerrecid - the recid for the record that must be fetched.IOException - when one of the underlying I/O operations fails.public Object fetch(long recid, Serializer serializer) throws IOException
fetch in interface RecordManagerrecid - the recid for the record that must be fetched.serializer - a custom serializerIOException - when one of the underlying I/O operations fails.public int getRootCount()
getRootCount in interface RecordManagerpublic long getRoot(int id)
throws IOException
getRoot in interface RecordManagerIOExceptiongetRootCount()public void setRoot(int id,
long rowid)
throws IOException
setRoot in interface RecordManagerIOExceptiongetRootCount()public long getNamedObject(String name) throws IOException
getNamedObject in interface RecordManagerIOExceptionpublic void setNamedObject(String name, long recid) throws IOException
setNamedObject in interface RecordManagerIOExceptionpublic void commit()
throws IOException
commit in interface RecordManagerIOExceptionpublic void rollback()
throws IOException
rollback in interface RecordManagerIOExceptionCopyright © 2003–2014 The Apache Software Foundation. All rights reserved.