Java Reference
In-Depth Information
grammatically simpler, especially in a long method, to mark the transaction as rolled back
using the setRollbackOnly method instead of writing an involved if-else block to
avoid such conditions. The getStatus method is a more robust version of getRoll-
backOnly in the CMT world. Instead of returning a Boolean, this method returns an
integer-based status of the current transactions, indicating a more fine-tuned set of states
that a transaction could possibly be in. The javax .transaction.Status interface
defines exactly what these states are, and they're listed in table 6.2 .
Table 6.2. The possible values of javax.transaction.Status interface. These are the status values returned
by the UserTransaction.getStatus method.
The associated transaction is in an active state.
The associated transaction is marked for rollback, possibly due to in-
vocation of the setRollbackOnly method.
The associated transaction is in the prepared state because all re-
sources have agreed to commit. (Refer to the section on two-phase
The associated transaction has been committed.
The associated transaction has been rolled back.
The status for the associated transaction isn't known.
There's no associated transaction in the current thread.
The associated transaction is preparing to be committed and awaiting
response from subordinate resources. (Refer to the section on two-
phase commit.)
The transaction is in the process of committing.
The transaction is in the process of rolling back.
The setTransactionTimeout method specifies the time (in seconds) in which a
transaction must finish. The default transaction time-out value is set to different values for
different application servers. For example, JBoss has a default transaction time-out value
of 300 seconds, whereas Oracle Application Server 10g has a default transaction time-out
value of 30 seconds. You might want to use this method if you're using a long-running
transaction. Typically, it's better to simply set the application server-wide defaults using
vendor-specific interfaces. At this point, you're probably wondering how to set a trans-
action time-out when using CMT instead. Only containers using either an attribute in the
vendor-specific deployment descriptor or vendor-specific annotation support this.
Search WWH ::

Custom Search