Some key considerations for writing application code between TSTART and TCOMMIT are as follows:
![]() | Note |
---|---|
GT.M uses implicit transaction processing when it needs to ensure complex operations, including spanning block actions, spanning region actions and trigger actions preserve Atomicity. Of these, triggers involve application code and therefore are most subject to the following discussion. |
![]() | Implementing Web Services Safely |
---|---|
To safely implement web services inside a transaction, an application must implement a guaranteed upper bound on the time taken by the service. The story or use case for each circumstance determines the appropriate timeout for the corresponding transaction. For example, if the web service is to authorize a transaction, there might be a 500 millisecond timeout with the authorization refused if the approval service does not respond within that time. There are two approaches to implementing web services with a timeout.
|
To achieve the best GT.M performance, transactions should:
TSTART ():SERIAL SET (ACCT,^M(0))=^M(0)+1 SET ^M(ACCT)=PREC,^PN(NAM)=ACCT TCOMMIT
TSTART ():SERIAL IF $TRESTART>3 DO QUIT .TROLLBACK .WRITE !,"Too many RESTARTs" .QUIT SET (NEXT,^ID(0))=^ID(0)+1 SET ^ID(NEXT)=RECORD,^XID(ZIP,NEXT)="" TCOMMIT
%GTM-I-TPRESTART, Database /gbls/dtx/dtx.dat; code: L; blk: 0x00BA13DD in glbl: ^DTX; pvtmods: 0, blkmods: 1, blklvl: 1, type: 4, readset: 3, writeset: 1, local_tn: 0x00000000000002D0, zpos: LABEL+108^ROUTINENAME
![]() | Note |
---|---|
|
trans ;This sets up the program constants ;for doit and trestart new set $piece(peekon,"V",51)="" set $piece(peekon,"V",25)="Peeking inside Job "_$job set $piece(peekoff,"^",51)="" set $piece(peekoff,"^",25)="Leaving peeking Job "_$job ;This establishes the main loop set CNFLTMSG="Conflict, please reenter" for read !,"Name: ",nam quit:'$length(nam) do .if "?"=nam do quit ..write !,"Current data in ^trans:",! do:$data(^trans) quit ...zwrite ^trans .for set ok=1 do quit:ok write !,$char(7),CNFLTMSG,$char(7),! ..set old=$get(^trans(nam),"?") ..if "?"=old write !,"Not on file" do quit ...;This is the code to add a new name ...for do quit:"?"'=data ....read !,"Enter any info using '#' delimiter: ",!,data ...if ""=data write !,"No entry made for ",nam quit ...TSTART ():SERIAL if $$trestart ;$$trestart for demo ...if $data(^trans(nam)) set ok=^trans(nam)=data TROLLBACK quit ...set ^trans(nam)=data ...TCOMMIT:$$doit ;$$doit for demo ..;This is the beginning of the change and delete loop ..for do quit:+fld=fld!'$length(fld) write " must be numeric" ...write !,"Current data: ",!,old ...read !,"Piece no. (negative to delete record) : ",fld ..if 'fld write !,"no change made" quit ..;This is the code to delete a new name ..if fld<0 do quit ; delete record ...for do quit:"YyNn"[x ....write !,"Ok to delete ",nam," Y(es) or N(o) <N>? " ....read x set x=$extract(x) ...if "Yy"'[x!'$length(x) write !,"No change made" quit ...TSTART ():SERIAL if $$trestart ;$$trestart for demo ...if $get(^trans(nam),"?")'=old TROLLBACK set ok=0 quit ...kill ^trans(nam) ...TCOMMIT:$$doit; $$doit for demo ..;This is the code to change a field ..for read !,"Data: ",data quit:("?"'=data)&(data'["#") do ...write " must not be a single '?' or contain any '#'" ..TSTART ():SERIAL if $$trestart ;$$trestart for demo ..if '$data(^trans(nam)) set ok=0 TROLLBACK q ..if $piece(^trans(nam),"#",fld)=$piece(old,"#",fld) do quit ...set ok=$piece(^trans(nam),"#",fld)=data TROLLBACK ..set $piece(^trans(nam),"#",fld)=data ..TCOMMIT:$$doit; $$doit for demo quit doit() ;This inserts delay and an optional ;rollback only to show how it works write !!,peekon do disp for do quit:"CR"[act .read !,"C(ommit), R(ollback), or W(ait) <C>? ",act .set act=$translate($extract(act),"cr","CR") .if "?"=act do disp if "R"=act TROLLBACK write !,"User requested DISCARD" write !,peekoff,! quit $TLEVEL trestart() ;This is only to show what is happening if $TRESTART do .write !!,peekon,!,">>>RESTART<<<",! do disp write !,peekoff,! quit 1 disp write !,"Name: ",nam write !,"Original data: ",!,old,!,"Current data: " write !,$get(^trans(nam),"KILLED!") quit
Generally, this type of program would be receiving data from multiple sessions into the same global.