RDB DAS Transaction Sample

 

Introduction

This stand-alone sample demonstrates the RDB Data Access Service transaction management with external Transaction Manager. This example uses Geronimo  as the transaction manager.

 

Example

In this MoneyTransfer example,user entered amount will be withdrawn from one of his bankaccount using one call to das.applyChanges(dataGraph1) and same amount will  be deposited to his another account using another call to das.applyChanges(dataGraph2). Based on whether user selects commit/rollback, these 2 applyChanges() will behave identically. i.e. both will commit or both will rollback, but partial transaction will not happen. Example build.xml - sets for transfer of 1200 from Account1 to Account2 [commit].

 

Building and Running

 From binary distribution, base directory is {DAS_ROOT}\ samples\transaction. Refer to below settings from this base directory.

1]BankAccounts.xml available in sample-transaction.jar, is the DAS config file. Note that, as transaction is externally managed, this uses managedtx=false setting.

 

2]MySQL server should be running. The example uses MySQL DB (with innoDB ON to support transaction). Database dastest, table bankaccount and data will be created during sample run. For this preconfigured BankAccountDBConfig.xml available in sample-transaction.jar, will be used. User needs to set correct values for url, login etc. in this.

 

3] Apache Ant latest version should be installed.Download Apache Ant latest version on and extract into folder <apache_ant_folder>. You can find it here: http://ant.apache.org/bindownload.cgi.Add <apache_ant_folder>/bin directory to your OS path variable.

 

4] From base directory run-  ant

 

The sample will run and output the following:

Buildfile: build.xml

 

run:

     [java] INIT database

     [java] INIT transaction manager

     [java] Wed Sep 19 17:09:42 IST 2007 DEBUG: Executing XA statement: XA START

 0x01000000000000004bceb90109b6b0f3000000000000000000000000000000000000000000000

000000000000000000000000000000000000000000000000000,0x00000000000000000000000000

00000000000000000000000000000000000000000000000000000000000000000000000000000000

0000000000000000000000,0x4765526f

     [java] Get a connection

     [java] Before transaction, table is:

     [java]     id      name    balance

     [java]     1       John Feng       1200

     [java]     2       John Feng       0

     [java] Begin a transaction

     [java] Update the table - 2 accounts

     [java] *commit* the transaction

     [java] Wed Sep 19 17:09:45 IST 2007 DEBUG: Executing XA statement: XA END 0

x01000000000000004bceb90109b6b0f300000000000000000000000000000000000000000000000

0000000000000000000000000000000000000000000000000,0x0000000000000000000000000000

00000000000000000000000000000000000000000000000000000000000000000000000000000000

00000000000000000000,0x4765526f

     [java] Wed Sep 19 17:09:45 IST 2007 DEBUG: Executing XA statement: XA PREPA

RE 0x01000000000000004bceb90109b6b0f30000000000000000000000000000000000000000000

00000000000000000000000000000000000000000000000000000,0x000000000000000000000000

00000000000000000000000000000000000000000000000000000000000000000000000000000000

000000000000000000000000,0x4765526f

     [java] Wed Sep 19 17:09:45 IST 2007 DEBUG: Executing XA statement: XA COMMI

T 0x01000000000000004bceb90109b6b0f300000000000000000000000000000000000000000000

0000000000000000000000000000000000000000000000000000,0x0000000000000000000000000

00000000000000000000000000000000000000000000000000000000000000000000000000000000

00000000000000000000000,0x4765526f

     [java] After transaction, table is:

     [java]     id      name    balance

     [java]     1       John Feng       0

     [java]     2       John Feng       1200

     [java] Cleanup

     [java] End MoneyTransfer

     [java]

 

BUILD SUCCESSFUL

Total time: 8 seconds

Observation: The build.xml ant file only works on DAS Java binary distribution.