3.7 Using a Transaction
You can use a transaction object to group multiple service calls into an atomic action, maintaining data integrity within your application logic. You obtain a transaction from a session pool with the method:
Transaction trans = ssPool.startTransaction(timeout);
where the transaction object
trans
holds the reference to the transaction,
ssPool
is the SessionPool or ServletSessionPool object, and the timeout
argument for the transaction is specified in seconds.
Once a transaction obtains a session, that session cannot be used by other transactions
until the transaction is committed, aborted, or times out. The session may, however, still
be used by single requests that are not part of a transaction. If a transaction fails to
obtain a session from the pool, this method throws a
bea.jolt.pool.TransactionException
. If the session pool is suspended,
the method throws a bea.jolt.pool.SessionPoolException.
Each time your application uses the call()
method, you should supply the
transaction object as the last parameter. For example:
ssPool.call("svcName", request, trans);
You can make multiple calls in the same transaction. The calls will not complete until you
either commit or roll back the transaction using the methods of the transaction object. The
trans.commit()
method completes the transaction. This method returns 0
if the commit was successful, or throws a TransactionException
if the
transaction failed to commit.
If you need to abort the transaction, use the Transaction.rollback()
method. This method attempts to abort the transaction. It returns 0 if successful;
otherwise it throws a TransactionException
.
Parent topic: Implementing Jolt for WebLogic