BEA Logo BEA Tuxedo Release 7.1

  Corporate Info  |  News  |  Solutions  |  Products  |  Partners  |  Services  |  Events  |  Download  |  How To Buy

 

   Tuxedo Doc Home   |   Programming   |   Topic List   |   Previous   |   Next   |   Contents

   Programming a BEA Tuxedo Application Using C

Suspending and Resuming a Transaction

At times, it may be desirable to temporarily remove a process from an incomplete transaction and allow it to initiate a different transaction by calling tpbegin() or tpresume(). For example, suppose a server wants to log a request to the database central event log, but does not want the logging activity to be rolled back if the transaction aborts.

The BEA Tuxedo system provides two functions that allow a client or server to suspend and resume a transaction in such situations: tpsuspend(3c) and tpresume(3c). Using these functions, a process can:

  1. Temporarily suspend the current transaction by calling tpsuspend().

  2. Start a separate transaction. (In the preceding example, the server writes an entry to the event log.)

  3. Commit the transaction started in step 2.

  4. Resume the original transaction by calling tpresume().

Suspending a Transaction

Use the tpsuspend(3c) function to suspend the current transaction. Use the following signature to call the tpsuspend() function.

int
tpsuspend(TPTRANID *t_id,long flags)

The following table describes the arguments to the tpsuspend() function.

tpsuspend( ) Function Arguments

Field

Description

*t_id

Pointer to the transaction identifier.

flags

Currently not used. Reserved for future use.

You cannot suspend a transaction with outstanding asynchronous events. When a transaction is suspended, all modifications previously performed are preserved in a pending state until the transaction is committed, aborted, or timed out.

Resuming a Transaction

To resume the current transaction, use the tpresume(3c) function with the following signature.

int
tpresume(TPTRANID *t_id,long flags)

The following table describes the arguments to the tpresume() function.

tpresume( ) Function Arguments

Field

Description

*t_id

Pointer to the transaction identifier.

flags

Currently not used. Reserved for future use.

It is possible to resume a transaction from a process other than the one that suspended it, subject to certain restrictions. For a list of these restrictions, refer to tpsuspend(3c) and tpresume(3c) in the BEA Tuxedo C Function Reference.

Example: Suspending and Resuming a Transaction

The following example shows how to suspend one transaction, start and commit a second transaction, and resume the initial transaction. For the sake of simplicity, error checking code has been omitted.

Suspending and Resuming a Transaction


DEBIT(SVCINFO *s)
{
TPTRANID t;
tpsuspend(&t,TPNOFLAGS); /* suspend invoking transaction*/

tpbegin(30,TPNOFLAGS); /* begin separate transaction */
Perform work in the separate transaction.
tpcommit(TPNOFLAGS); /* commit separate transaction */

tpresume(&t,TPNOFLAGS); /* resume invoking transaction*/

.
.
.
tpreturn(. . . );
}