tppt.xopen
Class ApplicationProgram

java.lang.Object
  |
  +--tppt.xopen.ApplicationProgram
All Implemented Interfaces:
APInterface

public class ApplicationProgram
extends java.lang.Object
implements APInterface

This class implements the ApplicatioProgram in the two-phase commit protocol.

Version:
2.0
Author:
Jodie Wu
See Also:
APInterface

Field Summary
private  TwoPhaseLogger logger
          The logger
private  int tid
          Transaction id
private  TMInterface tm
          Transaction Manager
 
Constructor Summary
ApplicationProgram()
          The Constructor.
 
Method Summary
 boolean beginTransaction()
          Application call the tx_begin() to obtains the transaction id from TM when this method is called.
 void closeTransaction()
          Application calls the tx_close() to tell TransactionManager that this transaction has been done.
 void commitTransaction()
          Application call the tx_commit() to commit the transaction.
 int getTransactionId()
          Obtains the transaction id
 void setTransactionManager(TMInterface obj)
          Set up the TransactionManager instance.
 boolean setupSubTransaction()
          Initiate and define the sub-transaction(s) under this method.
private  boolean workRequest(int subId, java.lang.String dbName, java.lang.String dbuser, java.lang.String dbpassd, java.lang.String driver, java.lang.String url, java.lang.String proxy, java.lang.String sqlStr)
          This method is private method used to set up the JDBC parameters for the specific sub-transaction.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

tid

private int tid
Transaction id

tm

private TMInterface tm
Transaction Manager

logger

private TwoPhaseLogger logger
The logger
Constructor Detail

ApplicationProgram

public ApplicationProgram()
The Constructor.
Method Detail

setTransactionManager

public void setTransactionManager(TMInterface obj)
Set up the TransactionManager instance. Notice that this method is called in the runtime by the TwoPhaseController when the user's TransactionManager is loaded.
Specified by:
setTransactionManager in interface APInterface
Parameters:
obj - TMInterface object
See Also:
TMInterface

getTransactionId

public int getTransactionId()
Obtains the transaction id
Specified by:
getTransactionId in interface APInterface
Returns:
transaction id

beginTransaction

public boolean beginTransaction()
Application call the tx_begin() to obtains the transaction id from TM when this method is called.
Specified by:
beginTransaction in interface APInterface
Returns:
true if obtains the transaction id sucessfully, false otherwise.
See Also:
TransactionManager.tx_begin()

closeTransaction

public void closeTransaction()
Application calls the tx_close() to tell TransactionManager that this transaction has been done.
Specified by:
closeTransaction in interface APInterface
See Also:
TransactionManager.tx_close(int)

commitTransaction

public void commitTransaction()
Application call the tx_commit() to commit the transaction. It is the start point of the two-phase commit protocol.
Specified by:
commitTransaction in interface APInterface

workRequest

private boolean workRequest(int subId,
                            java.lang.String dbName,
                            java.lang.String dbuser,
                            java.lang.String dbpassd,
                            java.lang.String driver,
                            java.lang.String url,
                            java.lang.String proxy,
                            java.lang.String sqlStr)
This method is private method used to set up the JDBC parameters for the specific sub-transaction. The tasks need to be done here are :

 (1) Create the DBSetting objects that stored the JDBC setting for this sub-transaction.
 (2) Connect to Resource Manager using the JDBC setting from (1)
 (3) Ask the ResourceManager to register to TM
 (4) Start the this sub-transaction
 (5) Execute this sub-transaction.
 
Parameters:
subId - the id for this subtransaction. It should be unique number for this application.
dbName - The name of DBMS. "DB2" or "SYBASE"
dbuser - The DB login name for the specific dbName
dbpassd - The DB password for the specific dbName
driver - The JDBC driver for the specific dbName
url - The JDBC url for the specific dbName
proxy - The proxy server if needed. Sybase needs proxy if connected from home.
sqlStr - The SQL command.
Returns:
true if

setupSubTransaction

public boolean setupSubTransaction()
Initiate and define the sub-transaction(s) under this method.
Specified by:
setupSubTransaction in interface APInterface
Returns:
true if sub-transactions set up sucessfully; false otherwise.