public final class BaseRecordManager extends java.lang.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 | Class and Description |
|---|---|
private static class |
BaseRecordManager.IOType |
private static class |
BaseRecordManager.LockElement
TODO add asserts to check internal consistency
|
| Modifier and Type | Field and Description |
|---|---|
static boolean |
DEBUG
Static debugging flag
|
private java.util.concurrent.ConcurrentHashMap<java.lang.Long,BaseRecordManager.LockElement> |
lockElements
Map used to synchronize reads and writes on the same logical
recid.
|
private static org.slf4j.Logger |
LOG
A logger for this class
|
private LogicalRowIdManager |
logMgr
Logical to Physical row identifier manager.
|
static int |
NAME_DIRECTORY_ROOT
Reserved slot for name directory.
|
private java.util.Map<java.lang.String,java.lang.Long> |
nameDirectory
Directory of named JDBMHashtables.
|
private PageManager |
pageMgr
Page manager.
|
private PhysicalRowIdManager |
physMgr
Physical row identifier manager.
|
private RecordFile |
recordFile
Underlying record recordFile.
|
| Constructor and Description |
|---|
BaseRecordManager(java.lang.String filename)
Creates a record manager for the indicated file
|
| Modifier and Type | Method and Description |
|---|---|
private BaseRecordManager.LockElement |
beginIO(java.lang.Long recid,
BaseRecordManager.IOType io)
Used to serialize reads/write on a given logical rowid.
|
private void |
checkIfClosed()
Check if RecordManager has been closed.
|
void |
close()
Closes the record manager.
|
void |
commit()
Commit (make persistent) all changes since beginning of transaction.
|
private boolean |
conflictingIOPredicate(BaseRecordManager.IOType io,
BaseRecordManager.LockElement element) |
void |
delete(long recid)
Deletes a record.
|
void |
disableTransactions()
Switches off transactions for the record manager.
|
private void |
endIO(java.lang.Long recid,
BaseRecordManager.LockElement element,
BaseRecordManager.IOType io)
Ends the IO by releasing the logical lock on the given recid
|
java.lang.Object |
fetch(long recid)
Fetches a record using standard java object serialization.
|
java.lang.Object |
fetch(long recid,
Serializer serializer)
Fetches a record using a custom serializer.
|
private java.util.Map<java.lang.String,java.lang.Long> |
getNameDirectory()
Load name directory
|
long |
getNamedObject(java.lang.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(java.lang.Object obj)
Inserts a new record using standard java object serialization.
|
long |
insert(java.lang.Object obj,
Serializer serializer)
Inserts a new record using a custom serializer.
|
void |
rollback()
Rollback (cancel) all changes since beginning of transaction.
|
private void |
saveNameDirectory() |
void |
setNamedObject(java.lang.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,
java.lang.Object obj)
Updates a record using standard java object serialization.
|
void |
update(long recid,
java.lang.Object obj,
Serializer serializer)
Updates a record using a custom serializer.
|
private static final org.slf4j.Logger LOG
private RecordFile recordFile
private PhysicalRowIdManager physMgr
private LogicalRowIdManager logMgr
private PageManager pageMgr
public static final int NAME_DIRECTORY_ROOT
public static final boolean DEBUG
private java.util.Map<java.lang.String,java.lang.Long> nameDirectory
private final java.util.concurrent.ConcurrentHashMap<java.lang.Long,BaseRecordManager.LockElement> lockElements
public BaseRecordManager(java.lang.String filename)
throws java.io.IOException
java.io.IOException - when the file cannot be opened or is not
a valid file content-wise.public TransactionManager getTransactionManager() throws java.io.IOException
java.io.IOExceptionpublic void disableTransactions()
Only call this method directly after opening the file, otherwise the results will be undefined.
public void close()
throws java.io.IOException
close in interface RecordManagerjava.io.IOException - when one of the underlying I/O operations fails.public long insert(java.lang.Object obj)
throws java.io.IOException
insert in interface RecordManagerobj - the object for the new record.java.io.IOException - when one of the underlying I/O operations fails.public long insert(java.lang.Object obj,
Serializer serializer)
throws java.io.IOException
insert in interface RecordManagerobj - the object for the new record.serializer - a custom serializerjava.io.IOException - when one of the underlying I/O operations fails.public void delete(long recid)
throws java.io.IOException
delete in interface RecordManagerrecid - the rowid for the record that should be deleted.java.io.IOException - when one of the underlying I/O operations fails.public void update(long recid,
java.lang.Object obj)
throws java.io.IOException
update in interface RecordManagerrecid - the recid for the record that is to be updated.obj - the new object for the record.java.io.IOException - when one of the underlying I/O operations fails.public void update(long recid,
java.lang.Object obj,
Serializer serializer)
throws java.io.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 serializerjava.io.IOException - when one of the underlying I/O operations fails.public java.lang.Object fetch(long recid)
throws java.io.IOException
fetch in interface RecordManagerrecid - the recid for the record that must be fetched.java.io.IOException - when one of the underlying I/O operations fails.public java.lang.Object fetch(long recid,
Serializer serializer)
throws java.io.IOException
fetch in interface RecordManagerrecid - the recid for the record that must be fetched.serializer - a custom serializerjava.io.IOException - when one of the underlying I/O operations fails.public int getRootCount()
getRootCount in interface RecordManagerpublic long getRoot(int id)
throws java.io.IOException
getRoot in interface RecordManagerjava.io.IOExceptiongetRootCount()public void setRoot(int id,
long rowid)
throws java.io.IOException
setRoot in interface RecordManagerjava.io.IOExceptiongetRootCount()public long getNamedObject(java.lang.String name)
throws java.io.IOException
getNamedObject in interface RecordManagerjava.io.IOExceptionpublic void setNamedObject(java.lang.String name,
long recid)
throws java.io.IOException
setNamedObject in interface RecordManagerjava.io.IOExceptionpublic void commit()
throws java.io.IOException
commit in interface RecordManagerjava.io.IOExceptionpublic void rollback()
throws java.io.IOException
rollback in interface RecordManagerjava.io.IOExceptionprivate java.util.Map<java.lang.String,java.lang.Long> getNameDirectory()
throws java.io.IOException
java.io.IOExceptionprivate void saveNameDirectory()
throws java.io.IOException
java.io.IOExceptionprivate void checkIfClosed()
throws java.lang.IllegalStateException
java.lang.IllegalStateExceptionprivate BaseRecordManager.LockElement beginIO(java.lang.Long recid, BaseRecordManager.IOType io)
recid - the logical rowid for which the fetch will be done.io - type of the IOprivate void endIO(java.lang.Long recid,
BaseRecordManager.LockElement element,
BaseRecordManager.IOType io)
recid - logical recid for which the IO is being endedelement - logical lock to be releasedio - type of the ioprivate boolean conflictingIOPredicate(BaseRecordManager.IOType io, BaseRecordManager.LockElement element)