OpenTP1 Version 7 Programming Guide

[Contents][Index][Back][Next]

4.2.6 Lock for TAM tables

If another UAP starts TAM table update processing while a TAM file is being updated, the results of both update processing are concurrently reflected into one record. Consequently, the table contents include conflicting information. To prevent this problem, specify lock in the function to access the TAM file. Specifying lock ensures that the data items accessed from UAPs match each other.

Lock for DAM files is managed in global transactions.

Organization of this subsection
(1) Lock modes
(2) Lock units
(3) Specification for awaiting unlocking of resources

(1) Lock modes

Lock conditions for accessing TAM tables are called lock modes. The following lock modes are available:

Lock for reference (shared mode PR Protected Retrieve):
Only records with lock specified can be referenced. Only reference from another global transaction is permitted.

Lock for update (exclusive mode EX EXclusive):
Records or tables with lock specified can be referenced and updated. Reference or update processing from another global transaction is not permitted.

(2) Lock units

Lock can be specified in units of records or tables when a TAM table is accessed in online mode as explained below.

(a) Record-based lock

Lock is enabled in records. When a record is input for reference processing, specify whether to enable lock for reference or not (other UAPs allowed to do update processing). When a record is input or updated for update processing, specify lock for update. The acquired lock is reset when the transaction that specified processing for the TAM table terminates normally.

(b) Table-based lock

Lock is enabled in tables. When a TAM table is opened under tables-based lock or when a record is added/deleted, specify lock for update for the entire TAM table. The acquired lock is reset when the transaction that specified processing for the TAM table terminates normally. If tables are opened before a transaction is started, tables-based lock cannot be specified for the tables.

(3) Specification for awaiting unlocking of resources

If an attempt is made to access a TAM table which is locked by another UAP (lock error), the function for this access will return with an error or wait until the TAM table is unlocked. This can be specified in the argument to the function.

If wait until unlocking is specified and a deadlock or timeout occurs, deadlock information will be output after the function waiting for an unlocked TAM table returns with an error. If the function returns with a deadlock or timeout error, acquire the synchronization point of the transaction and free all the acquired resources.

For UAPs written in COBOL, use either of the following methods to specify whether the function for access will wait until the TAM table is unlocked:

See the manuals OpenTP1 System Definition and OpenTP1 Programming Reference COBOL Language on how to specify for COBOL UAPs whether the function for access will wait until the resource is unlocked.

The table below indicates how lock specifications in TAM service functions are related to actual lock statuses. UAPs written in COBOL lock or unlock resources by using API functions for record access.

Table 4-9 Lock specifications in TAM service functions and actual lock statuses

Value assigned to flags on TAM service function TAM table lock TAM record lock
dc_tam_open Table-based lock Update lock --#1
Record-based lock A record is locked using a function for access to the record.
dc_tam_read For referencing No lock -- --
Lock possible Lock for referencing#2 Lock for referencing
For update Lock for referencing#2 Update lock
dc_tam_rewrite Lock for referencing#3 Update lock#3
dc_tam_write For update Lock for referencing#2 Update lock
Either for update or addition or for addition Update lock --#1
dc_dam_delete Update lock --#1

Legend:
--: Not applicable

#1
Since the entire table is locked for updating, it is inaccessible to other transactions.

#2
A table of the reference type or the update type without permission for addition or deletion cannot be locked in this mode if "unlocked" is specified as the table lock mode in the TAM service definition.

#3
The resource is already made available by the function dc_tam_read() for update.