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…

     

如果这文章对你有帮助,请扫左上角微信支付-支付宝,给于打赏,以助博客运营

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注