|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.helidb.impl.AbstractDatabase<K,V,P>
org.helidb.impl.txn.AbstractTransactionalDatabase<K,V,P>
K
- The type of the keys in the database.V
- The type of the values in the database.P
- The type of positions used by the
DatabaseBackend
to locate records.public abstract class AbstractTransactionalDatabase<K,V,P>
This abstract class can be extended by subclasses that implement a
transactional database. It implements all methods of the
TransactionalDatabase
. Subclasses only have to implement the abstract
methods of this class and of AbstractDatabase
.
When participating in a read/write transaction, this database is locked by a database-global, exclusive write lock. When participating in a read only transaction, it is locked by a database-global, shared read lock that can be shared by other read only transactions.
The inherited equals(Object)
and hashCode()
methods are
overridden by this class and they no longer follow the contract from
Map
since that would require a transaction every time that
they were called.
Nested Class Summary |
---|
Nested classes/interfaces inherited from interface java.util.Map |
---|
Map.Entry<K,V> |
Constructor Summary | |
---|---|
protected |
AbstractTransactionalDatabase(LogAdapterHolder lah)
|
Method Summary | |
---|---|
protected void |
cleanupBeforeReleasingReadLock()
This method is called to clean up the database state before releasing the read lock for a read only transaction. |
void |
close()
This method overrides the inherited close method to acquire a
write lock on the database before calling super.close() . |
protected void |
closeWithWriteLockOnDb()
This method is called by close() when it has acquired an
exclusive write lock on the database. |
protected abstract TransactionCollaborator<K,V,P> |
createReadOnlyCollaborator(Lock readLock)
Create a TransactionCollaborator for a read only transaction. |
protected abstract TransactionCollaborator<K,V,P> |
createReadWriteCollaborator(Lock writeLock)
Create a TransactionCollaborator for a read/write transaction. |
boolean |
equals(Object o)
Not implemented according to the contract in Map since
that would require a transaction. |
protected DatabaseBackend<K,V,P> |
getBackendForReading()
Get a readable database backend. |
protected DatabaseBackend<K,V,P> |
getBackendForWriting()
Get a writable database backend. |
protected Observable |
getCloseObservable()
Get an observable that notifies its observers when the database is closed. |
protected ReadWriteLock |
getLock()
Get the database's ReadWriteLock . |
int |
hashCode()
Not implemented according to the contract in Map since
that would require a transaction. |
boolean |
isClosed()
This method overrides the inherited isClosed method to acquire a
read lock on the database before calling super.isClosed() . |
void |
joinTransaction(boolean readOnly)
Manually join the calling thread's transaction. |
Methods inherited from class org.helidb.impl.AbstractDatabase |
---|
assertNotClosed, clear, closeBackend, compact, containsKey, containsValue, delete, entrySet, fasterInsert, find, find, find, firstRecord, get, getLogAdapterHolder, insert, insertOrUpdate, isEmpty, iterator, keyIterator, keySet, lastRecord, put, putAll, remove, size, update, valueIterator, values |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface org.helidb.Database |
---|
compact, delete, fasterInsert, find, find, find, firstRecord, insert, insertOrUpdate, keyIterator, lastRecord, update, valueIterator |
Methods inherited from interface java.util.Map |
---|
clear, containsKey, containsValue, entrySet, get, isEmpty, keySet, put, putAll, remove, size, values |
Methods inherited from interface java.lang.Iterable |
---|
iterator |
Constructor Detail |
---|
protected AbstractTransactionalDatabase(LogAdapterHolder lah)
Method Detail |
---|
protected void cleanupBeforeReleasingReadLock()
This method does nothing. Subclasses may override it.
protected abstract TransactionCollaborator<K,V,P> createReadOnlyCollaborator(Lock readLock)
TransactionCollaborator
for a read only transaction.
readLock
- A locked, shared read lock for the database. The
collaborator is responsible for releasing this lock when it is committed
or rolled back.
protected abstract TransactionCollaborator<K,V,P> createReadWriteCollaborator(Lock writeLock)
TransactionCollaborator
for a read/write transaction.
writeLock
- A locked, exclusive write lock for the database. The
collaborator is responsible for releasing this lock when it is committed
or rolled back.
protected Observable getCloseObservable()
protected ReadWriteLock getLock()
ReadWriteLock
.
ReadWriteLock
.public void joinTransaction(boolean readOnly)
TransactionalDatabase
joinTransaction
in interface TransactionalDatabase<K,V>
readOnly
- Should this database join the transaction as read only?protected DatabaseBackend<K,V,P> getBackendForWriting() throws NoTransactionException, ReadOnlyTransactionException, WrappedIOException
If this database does not already participate in a read/write transaction, this method joins the current transaction and copies the database backend file to a temporary location for writing.
getBackendForWriting
in class AbstractDatabase<K,V,P>
NoTransactionException
- If there is no current transaction.
ReadOnlyTransactionException
- If the current transaction is read
only.
WrappedIOException
- If there is an error copying the database file
when joining a read/write transaction.protected DatabaseBackend<K,V,P> getBackendForReading() throws NoTransactionException, WrappedIOException
If this database does not already participate in a read only or read/write transaction, this method joins the current transaction. If the current transaction is read/write, the database backend file is copied to a temporary location when joining.
getBackendForReading
in class AbstractDatabase<K,V,P>
NoTransactionException
- If there is no current transaction.
WrappedIOException
- If there is an error copying the database file
when joining a read/write transaction.protected void closeWithWriteLockOnDb()
close()
when it has acquired an
exclusive write lock on the database. Subclasses may override this
method, but they should remember to call super.closeWithWriteLockOnDb()
.
public void close()
close
method to acquire a
write lock on the database before calling super.close()
.
close
in interface Database<K,V>
close
in class AbstractDatabase<K,V,P>
public boolean isClosed()
isClosed
method to acquire a
read lock on the database before calling super.isClosed()
.
isClosed
in interface Database<K,V>
isClosed
in class AbstractDatabase<K,V,P>
true
if this database is closed.public boolean equals(Object o)
Map
since
that would require a transaction.
equals
in interface Map<K,V>
equals
in class AbstractDatabase<K,V,P>
public int hashCode()
Map
since
that would require a transaction.
hashCode
in interface Map<K,V>
hashCode
in class AbstractDatabase<K,V,P>
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |