TurboIMAGE/XL Database Management System Reference Manual MPE/iX V6.5 (30391-90011)

Chapter 4 117
Using the Database
Using the Locking Facility
Using the Locking Facility
The DBLOCK procedure applies a logical lock to a database or one or more data sets or data
entries. The DBUNLOCK procedure releases these locks.
Locking can be viewed as a means of communication and control to be used by mutually
cooperating users. The locking facility provides a method for protecting the logical
integrity of the data shared in a database. With the DBLOCK procedure, application
programs can isolate temporarily a subsection of the database in order to perform a
transaction against the isolated data. Locking is not required to protect the structure of
the database. TurboIMAGE/XL has internal mechanisms that do this.
If a program opens the database in access mode 1 and locks a part of the database, it can
perform the transaction with the certain knowledge that no other user will modify the data
until the application program issues a DBUNLOCK call. This is because TurboIMAGE/XL
does not allow changes in access mode 1 unless a lock covers the data to be changed. If one
process has the database opened in access mode 1, TurboIMAGE/XL requires that all other
processes that modify the database must also operate in access mode 1.
The DBLOCK procedure operates in one of six modes. Modes 1 and 2 can be used for locking
the database and modes 3 and 4 for locking a data set. In modes 5 and 6, you describe the
database entity or entities to be locked using lock descriptors.
At the data entry level, locking is performed on the basis of data item values. For example,
suppose a customer requests a change in an order the customer has placed. The data
entries for the customer's account that are in the SALES data set could be locked while the
order is changed and other database activity can continue concurrently.
Lock Descriptors
A lock descriptor is used to specify a group of data entries that are to be locked. It consists
of a data set name or number, a data item name or number, a relational operator, and an
associated value. For purposes of this discussion, the notation dset : ditem relop value is
used. For example, the lock descriptor SALES:ACCOUNT = 89393899 requests locking of all
the data entries in the SALES data set with an ACCOUNT data item equal to 89393899.
Note that the result of specifying a single lock descriptor can be that none, one, or many
entries are locked depending on how many entries qualify.
The following relational operators can be used:
less than or equal (<=)
greater than or equal (>=)
equal (= or =), where indicates a space character
The value must be specified exactly as it is stored in the database. A lock will succeed even
if no data item with the specified value exists in the data set; no check is made during the
DBLOCK procedure to determine the existence of a particular data item value. This allows
you to use techniques such as issuing a lock to cover a data entry before you actually add it
to a data set.