Package org.odmg
Interface Transaction
- All Known Implementing Classes:
RasTransaction
public interface Transaction
This interfaces provides the operations necessary to perform database transactions.
All access, creation, and modification of persistent objects and their fields
must be done within a transaction. Before performing any database operations,
a thread must explicitly create a transaction object or associate itself with
an existing transaction object (by calling
join),
and that transaction must be open (through a call to begin).
All subsequent operations by the thread, including reads, writes, and lock
acquisitions, are done under the thread's current transaction.
A thread may only operate on its current transaction. For example,
a TransactionNotInProgressException is thrown if a thread attempts
to begin, commit, checkpoint, or abort a transaction prior to joining itself
to that transaction.
A transaction is either open or closed. A transaction is open if a call
has been made to begin, but no call has been made to commit or
abort. Once commit or abort is called,
the transaction is closed. The method isOpen can be called to
determine the state of the transaction.
Read locks are implicitly obtained on objects as they are accessed.
Write locks are implicitly obtained as objects are modified.
Transaction objects are transient, they cannot be stored in the database.
- Author:
- David Jordan (as Java Editor of the Object Data Management Group)
- See Also:
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionvoidabort()Abort and close the transaction.voidbegin()Start a transaction.voidCommit the transaction, but reopen the transaction, retaining all locks.voidcommit()Commit and close the transaction.booleanisOpen()Determine whether the transaction is open or not.voidjoin()Attach the caller's thread to thisTransactionand detach the thread from any formerTransactionthe thread may have been associated with,
not yet available in rasdaman.voidleave()Detach the caller's thread from thisTransaction, but do not attach the thread to anotherTransaction,
not yet available in rasdaman.voidUpgrade the lock on the given object to the given lock mode,
not yet available in rasdaman.booleanUpgrade the lock on the given object to the given lock mode,
not yet available in rasdaman.
-
Field Details
-
READ
static final int READRead lock mode.- See Also:
-
UPGRADE
static final int UPGRADEUpgrade lock mode.- See Also:
-
WRITE
static final int WRITEWrite lock mode.- See Also:
-
-
Method Details
-
join
void join()Attach the caller's thread to thisTransactionand detach the thread from any formerTransactionthe thread may have been associated with,
not yet available in rasdaman. -
leave
void leave()Detach the caller's thread from thisTransaction, but do not attach the thread to anotherTransaction,
not yet available in rasdaman. -
begin
void begin()Start a transaction. Callingbeginmultiple times on the same transaction object, without an intervening call tocommitorabort, causes the exceptionTransactionInProgressExceptionto be thrown on the second and subsequent calls. Operations executed before a transaction has been opened, or before reopening after a transaction is aborted or committed, have undefined results; these may throw aTransactionNotInProgressExceptionexception. -
isOpen
boolean isOpen()Determine whether the transaction is open or not. A transaction is open if a call has been made tobegin, but a subsequent call to eithercommitoraborthas not been made.- Returns:
- True if the transaction is open, otherwise false.
-
commit
void commit()Commit and close the transaction. Callingcommitcommits to the database all persistent object modifications within the transaction and releases any locks held by the transaction. A persistent object modification is an update of any field of an existing persistent object, or an update or creation of a new named object in the database. If a persistent object modification results in a reference from an existing persistent object to a transient object, the transient object is moved to the database, and all references to it updated accordingly. Note that the act of moving a transient object to the database may create still more persistent references to transient objects, so its referents must be examined and moved as well. This process continues until the database contains no references to transient objects, a condition that is guaranteed as part of transaction commit. Committing a transaction does not remove from memory transient objects created during the transaction -
abort
void abort()Abort and close the transaction. Calling abort abandons all persistent object modifications and releases the associated locks. Aborting a transaction does not restore the state of modified transient objects -
checkpoint
void checkpoint()Commit the transaction, but reopen the transaction, retaining all locks. Callingcheckpointcommits persistent object modifications made within the transaction since the last checkpoint to the database. The transaction retains all locks it held on those objects at the time the checkpoint was invoked. -
lock
Upgrade the lock on the given object to the given lock mode,
not yet available in rasdaman. The call has no effect if the object's current lock is already at or above that level of lock mode.- Parameters:
obj- The object to acquire a lock on.lockMode- The lock mode to acquire. The lock modes areREAD,UPGRADE, andWRITE.- Throws:
LockNotGrantedException- Is thrown if the given lock mode could not be acquired.
-
tryLock
Upgrade the lock on the given object to the given lock mode,
not yet available in rasdaman. MethodtryLockis the same aslockexcept it returns a boolean indicating whether the lock was granted instead of generating an exception.- Parameters:
obj- The object to acquire a lock on.lockMode- The lock mode to acquire. The lock modes areREAD,UPGRADE, andWRITE.- Returns:
- True if the lock has been acquired, otherwise false.
-