|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.apache.commons.transaction.DefaultTransaction
public class DefaultTransaction
Default implementation for the Transaction interface. Needs a common
lock manager shared by all resource managers to make detection of distributed
deadlocks possible.
Sample usage:
LockManager<Object, Object> lm = new RWLockManager<Object, Object>();
Transaction t = new DefaultTransaction(lm);
TxMap<String, Object> txMap1 = new PessimisticTxMap<String, Object>("TxMap1");
t.enlistResourceManager(txMap1);
TxMap<String, Object> txMap2 = new PessimisticTxMap<String, Object>("TxMap2");
t.enlistResourceManager(txMap2);
try {
t.start(60, TimeUnit.SECONDS);
txMap1.put("Olli", "Huhu");
txMap2.put("Olli", "Haha");
t.commit();
} catch (Throwable throwable) {
t.rollback();
}
This implementation is thread-safe.
| Field Summary | |
|---|---|
protected LockManager<Object,Object> |
lm
|
protected List<ManageableResourceManager> |
rms
|
protected boolean |
started
|
| Constructor Summary | |
|---|---|
DefaultTransaction()
Creates a new transaction implementation using the default lock manager. |
|
DefaultTransaction(LockManager<Object,Object> lm)
Creates a new transaction implementation. |
|
| Method Summary | |
|---|---|
void |
commit()
Commits the complex transaction meaning that all changes made to participating resource managers are made permanent. |
void |
enlistResourceManager(ManageableResourceManager resourceManager)
Adds a resource manager to this complex transaction. |
boolean |
isRollbackOnly()
Checks whether this transaction allows a rollback as the only valid outcome. |
protected boolean |
prepare()
|
void |
rollback()
Rolls back the complex transaction meaning that all changes made to participating resource managers are undone. |
void |
start(long timeout,
TimeUnit unit)
Starts a new transactions having a specific timeout. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected LockManager<Object,Object> lm
protected boolean started
protected List<ManageableResourceManager> rms
| Constructor Detail |
|---|
public DefaultTransaction(LockManager<Object,Object> lm)
lm - the lock manager shared by all resource managerspublic DefaultTransaction()
| Method Detail |
|---|
public void commit()
throws TransactionException
Transaction
commit in interface TransactionTransactionExceptionpublic void enlistResourceManager(ManageableResourceManager resourceManager)
Transaction
enlistResourceManager in interface TransactionresourceManager - the resource manager to addpublic boolean isRollbackOnly()
Transaction
isRollbackOnly in interface Transactiontrue if this transaction can only rolled backpublic void rollback()
Transaction
rollback in interface Transaction
public void start(long timeout,
TimeUnit unit)
Transactionadd resource managers
before start or afterwards.
start in interface Transactiontimeout - the maximum time this transaction can run before it times outunit - the time unit of the timeout argumentprotected boolean prepare()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||