ITrans interface (deprecated)
ITrans is deprecated and is provided for backward compatibility only. In new applications, either use XA transactions from the Java Transaction API (JTA), or set the appropriate autocommit mode on java.sql.Connection, an interface of the JDBC Core API.
The ITransinterface represents a transaction object used for subsequent transaction processing operations. ITrans provides operations for beginning, committing, and rolling back transactions.
After instantiating a transaction object, the AppLogic calls begin( ) to start the transaction. Next, the AppLogic performs any query, insert, update, or delete operations, passing the transaction object to the respective method in the ITable interface (deprecated). Finally, the AppLogic closes the transaction by calling either commit( ) to save all changes or rollback( ) to cancel them. Closing a transaction terminates the transaction object and releases system resources.
The calls that make up a transaction can be in any part of the code; they need not be consecutive. The commands in a transaction are united by the fact that they all have the same transaction object as a parameter.
An application can process several transactions simultaneously. Each transaction works with a different database connection object. Within a single transaction, however, all the commands must access a single database through a single connection object.
To create an instance of the ITrans interface, use createTrans( ) in the AppLogic class (deprecated), as shown in the following example:.
ITrans trx = createTrans();
Package
com.kivasoft
Methods
Example
// Create and begin a transaction
ITrans trx=createTrans();
trx.begin();
// 1) Process the credit card
if(!processCreditCard(cusId, card, number, expirationDate, trx)) {
trx.rollback();
return result("Could not process the credit card information"); }
// 2) Process the invoice record
InfoHolder info=new InfoHolder();
if(!makeInvoiceRecord(cusId, number, trx, info)) {
trx.rollback();
return result("Could not create the invoice record"); };
// 3) Process products on the invoice
if(!makeInvoiceEntries(info.invoiceId, trx)) {
trx.rollback();
return result("Could not create the invoice product records"); };
// 4) Process optional shipping information
if(shippingInfo && !makeShippingRecord(info.invoiceId, trx, addr1,
addr2, city, state, zip)) {
trx.rollback();
return result("Could not create the shipping information record"); };
// 5) Process the inventory for each purchased product
if(!reduceProductInventory(trx)) {
// Problem occurred - abandon everything
trx.rollback();
return 0;
}
// No problem occurred - save everything
trx.commit(0);
Related Topics
createTrans( ) in the AppLogic class (deprecated)
addRow( ), updateRow( ), and deleteRow( ) in the ITable interface (deprecated)
begin( )
Starts the transaction.
Syntax
public int begin()
Usage
Use begin( ) to start a transaction before performing any operations in the transaction. Subsequent operations belong to the current transaction until either commit( ) or rollback( ) is called.
Rules
Tip
Use transactions judiciously to avoid locking conflicts. For example, avoid deadlocks by not using different open transactions on the same table.
Return Value
GXE.SUCCESS if the method succeeds.
Example
// Create a transaction
ITrans updCustTrans = createTrans();
if (updCustTrans == null)
{
return handleOBSystemError("Could not create transaction");
}
// Begin the transaction
updCustTrans.begin();
Related Topics
createTrans( ) in the AppLogic class (deprecated)
addRow( ), updateRow( ), and deleteRow( ) in the ITable interface (deprecated)
commit( )
Commits the transaction, saving any changes.
Syntax
public IObject commit(
int dwFlags)
dwFlags.
Specify 0.
Usage
Use commit( ) to commit a transaction and write unsaved changes to disk. commit( ) saves the changes, terminates the transaction object, and releases system resources.
Rules
Tips
Return Value
IObject object (for internal use only), or null for failure.
Example
// Update Customer record
rs = updCustPQuery.execute(0, custValList, updCustTrans, null);
if (rs == null)
{
// Rollback transaction if the update operation failed
updCustTrans.rollback();
return handleOBSystemError("Could not update Customer.");
}
// Commit the transaction if the update operation succeeded
updCustTrans.commit(0);
valIn.setValString("OUTPUTMESSAGE", "Successfully updated customer
record.");
Related Topics
createTrans( ) in the AppLogic class (deprecated)
addRow( ), updateRow( ), and deleteRow( ) in the ITable interface (deprecated)
rollback( )
Rolls back the transaction, abandoning any changes.
Syntax
public int rollback()
Usage
Many database servers buffer changes made during a transaction, then update the affected tables only after the commit request is received.
Rolling back a transaction terminates the transaction object and releases system resources.
Rules
Tip
If an error occurs before the commit operation succeeds, the database server usually rolls back the transaction automatically.
Return Value
GXE.SUCCESS if the method succeeds.
Example
IResultSet rs;
// Update User
rs = updUserPQuery.execute(0, userValList, updCustTrans, null);
if (rs == null)
{
updCustTrans.rollback();
return handleOBSystemError("Could not update User.");
}
Related Topics
createTrans( ) in the AppLogic class (deprecated)
addRow( ), updateRow( ), and deleteRow( ) in the ITable interface (deprecated)
|