beautypg.com

Jolt class library walk-through, Transaction begin, commit, and rollback – HP NonStop G-Series User Manual

Page 69

background image

Transaction Begin, Commit, and Rollback

In Jolt, a transaction is represented as an object of the class JoltTransaction. The transaction begins when the transaction object is
instantiated. The transaction object is created with a time out and JoltSession object parameter:

trans = new JoltTransaction(timeout, session)

Jolt uses an explicit transaction model for any services involved in a transaction. The transaction service invocation requires a
JoltTransaction object as a parameter. Jolt also requires that the service and the transaction belong to the same session. Jolt does not allow
you to use services and transactions that are not bound to the same session.

Jolt Class Library Walk-through

Example 6-1

shows how to use the Jolt Class Library and includes the use of the JoltSessionAttributes, JoltSession, JoltRemoteService,

and JoltTransaction classes.

The example combines two user-defined TUXEDO services (WITHDRAWAL and DEPOSIT) to perform a simulated TRANSFER
transaction. If the WITHDRAWAL operation fails, a rollback is performed. Otherwise, a DEPOSIT is performed and a commit completes
the transaction.

The basic steps of the transaction process shown in the example are as follows:

Set the connection attributes like hostname and portnumber in the JoltSessionAttribute object. Refer to the following line in

Example 6-1

:

sattr = new JoltSessionAttributes();

1.

The sattr.checkAuthenticationLevel() allows the application to determine the level of security required to log on to the server. Refer
to the following line in

Example 6-1

:

switch (sattr.checkAuthenticationLevel())

2.

The logon is accomplished by instantiating a JoltSession object. Refer to the following lines in

Example 6-1

:

session = new JoltSession (sattr, userName, userRole,
userPassword, appPassword);

This example does not explicitly catch SessionException errors.

3.

All JoltRemoteService calls require a service to be specified and the session key returned from JoltSession(). Refer to the following
lines in

Example 6-1

:

withdrawal = new JoltRemoteService("WITHDRAWAL", session);

deposit = new JoltRemoteService("DEPOSIT", session);

These calls bind the service definition of both the WITHDRAWAL and DEPOSIT services, which are stored in the Jolt Repository,
to the withdrawal and deposit objects, respectively. The services WITHDRAWAL and DEPOSIT must be defined in the Jolt
Repository otherwise a ServiceException will be thrown. This example does not explicitly catch ServiceException errors.

4.

Once the service definitions are returned, the application-specific fields such as account number ACCOUNT_ID and withdrawal
amount SAMOUNT are automatically populated. Refer to the following lines in

Example 6-1

:

withdrawal.addInt("ACCOUNT_ID", 100000);

withdrawal.addString("SAMOUNT", "100.00");

The add*() methods can throw IllegalAccessError or NoSuchFieldError exceptions.

5.

The JoltTransaction call allows a timeout to be specified if the transaction does not complete within the specified time. Refer to the
following line in

Example 6-1

:

trans = new JoltTransaction(5,session);

6.

Once the withdrawal service definition has been automatically populated, the withdrawal service is invoked by calling the
withdrawal.call(trans) method. Refer to the following line in

Example 6-1

:

withdrawal.call(trans);

7.

A failed WITHDRAWAL can be rolled back. Refer to the following line in

Example 6-1

:

trans.rollback();

8.

Otherwise, once the DEPOSIT is performed, all the transactions are committed. Refer to the following lines in

Example 6-1

:

deposit.call(trans);

9.