TurboIMAGE/XL Database Management System Reference Manual MPE/iX V6.5 (30391-90011)
122 Chapter4
Using the Database
Using the Locking Facility
or the dynamic transaction is aborted.
NOTE
A call to DBXUNDO must be processed if an error occurs or if the transaction
needs to be rolled back for any other reason, because TurboIMAGE/XL will
not go on to the next transaction in the event of a transaction abort unless an
intervening call to DBXUNDO occurs. Furthermore, if DBXUNDO was used to roll
back a transaction, the program logic should ensure that the subsequent call
to DBXEND is not processed.
Choosing an Item for Locking
An important convention to follow in designing a locking scheme is that all programs
sharing the database concurrently use the same data item to lock data entries in a
particular data set. At any one time, TurboIMAGE/XL allows no more than one data item
per data set to be used for locking purposes. However, several values of the data item can
be locked at the same time. For example, if one process has successfully locked
SALES:ACCOUNT = 54321000, another process could lock SALES:ACCOUNT = 11111111. If a
request is made to unconditionally lock SALES:STOCK# = 8888X22R, the requesting process
will be made to wait until all entries locked by ACCOUNT number are unlocked.
Furthermore, any new requests for locking other SALES:ACCOUNT values will wait until
SALES:STOCK# = 8888X22R is successfully locked and unlocked again.
With this in mind, it is apparent that it is more efficient if all processes locking data
entries in the SALES data set use the same data item because it is much less likely that
one process will have to wait until another process finishes using the data. Therefore, at
system design time, decide which item will be used in each data set for lock specification
purposes. It can be useful to add comments in the schema indicating which item is the
locking item for each set. If a chain is used heavily for chained reads, its search item is a
prime candidate for a lock item.
Examples of Locking
The examples in this section show the order in which TurboIMAGE/XL intrinsics can be
called when locking is used. The ORDERS database is used in the examples. (Refer to the
ORDERS database schema in chapter 3.) For descriptions of the procedures used in these
examples, refer to chapter 5.
Table 4-4. contains guidelines that can be helpful in designing locking schemes for
shared-access environments which include users who might modify the database.
Although data entry level locks are recommended in this table and illustrated in the
following examples, data set or database locks could be more appropriate for similar tasks
depending upon other application requirements.