|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjodd.jtx.JtxTransaction
public class JtxTransaction
Transaction is an unit of work that is performed by one or more resources.
Created and controlled by transaction manager
.
Transaction is associated to a thread from where it was created. Transaction may have more than one resource attached.
Committing and rolling back transaction actually performs commit/rollback on all attached resources. Therefore, it may happens that committing of one resource fails, what actually breaks the atomicity of the transaction. If transaction is attached just to one resource, atomicity is saved.
Only one resource of some type may exists in the transaction. There is no way to have two resources of the same type in one transaction.
This class is responsible for transaction life-cycle. It can be consider that all work is scoped to associated thread.
Field Summary | |
---|---|
protected long |
deadline
|
protected JtxTransactionMode |
mode
|
protected java.util.Set<jodd.jtx.JtxResource> |
resources
|
protected java.lang.Throwable |
rollbackCause
|
protected JtxStatus |
status
|
protected JtxTransactionManager |
txManager
|
Constructor Summary | |
---|---|
JtxTransaction(JtxTransactionManager txManager,
JtxTransactionMode mode)
Creates new transaction. |
Method Summary | ||
---|---|---|
protected void |
checkTimeout()
Sets the rollback-only if the deadline has been reached and throws an exception. |
|
void |
commit()
Commit and completes current transaction. |
|
protected void |
commitAllResources()
Commits all attached resources. |
|
protected void |
commitOrRollback(boolean doCommit)
Performs either commit or rollback on all transaction resources. |
|
JtxStatus |
getStatus()
Returns current transaction status. |
|
JtxTransactionManager |
getTransactionManager()
Returns transaction manager that owns this transaction. |
|
JtxTransactionMode |
getTransactionMode()
Returns transaction mode. |
|
boolean |
isActive()
Returns true if transaction is active. |
|
boolean |
isCommitted()
Returns true if transaction and all its resources are committed successfully. |
|
boolean |
isCompleted()
Returns true if transaction is either committed or rolled back. |
|
boolean |
isNoTransaction()
Returns true if transaction is explicitly forbidden, i.e. |
|
boolean |
isRollbackOnly()
Returns true if transaction is marked as rollback only. |
|
boolean |
isRolledback()
Returns true if transaction and all its resources are rolled-back successfully. |
|
protected
|
lookupResource(java.lang.Class<E> resourceType)
Lookups for open resource. |
|
|
requestResource(java.lang.Class<E> resourceType)
Requests a resource. |
|
protected void |
rolbackAllResources(boolean wasForced)
Rollbacks all attached resources. |
|
void |
rollback()
Roll back and completes current transaction. |
|
void |
setRollbackOnly()
Modify the transaction associated with the target object such that the only possible outcome of the transaction is to roll back the transaction. |
|
void |
setRollbackOnly(java.lang.Throwable th)
Modify the transaction associated with the target object such that the only possible outcome of the transaction is to roll back the transaction. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected final JtxTransactionManager txManager
protected final JtxTransactionMode mode
protected final java.util.Set<jodd.jtx.JtxResource> resources
protected final long deadline
protected JtxStatus status
protected java.lang.Throwable rollbackCause
Constructor Detail |
---|
public JtxTransaction(JtxTransactionManager txManager, JtxTransactionMode mode)
JtxTransactionManager
.
Method Detail |
---|
public JtxTransactionMode getTransactionMode()
public JtxTransactionManager getTransactionManager()
public JtxStatus getStatus()
public boolean isActive()
true
if transaction is active.
public boolean isNoTransaction()
true
if transaction is explicitly forbidden, i.e.
session is in auto-commit mode, or not started yet.
public boolean isCommitted()
true
if transaction and all its resources are committed successfully.
public boolean isRolledback()
true
if transaction and all its resources are rolled-back successfully.
public boolean isCompleted()
true
if transaction is either committed or rolled back.
public void setRollbackOnly()
public void setRollbackOnly(java.lang.Throwable th)
public boolean isRollbackOnly()
true
if transaction is marked as rollback only.
protected void checkTimeout()
public void commit()
public void rollback()
protected void commitOrRollback(boolean doCommit)
protected void commitAllResources() throws JtxException
All resources will be committed, even if commit fails on some in that process. If there was at least one failed commit, its exception will be re-thrown after finishing committing all resources, and transaction will be marked as rollback only.
JtxException
protected void rolbackAllResources(boolean wasForced)
public <E> E requestResource(java.lang.Class<E> resourceType)
protected <E> E lookupResource(java.lang.Class<E> resourceType)
null
if resource not found.
Only open resources can be found.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |