TMF Introduction (G06.26+)

TMF Application Programming
HP NonStop TMF Introduction522414-002
5-6
Accessing Enscribe Data
The syntax for accessing Enscribe data and specifying isolation level of the application
varies depending on the programming language. Typically, servers issue lock requests
for all the data they update and for some of the data they read. The servers are
responsible for issuing unlock requests when they finish their tasks, but they also need
to provide for potential errors. Typically, servers include requests to unlock data as
follows:
For successful database access, the server issues an unlock file statement and
then replies to the requester.
For unsuccessful database access, the server omits unlock file statements
(therefore retaining the locks) and then replies to the requester about the failure.
As examples of accessing Enscribe data, consider the following uses of an HP COBOL
application.
Using Locks With READ and REWRITE Statements in an HP
COBOL Program
The READ statement specifies locking for the record being read:
READ EMP-MASTER WITH LOCK KEY IS EMP-NO-KEY OF EMP-REC.
IF EMP-FIELDS OF EMP-REC = SAVED-EMP-FIELDS OF EUPDATE-MSG
PERFORM 970-REWRITE-EMP
970-REWRITE-EMP.
REWRITE EMP-REC WITH UNLOCK.
READ WITH LOCK ensures that no other user can read the record; it acquires a lock
on the record for subsequent updating. For REWRITE, TMF requires that the
transaction has previously locked the record. UNLOCK on the REWRITE statement
indicates that the program has completed accessing the record. The locks held by the
transaction on the rewritten record are held until the transaction is either committed or
backed out.
Using Repeatable Reads in an HP COBOL Program
The program locks records it reads and uses in the transaction even though the
records are not changed. By locking the records, the program ensures that the
transaction’s reads are repeatable:
READ EMP-MASTER WITH LOCK KEY IS EMP-NO-KEY OF EMP-REC.
IF EMP-FIELDS OF EMP-REC = SAVED-EMP-FIELDS OF EUPDATE-MSG
.
.
ELSE
UNLOCKRECORD EMP-MASTER
Until it issued UNLOCKRECORD, the program had repeatable reads.