dsp:transactionStatus
retrieves the status of the active transaction and saves that status to a variable named by the var
attribute. Other tags can query the variable for transaction status information. If the tag is unable to access status information, the success
property is set to false and the exception
property holds a Throwable
exception.
Attributes
TagVariable:varorid(Required)
You must define an EL variable or scripting variable:
Attribute | Description |
---|---|
| Names an EL variable. When you use |
| Names a scripting variable, which scriptlets and expressions can access at runtime. |
VariableScope:scope
The scope
attribute determines where the object identified by the var
attribute is stored and what resources can access it. Options include: page
, request
, session
, or application
. Omitting this attribute causes the default, page
, to be used.
Properties
success
The success
property evaluates whether the tag retrieved the transaction’s status. A call to isSuccess
returns either true.
exception
The exception
property identifies the Throwable
exception object when the transaction status is not accessed. A call to getException
returns the exception object.
status
The status
property holds the status code for the transaction. Options include:
0 (Active)
3 (Committed)
8 (Committing)
1 (Marked Rollback)
6 (No Transaction)
2 (Prepared)
7 (Preparing)
4 (Rolled Back)
9 (Rolling Back)
5 (Unknown)
For an explanation of each status, see the property named for that status below.
statusString
The statusString
property holds a text string that describes the current status of the active transaction. Options include:
Active
Committed
Committing
Marked Rollback
No Transaction
Prepared
Preparing
Rolled Back
Rolling Back
Unknown
For an explanation of each status, see the property named for that status below.
active
The active
property determines whether the status is set to Status.STATUS_ACTIVE
. A status of Active
indicates that the transaction is in its early stages of operation and has not received any instructions about how to end. A call to isActive
returns true.
committed
The committed
property determines whether the status is set to Status.STATUS_COMMITTED
. A status of Committed
indicates tasks associated with the transaction executed, any changes made to a database(s) as a result were saved, and the transaction ended. A call to isCommitted
returns either true.
committing
The committing
property determines whether the status is set to Status.STATUS_COMMITTING.
A status of Committing
indicates tasks associated with the database are in the process of committing. It is most likely that the transaction involves multiple databases, of which some have committed data and others do not. A call to isCommitting
returns either true.
markedRollback
The markedRollback
property determines whether the status is set to Status.STATUS_MARKED_ROLLBACK.
A status of Marked Rollback
indicates that the transaction has been instructed that, when it is prompted to end, it must revert the database(s) to its pre-transaction state (rollback). A call to isMarketedRollback
returns either true.
noTransaction
The noTransaction
property determines whether the status is set to Status.STATUS_NO_TRANSACTION.
A status of No
Transaction
indicates that no transaction is associated with current request thread. A call to isNoTransaction
returns either true.
prepared
The prepared
property determines whether the status is set to Status.STATUS_PREPARED
. A status of Prepared
indicates that each database involved in the transaction has verified that it can commit the transaction without any errors. A call to isPrepared
returns either true.
preparing
The preparing
property determines whether the status is set to Status.STATUS_PREPARING
. A status of Preparing
indicates that each database involved in the transaction is investigating whether it can commit the tasks associated with the transaction. A call to isPreparing
returns either true.
rolledback
The rolledback
property determines whether the status is set to Status.STATUS_ROLLEDBACK
. A status of Rolledback
indicates that the tasks associated with the transaction did not complete and so no changes were made by the transaction. The transaction ended. A call to isRolledback
returns either true.
rollingback
The rollingback
property determines whether the status is set to Status.STATUS_ROLLING_BACK
. A status of Rolling
Back
indicates that the transaction is in the process of undoing any tasks that it performed, so no changes are saved. A call to isRollingback
returns either true.
unknown
The unknown
property determines whether the status is set to Status.STATUS_UNKNOWN
. A status of Unknown
indicates that the transaction manager is unable to recognize the status as any of those mentioned above. A call to isUnknown
returns either true.
Example
<dsp:transactionStatus var="statusXA"/>
<c:choose>
<c:when test="${statusXA.committed}">
Congratulations! You will graduate this June!
</c:when>
<c:when test="${statusXA.rolledBack}">
You will not graduate this year. Be sure to enroll in classes for
next semester.
</c:when>
<c:otherwise>
It takes 10 days to gather your records and process them. Check
again in a few days.
</c:otherwise>
</c:choose>
In this example, the status of the transaction determines the message a user sees. The transaction status is set in the EL variable statusXA
that is defined by dsp:transactionStatus
. When the status is rolledback
users see one message, when it is committed
they see another. All other transaction statuses provide the same in process notification to their recipients.