|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object atg.dtm.TransactionDemarcation
public class TransactionDemarcation
This is used by applications to demarcate transactions "by hand" around a section of code. An application will get or create one of these instances, then call begin() before the section of code. When the code finishes (preferably in a finally clause), end() should be called. Instances of this class are reusable, as long as begin/end is always called in sequence.
The begin method allows any of the transaction demarcation attributes specifed by EJB. If none is specified, it defaults to REQUIRED. Most of the time the transaction attribute will be REQUIRED or REQUIRES_NEW. The following explains all of the different transaction attribute types:
The following is a sample use:
TransactionDemarcation td = new TransactionDemarcation (); boolean success = false; try { td.begin (mTransactionManager); ... code to execute within the transaction ... success = true; } finally { td.end (!success); }
Field Summary | |
---|---|
static java.lang.String |
CLASS_VERSION
Class version string |
static int |
MANDATORY
|
static int |
NEVER
|
static int |
NOT_SUPPORTED
|
static int |
REQUIRED
|
static int |
REQUIRES_NEW
|
static int |
STATUS_CREATED_TRANSACTION_COMMITTED
|
static int |
STATUS_SUSPENDED_TRANSACTION_RESUMED
|
static int |
STATUS_TRANSACTION_CREATED
|
static int |
STATUS_TRANSACTION_ENDED_IN_CODE
|
static int |
SUPPORTS
|
Constructor Summary | |
---|---|
TransactionDemarcation()
Constructs a new TransactionDemarcation |
Method Summary | |
---|---|
void |
begin(javax.transaction.TransactionManager pTransactionManager)
This should be called at the beginning of a section of code to be demarcated by a transaction. |
void |
begin(javax.transaction.TransactionManager pTransactionManager,
int pTransAttribute)
This should be called at the beginning of a section of code to be demarcated by a transaction. |
int |
end()
This calls end with a rollback flag of false, meaning that it will commit the transaction unless it has been marked for rollback only. |
int |
end(boolean pRollback)
This must be called at the end of a section of code demarcated by this TransactionDemarcation, preferably in a finally clause. |
static boolean |
equalTransactions(javax.transaction.Transaction pTransaction1,
javax.transaction.Transaction pTransaction2)
Compare two Transactions for equality. |
javax.transaction.Transaction |
getTransaction()
Get the Transaction that is associated with this TransactionDemarcation; |
boolean |
isTransactionCreated()
Return whether we created a transaction. |
void |
setClearTransactionOnEnd(boolean pClearTransactionOnEnd)
Tells this TransactionDemarcation object to not clear the associated transaction when end() is called. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static java.lang.String CLASS_VERSION
public static final int NOT_SUPPORTED
public static final int SUPPORTS
public static final int REQUIRED
public static final int REQUIRES_NEW
public static final int MANDATORY
public static final int NEVER
public static final int STATUS_TRANSACTION_CREATED
public static final int STATUS_CREATED_TRANSACTION_COMMITTED
public static final int STATUS_SUSPENDED_TRANSACTION_RESUMED
public static final int STATUS_TRANSACTION_ENDED_IN_CODE
Constructor Detail |
---|
public TransactionDemarcation()
Method Detail |
---|
public javax.transaction.Transaction getTransaction()
public void setClearTransactionOnEnd(boolean pClearTransactionOnEnd)
public void begin(javax.transaction.TransactionManager pTransactionManager, int pTransAttribute) throws TransactionDemarcationException
TransactionDemarcationException
public void begin(javax.transaction.TransactionManager pTransactionManager) throws TransactionDemarcationException
TransactionDemarcationException
public int end(boolean pRollback) throws TransactionDemarcationException
This must be called at the end of a section of code demarcated by this TransactionDemarcation, preferably in a finally clause. This will commit (or rollback if marked for rollback only) any created transaction, and resume any suspended transaction. If the demarcated code already committed the current transaction, everything is fine. But if the demarcated code changed the current transaction (by suspending and not resuming, or creating and not committing), an error is produced.
The pRollback flag indicates if the transaction should be rolled back. If true, the transaction will bve rolled back. If false, then the transaction will be rolled back only if it has been marked for rollback only.
This method returns a status code indicating what happened to the transactions during the demarcated area. The status code is a bitwise-OR of several flags, indicating the following:
A typical use of the status flags is to see if a transaction was rolled back ((status & STATUS_TRANSACTION_CREATED != 0) && (status & STATUS_TRANSACTION_COMMITTED == 0)). But be aware - the only time this will be valid is if the code enclosed by the demarcation explicitly set the transaction to rollback only. If the transaction tried to commit and rolled back because of some other error, the result will be a rollback exception (enclosed in a TransactionDemarcationException).
TransactionDemarcationException
public int end() throws TransactionDemarcationException
This calls end with a rollback flag of false, meaning that it will commit the transaction unless it has been marked for rollback only.
TransactionDemarcationException
public static final boolean equalTransactions(javax.transaction.Transaction pTransaction1, javax.transaction.Transaction pTransaction2)
pTransaction1
- first transaction to comparepTransaction2
- second transaction to compare
equals()
, else false.public boolean isTransactionCreated()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |