tuxedo應用程序開發指南5

TBAL_BID 

BAL 

aud.vVIEW緩衝區

計算BRANCH_ID的出納員餘額

bankapp服務的演算法

⑴.    BR_ADD

void BR_ADD (TPSVCINFO *transb){

-set pointer to TPSVCINFO data buffer;

-get all values for service request from field buffer;

-insert record into BRANCH;

-tpreturn() with success;

}

⑵.    TLR_ADD

void TLR_ADD (TPSVCINFO *transb){

-set pointer to TPSVCINFO data buffer;

-get all values for service request from fielded buffer;

-get TELLER_ID by reading branch’s LAST_ACCT;

-insert teller record;

-update BRANCH with new LAST_TELLER;

-tpreturn() with success;

}

⑶.    OPEN_ACCT

void OPEN_ACCT(TPSVCINFO *transb){

-Extract all values for service request from fielded buffer using Fget() and Fvall();

-Check that initial deposit is positive amount and tpreturn() with failure if not;

-Check that branch ID is a legal value and tpreturn() with failure if it is not;

-Set transaction consistency level to read/write;

-Retrieve BRANCH record to choose new account based on branch’s LAST_ACCT

field;

-Insert new account record into ACCOUNT file;

-Update BRANCH record with new value for LAST_ACCT;

-Create deposit request buffer with tpalloc(); initialize it for FML withFinit();

-Fill deposit buffer with values for DEPOSIT service request;

-Increase priority of coming DEPOSIT request since call is from a service;

-Do tpcall() to DEPOSIT service to add amount of initial balance;

-Prepare return buffer with necessary information;

-Free deposit request buffer with tpfree();

tpreturn() with success;

}

⑷.    CLOSE_ACCT

void CLOSE_ACCT(TPSVCINFO *transb){

-Extract account ID from fielded buffer using Fvall();

-Check that account ID is a legal value and tpreturn() with failure if it is not;

-Set transaction consistency level to read/write;

-Retrieve ACCOUNT record to determine amount of final withdrawal;

-Create withdrawal request buffer with tpalloc(); initialize it for FML with Finit();

-Fill withdrawal buffer with values for WITHDRAWAL service request;

-Increase priority of coming WITHDRAWAL request since call is from a service;

-Do tpcall() to WITHDRAWAL service to withdraw balance of account;

-Delete ACCOUNT record;

-Prepare return buffer with necessary information;

-Free withdrawal request buffer with tpfree();

tpreturn with success;

}

⑸.    WITHDRAWAL

void WITHDRAWAL(TPSVCINFO *transb){

-Extract account id and amount from fielded buffer using Fvall() and Fget();

-Check that account id is a legal value and tpreturn() with failure if not;

-Check that withdraw amount (amt) is positive and tpreturn() with failure if not;

-Set transaction consistency level to read/write;

-Retrieve ACCOUNT record to get account balance;

-Check that amount of withdrawal does not exceed ACCOUNT balance;

-Retrieve TELLER record to get teller’s balance and branch id;

-Check that amount of withdrawal does not exceed TELLER balance;

-Retrieve BRANCH record to get branch balance;

-Check that amount of withdrawal does not exceed BRANCH balance;

-Subtract amt to obtain new account balance;

-Update ACCOUNT record with new account balance;

-Subtract amt to obtain new teller balance;

-Update TELLER record with new teller balance;

-Subtract amt to obtain new branch balance;

-Update BRANCH record with new branch balance;

-Insert new HISTORY record with transaction information;

-Prepare return buffer with necessary information;

tpreturn with success;

}

⑹.    DEPOSIT

void DEPOSIT(TPSVCINFO *transb){

-Extract account id and amount from fielded buffer using Fvall() and Fget();

-Check that account ID is a legal value and tpreturn() with failure if not;

-Check that deposit amount (amt) is positive and tpreturn() with failure if not;

-Set transaction consistency level to read/write;

-Retrieve ACCOUNT record to get account balance;

-Retrieve TELLER record to get teller’s balance and branch ID;

-Retrieve BRANCH record to get branch balance;

-Add amt to obtain new account balance;

-Update ACCOUNT record with new account balance;

-Add amt to obtain new teller balance;

-Update TELLER record with new teller balance;

-Add amt to obtain new branch balance;

-Update BRANCH record with new branch balance;

-Insert new HISTORY record with transaction information;

-Prepare return buffer with necessary information;

tpreturn() with success;

}

⑺.    INQUIRY

void INQUIRY(TPSVCINFO *transb){

-Extract account ID from fielded buffer using Fvall();

-Check that account ID is a legal value and tpreturn() with failure if not;

-Set transaction consistency level to read only;

-Retrieve ACCOUNT record to get account balance;

-Prepare return buffer with necessary information;

tpreturn() with success;

}

⑻.    TRANSFER

void TRANSFER(TPSVCINFO *transb){

-Extract account ID’s and amount from fielded buffer using Fvall() and Fget();

-Check that both account IDs are legal values and tpreturn() with failure if not;

-Check that transfer amount is positive and tpreturn() with failure if it is not;

-Create withdrawal request buffer with tpalloc(); initialize it for FML with Finit();

-Fill withdrawal request buffer with values for WITHDRAWAL service request;

-Increase priority of coming WITHDRAWAL request since call is from a service;

-Do tpcall() to WITHDRAWAL service;

-Get information from returned request buffer;

-Reinitialize withdrawal request buffer for use as deposit request buffer with Finit();

-Fill deposit request buffer with values for DEPOSIT service request;

-Increase priority of coming DEPOSIT request;

-Do tpcall() to DEPOSIT service;

-Prepare return buffer with necessary information;

-Free withdrawal/deposit request buffer with tpfree();

tpreturn() with success;

}

⑼.    ABAL

void ABAL(TPSVCINFO *transb){

-Set transaction consistency level to read only;

-Retrieve sum of all ACCOUNT file BALANCE values for the

database of this server group (A single ESQL

statement is sufficient);

-Place sum into return buffer data structure;

tpreturn( ) with success;

}

⑽.    TBAL

void TBAL(TPSVCINFO *transb){

-Set transaction consistency level to read only;

-Retrieve sum of all TELLER file BALANCE values for the

database of this server group (A single ESQL statement is sufficient);

-Place sum into return buffer data structure;

tpreturn( ) with success;

}

⑾.    ABAL_BID

void ABAL_BID(TPSVCINFO *transb){

-Set transaction consistency level to read only;

-Set branch_ID based on transb buffer;

-Retrieve sum of all ACCOUNT file BALANCE values for records

having BRANCH_ID = branch_ID (A single ESQL statement is sufficient);

-Place sum into return buffer data structure;

tpreturn( ) with success;

}

⑿.    ABAL_BID

void TBAL_BID(TPSVCINFO *transb){

-Set transaction consistency level to read only;

-Set branch_ID based on transb buffer;

-Retrieve sum of all TELLER file BALANCE values for records

having BRANCH_ID = branch_ID (A single ESQL statement is sufficient);

-Place sum into return buffer data structure;

tpreturn( ) with success;

}

4.集成到伺服器中的應用

bankapp中用到了兩個C語言的源程:

appint.c:包含應用程序定義版的tpsvrinit()tpsvrdown()過程,它們被包含到Tuxedo系統的main()中。預設版的tpsvrinit()調用了兩個函數:tpopen()userlog()tpopen()用於打開資源管理器,userlog()用於記錄各類消息。帛省版的tpsvrdown()同樣調用了兩個函數:tpclose()userlog(),分別用於關閉資源管理器和記錄關閉過程中的各類事件。你可以修改這兩個過程,以完成各類初始化或應用程序結束時的收尾工作。

util.c:包含了一個叫getstr()的過程,bankapp中用它來SQL的錯誤消息。

5.服務編碼的可選方法

bankapp中,一個伺服器提供的所有服務的代碼都集成到一個文件中,文件名和伺服器名字相同,它們還不是真正的伺服器,因為它們不包含main()方法,在buildserver時由系統提供一個。另一種組織Tuxedo系統應用程序的方法是把每個服務代碼保存在一個單獨的文件中。例如,對於TLR伺服器,TLR.EC文件包含三個服務,請可以將它們分成三個文件:INQUIRY.ECWITHDRAW.ECDEPOSIT.EC。按如下步驟完成:

⑴.    將每個EC文件編譯成OBJ文件

⑵.    運行buildserver,將它們放到-f開關後面:

buildserver     –r TUXEDO/SQL

            -s DEOISUT –s WITHDRAW –s INQUIRY

            -o TLR

            -f DEPOSIT.C –f WITHDRAW.C –f INQUIRY.C

            -f util.obj –f lm

這樣一來,你就沒有必要將所有的服務都寫到一個源文件中了,從而增加了靈活性。

6.準備bankapp的文件和資源

⑴.設置環境變數

    samples\atmi\bankapp\nt下的bankvar文件改名為bankvar.bat,複製到父目錄,然後對其進行編輯:

@echo off

rem %Tuxedo%Tuxedo安裝目錄,APPDIRbankapp所在的目錄

set
APPDIR=%TUXDIR%\samples\atmi\bankapp

rem消息所在目錄

set NLSPATH=%TUXDIR%\locale\C

rem邏輯塊大小,資料庫管理員必須設置

set BLKSIZE=512

rem
被預設使用的資料庫名字

set DBNAME=bankdb

rem
指示資料庫為共享模式還是私有模式

set DBPRIVATE=no

rem
指示資料庫使用的IPC值,必須與ubbconfig中的IPCKEY不同

set DIPCKEY=80953

rem
tmloadcf使用的環境文件

set ENVFILE=%APPDIR%\ENVFILE

rem
mc, viewc, tmloadcf使用的欄位表文件

set FIELDTBLS=Usysflds,bankflds,creditflds

rem
查找欄位表文件的目錄

set FLDTBLDIR=%TUXDIR%\udataobj;%APPDIR%

rem
資料庫使用的通用設備列表

set FSCONFIG=%APPDIR%\bankdl1

rem MENU中使用的網路地址

set NADDR=

rem
網路設備名

set NDEVICE=

rem MENU腳本中使用的網路監聽器地址

set NLSADDR=

rem
事務日誌設備,必須和ubbconfigMACHINES

rem LMID站點的TLOGDEVICE參數相同

set TLOGDEVICE=%APPDIR%\TLOG

rem
/T提供全部信息的二進位配置文件

set TUXCONFIG=%APPDIR%\tuxconfig

rem
用戶日誌文件,必須和ubbconfig中的MACHINES

rem LMID站點的ULOGPFX參數相同

set ULOGPFX=%APPDIR%\ULOG

rem
RUNME.sh使用的系統名

set UNAME=

rem
viewc, tmloadcf使用的view文件列表

set VIEWFILES=aud.vv

set VIEWFILES32=mib_views,tmib_views

rem
查找view文件的目錄

set VIEWDIR=%TUXDIR%\udataobj;%APPDIR%

set VIEWDIR32=%TUXDIR%\udataobj;%APPDIR%

rem
指定Q設備

set QMCONFIG=%APPDIR%\qdevice

set PATH=%TUXDIR%\bin;%PATH%

rem
指出Visual C++安裝的目錄

set MSDEV=G:\Program Files\Microsoft Visual Studio\VC98

set PATH=%PATH%;%MSDEV%\bin

set INCLUDE=%INCLUDE%;%MSDEV%\include;%MSDEV%\mfc\include

set LIB=%LIB%;%MSDEV%\lib;%MSDEV%\mfc\lib

⑵.Build bankapp的應用程序

    bankapp5個伺服器:ACCTBALBTADDTLRXFER。用一個命令就可以完成編譯任務:

G:\Tuxedo\samples\atmi\bankapp\nmake bankapp.nt

若要手工完成編譯,首先要將EC文件編譯成C文件:

G:\Tuxedo\samples\atmi\bankapp\ESQLC ACCT.EC

生成FML緩衝區頭文件:

G:\Tuxedo\samples\atmi\bankapp\mkfldhdr bankflds eventflds

生成目標文件:

G:\Tuxedo\samples\atmi\bankapp\CL /c ACCT.c appinit.c util.c

以下文章點擊率最高

Loading…

     

如果這文章對你有幫助,請掃左上角微信支付-支付寶,給於打賞,以助博客運營

發表評論

您的電子郵箱地址不會被公開。 必填項已用*標註