Controlling transactions from a client
PowerBuilder clients can exercise explicit control of a transaction
on a COM+ server by using a variable of type OleTxnObject
instead of OLEObject to connect to the COM object.
The ConnectToNewObject call on an OleTxnObject
fails if COM+ 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
is 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 COM object on a 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<br>OleTxnObject lotxn_obj<br> <br>lotxn_obj = CREATE OleTxnObject<br>li_rc = lotxn_obj.ConnectToNewObject("pbcom.n_test")<br>IF li_rc <> 0 THEN<br>    Messagebox( "Connect Error", string(li_rc) )<br>    HALT<br>END IF<br> <br>lotxn_obj.f_dowork()<br>lotxn_obj.f_domorework()<br> <br>lotxn_obj.SetComplete()<br>lotxn_obj.DisconnectObject() |
This f_dowork function on the
COM object on the 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<br>integer li_rc<br> <br>li_rc = GetContextService( "TransactionServer", &<br>    txninfo_one )<br>txninfo_one.DisableCommit()<br> <br>// do some work and return a return code<br>IF li_rc <> 0 THEN<br>    txninfo_one.SetAbort()<br>    return -1<br>ELSE<br>    txninfo_one.SetComplete()<br>    return 1<br>END IF |
The SetComplete call on the client commits
the transaction if all of the methods in the
transaction called SetComplete or EnableCommit.