Controlling transactions from a client
PowerBuilder clients can exercise explicit control of a transaction
on an MTS server by using a variable of type OleTxnObject instead
of OLEObject to connect to the COM object in MTS.
Requires MTS installation The ConnectToNewObject call on an OleTxnObject fails if MTS
is not installed on the client computer.
The OleTxnObject object, derived from the OLEObject object,
provides two additional functions (SetComplete and SetAbort) that
enable the client to participate in transaction control. When the
client calls SetComplete, the transaction will be committed if no
other participant in the transaction has called SetAbort or otherwise
failed. If the client calls SetAbort, the transaction is always
aborted.
Example In this example, the clicked event on a button creates a variable
of type OleTxnObject, connects to a PowerBuilder COM object on an
MTS server, and calls some methods on the object. When all the methods
have returned, the client calls SetComplete and disconnects from
the object.
1 |
integer li_rc |
1 |
OleTxnObject lotxn_obj |
1 |
1 |
lotxn_obj = CREATE OleTxnObject |
1 |
li_rc = lotxn_obj.ConnectToNewObject("pb70.n_test") |
1 |
IF li_rc <> 0 THEN |
1 |
Messagebox( "Connect Error", string(li_rc) ) |
1 |
HALT |
1 |
END IF |
1 |
1 |
lotxn_obj.f_dowork() |
1 |
lotxn_obj.f_domorework() |
1 |
1 |
lotxn_obj.SetComplete() |
1 |
lotxn_obj.DisconnectObject() |
1 |
This f_dowork() function on the PowerBuilder COM
object on the MTS server creates an instance of the transaction
context service and calls its DisableCommit method to prevent the
transaction from committing prematurely between method calls. After
completing some work, the function calls SetAbort if the work was
not successfully completed and SetComplete if it was.
1 |
TransactionServer txninfo_one |
1 |
integer li_rc |
1 |
1 |
li_rc = GetContextService( "TransactionServer", & |
1 |
txninfo_one ) |
1 |
txninfo_one.DisableCommit() |
1 |
1 |
// do some work and return a return code |
1 |
IF li_rc <> 0 THEN |
1 |
txninfo_one.SetAbort() |
1 |
return -1 |
1 |
ELSE |
1 |
txninfo_one.SetComplete() |
1 |
return 1 |
1 |
END IF |
The SetComplete call on the client commits the transaction
if all
of the methods in the transaction called
SetComplete or EnableCommit.