public final class Transaction extends Object implements IDisposable
TransactionContext
. A transaction
will only successfully commit if no update it has made conflicts with any
concurrent updates that have been committed since the transaction was started.Constructor and Description |
---|
Transaction(TransactionContext context)
Begins a new transaction.
|
Modifier and Type | Method and Description |
---|---|
void |
abort()
Aborts this transactions.
|
void |
addModification(TransactedObject modifiedObject,
Object details)
Adds a modification to this transaction.
|
void |
commit()
Commits this transaction so that its changes are visible to other transactions.
|
void |
dispose()
Disposes this transaction.
|
TransactionContext |
getContext()
Gets the transaction context in which this transaction operates.
|
boolean |
getIsActive()
Gets a value indicating whether or not this transaction is still active.
|
long |
getNumber()
Gets the number of this transaction.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
close
public Transaction(TransactionContext context)
IDisposable.close()
,
Transaction.commit()
, or Transaction.abort()
this transaction as soon as you
are done using it. Keeping transactions open for a long time will substantially
increase the memory usage and slow the performance of the software transactional
memory system. You should generally use
TransactionContext.doTransactionally(agi.foundation.compatibility.Action1<agi.foundation.Transaction>)
instead of constructing a transaction directly.context
- The context in which this transaction operates. The new transaction can only be used to
access transacted values in this context.public final void dispose()
dispose
in interface IDisposable
public final TransactionContext getContext()
public final long getNumber()
public final boolean getIsActive()
Transaction.commit()
,
Transaction.abort()
, or IDisposable.close()
is called on it.public final void commit()
TransactionConflictException
if another transaction
modifies one of the same values as this transaction and the other transaction commits first.
Use TransactionContext.doTransactionally(agi.foundation.compatibility.Action1<agi.foundation.Transaction>)
to automatically retry conflicting
exceptions.TransactionConflictException
- Raised when another transaction modifies one of the same values as this one and the other
transaction commits first. It can also be raised when a method like
TransactedProperty.ensureValue(agi.foundation.Transaction)
has been called within this transaction
and the value was changed by another transaction. Use
TransactionContext.doTransactionally(agi.foundation.compatibility.Action1<agi.foundation.Transaction>)
to automatically retry conflicting exceptions.public final void abort()
public final void addModification(TransactedObject modifiedObject, Object details)
TransactedObject
implementations.modifiedObject
- The modified object.details
- Details about the modification that will be passed to the modified object's
TransactedObject.commit(agi.foundation.Transaction, java.lang.Object)
, TransactedObject.abort(agi.foundation.Transaction, java.lang.Object)
,
TransactedObject.cleanup(java.lang.Object)
, and TransactedObject.validateModification(agi.foundation.Transaction, java.lang.Object)
methods.