org.helidb.impl.txn
Class SharedReadLockReadOnlyTxnCollaborator<K,V,P>

java.lang.Object
  extended by org.helidb.impl.txn.SharedReadLockReadOnlyTxnCollaborator<K,V,P>
Type Parameters:
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.
All Implemented Interfaces:
TransactionCollaborator<K,V,P>

public final class SharedReadLockReadOnlyTxnCollaborator<K,V,P>
extends Object
implements TransactionCollaborator<K,V,P>

This is a generic TransactionCollaborator for read only transactions.

Since:
1.0
Author:
Karl Gustafsson
In_jar:
helidb-core

Constructor Summary
SharedReadLockReadOnlyTxnCollaborator(DatabaseBackend<K,V,P> backend, Lock backendReadLock, LogAdapterHolder lah)
          Create a collaborator for a read only transaction.
 
Method Summary
 void commit()
          Commit this collaborator's work.
protected  void finalize()
          Unlocks the backend read lock if it is still locked before calling super.finalize().
 DatabaseBackend<K,V,P> getBackend()
          Get the database's DatabaseBackend object.
 String getReasonForUnableToCommit()
          Can this collaborator commit its changes? If not, why?
 boolean isFinished()
          Has this collaborator finished or rolled back its part of the transaction?
 boolean isReadOnly()
          Does this collaborator's Database participate in the transaction read only?
 void rollback()
          Roll back this collaborator's work.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SharedReadLockReadOnlyTxnCollaborator

public SharedReadLockReadOnlyTxnCollaborator(DatabaseBackend<K,V,P> backend,
                                             Lock backendReadLock,
                                             LogAdapterHolder lah)
Create a collaborator for a read only transaction.

Parameters:
backend - The database backend.
backendReadLock - A locked read lock for the database. This lock is released when the transaction is committed or rolled back.
lah - A log adapter holder.
Method Detail

isReadOnly

public boolean isReadOnly()
Description copied from interface: TransactionCollaborator
Does this collaborator's Database participate in the transaction read only?

Specified by:
isReadOnly in interface TransactionCollaborator<K,V,P>
Returns:
true, always.

isFinished

public boolean isFinished()
Description copied from interface: TransactionCollaborator
Has this collaborator finished or rolled back its part of the transaction?

Specified by:
isFinished in interface TransactionCollaborator<K,V,P>
Returns:
true if this collaborator has finished or rolled back its part of the transaction.

getBackend

public DatabaseBackend<K,V,P> getBackend()
Description copied from interface: TransactionCollaborator
Get the database's DatabaseBackend object.

Specified by:
getBackend in interface TransactionCollaborator<K,V,P>
Returns:
The database's DatabaseBackend object.

rollback

public void rollback()
Description copied from interface: TransactionCollaborator
Roll back this collaborator's work.

This method should try to avoid throwing exceptions since that may put the resources participating in the entire transaction in an undefined state.

Specified by:
rollback in interface TransactionCollaborator<K,V,P>

getReasonForUnableToCommit

public String getReasonForUnableToCommit()
Description copied from interface: TransactionCollaborator
Can this collaborator commit its changes? If not, why?

Specified by:
getReasonForUnableToCommit in interface TransactionCollaborator<K,V,P>
Returns:
null if the collaborator is able to commit its changes to its database, or a reason for why it cannot.

commit

public void commit()
Description copied from interface: TransactionCollaborator
Commit this collaborator's work. This is called for each collaborator participating in a transaction after TransactionCollaborator.getReasonForUnableToCommit() has been called on all collaborators.

This method should really not throw any exceptions since that would put the resources participating in the entire transaction in an undefined state. If the collaborator cannot commit the work in the database, it should say so when asked via the TransactionCollaborator.getReasonForUnableToCommit().

Specified by:
commit in interface TransactionCollaborator<K,V,P>

finalize

protected void finalize()
                 throws Throwable
Unlocks the backend read lock if it is still locked before calling super.finalize().

Overrides:
finalize in class Object
Throws:
Throwable