![]() |
![]() |
|
|
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.
Handling Exceptions
Errors or failures that may occur when Jolt initiates a Tuxedo service call are reported to your application through Java exceptions. Always enclose the call() method within a try / catch block and attempt to deal with any exceptions appropriately. The call() method can throw any of the following exceptions for the following reasons:
Thrown when an error occurs in the logic of the Tuxedo service. For example, a client illegally attempts to use a withdrawal service to withdraw more money from an account than the current balance. The ApplicationException is thrown when the Tuxedo service returns a TPESVCFAIL. Application-specific information about the error can be included in the Result object that was returned from the service invocation. You can access the Result object through the ApplicationException.getResult() method.
Be sure to use the full package name of the bea.jolt.pool.ApplicationException, because Jolt defines another exception whose full package name is bea.jolt.ApplicationException.
A JoltException is the super class of all the following exceptions. These exceptions all signify that a system error has occurred that is not part of the application logic. JoltException is documented in Appendix A, "BEA Jolt Exceptions," in the Using BEA Jolt.
Thrown when an error occurs in the Jolt SessionPool. For example, this may occur if all sessions are busy, or if the session pool is suspended.
Thrown when an error occurs related to invoking the Tuxedo service that contains the application. For example, a service timeout, or a non-existent service is called.
Thrown when a transaction cannot be either started, committed, or aborted.
![]() |
![]() |
![]() |
|
Copyright © 2001 BEA Systems, Inc. All rights reserved.
|