Transaction management with a separate transaction object
How it works
When you use a separate transaction object, you control the
duration of the database transaction. Your scripts explicitly connect
to and disconnect from the database. If the transaction object’s
AutoCommit property is set to false, you also
program when an update is committed or rolled back.
Typically, a script for data retrieval or update involves
these statements:
-
Connect
-
SetTransObject
-
Retrieve or Update
-
Commit or Rollback
-
Disconnect
In PowerBuilder, you use embedded SQL for connecting and committing.
For the Web ActiveX, the transaction object has methods that perform
these actions.
The transaction object also stores error messages returned
from the database in its properties. You can use the error information
to determine whether to commit or roll back database changes.
When to use it
When the DataWindow control uses a separate transaction object,
you have more control of the database processing and are responsible
for managing the database transaction.
There are several reasons to use a separate transaction object:
-
You have several DataWindow controls that connect
to the same database and you want to make one database connection
for all of them, saving the overhead of multiple connections -
You want to control transaction processing
-
You require the improved performance provided by
keeping database connections open
How it works
PowerBuilder
The SetTransObject method associates a transaction object with
the DataWindow control. PowerBuilder has a default transaction object called
SQLCA that is automatically instantiated. You can set its connection properties,
connect, and assign it to the DataWindow control.
The following statement uses SetTransObject to associate the
DataWindow control dw_emp with the default transaction
object (SQLCA):
1 |
// Set connection parameters in the transaction object |
1 |
SQLCA.DBMS = ... |
1 |
SQLCA.database = ... |
1 |
CONNECT USING SQLCA; |
1 |
dw_emp.SetTransObject(SQLCA) |
1 |
dw_emp.Retrieve( ) |
Instead of or in addition to using the predefined SQLCA transaction
object, you can define your own transaction object in a script.
This is necessary if your application needs to connect to more than
one database at the same time.
The following statement uses SetTransObject to associate dw_customer
with a programmer-created transaction object (trans_customer):
1 |
transaction trans_customer |
1 |
trans_customer = CREATE transaction |
1 |
// Set connection parameters in the transaction object |
1 |
trans_customer.DBMS = ... |
1 |
trans_customer.database = ... |
1 |
CONNECT USING trans_customer; |
1 |
dw_customer.SetTransObject(trans_customer) |
1 |
dw_customer.Retrieve( ) |
Web ActiveX
To use a separate transaction object for the Web ActiveX,
you add an OBJECT element for the SAP DataWindow Transaction Object
control to the Web page. You can set its connection properties using
Param elements or a script.
A script that connects and retrieves data would have statements
like these:
1 |
trans_1.Connect( ); |
1 |
dw_employee.SetTransObject( trans_1 ); |
1 |
dw_employee.Retrieve( ); |
1 |
trans_1.Disconnect( ); |
For more information
For more information about database transaction
processing:
-
PowerBuilder
See the chapter on using transaction objects in Application
Techniques -
Web ActiveX
See Chapter 8, “Using the DataWindow Web Control
for ActiveX”
For more information about SetTrans and SetTransObject
methods, see the DataWindow Reference.