Difficulty: Hard
Correct Answer: By using a dedicated lock table or dummy update technique so that a transaction updates or marks a specific row and thereby holds a lock on it.
Explanation:
Introduction / Context:
Some early DB2 and related environments did not provide flexible row level locking in the way that modern systems do. Developers sometimes had to implement their own logical locking strategies to prevent concurrent users from updating the same business record at the same time. This question checks whether the candidate understands the general idea of simulating record locks with application level constructs.
Given Data / Assumptions:
Concept / Approach:
A common approach is to use an auxiliary lock table or a dummy update on the row that acts as a logical lock. For example, when a transaction wants to work on a business entity, it inserts or updates a corresponding row in a lock table or sets a status flag. Because this action uses the database locking mechanism at table or row level, other transactions that attempt the same operation will block or fail, effectively simulating record level locking for the application.
Step-by-Step Solution:
Step 1: Identify the logical key that uniquely represents the business record, such as a customer or order ID.
Step 2: Create a lock table that contains this key and a marker indicating that the record is in use, or perform a dummy update on the business record itself.
Step 3: When a transaction starts, it tries to insert or update the lock table row for that key.
Step 4: If the insert or update succeeds, the transaction holds a lock granted by DB2 on that row, simulating a record level lock.
Step 5: When the transaction completes and commits or rolls back, it deletes or resets the lock entry so that other transactions can acquire it later.
Verification / Alternative check:
Testing this approach shows that if one transaction has successfully inserted a lock row and not yet committed, another transaction attempting the same insert will be blocked or receive a duplicate key error. This behavior demonstrates that the database locking mechanism on the lock table is enforcing mutual exclusion, which is the central idea of record locking, even if the underlying DBMS does not provide a built in row lock on the target data table.
Why Other Options Are Wrong:
Option B is wrong because time sharing alone does not guarantee that two transactions will not access the same data concurrently; explicit coordination is needed.
Option C is wrong because disabling indexes does not prevent concurrent access; it mainly harms performance and does not provide logical locking.
Option D is wrong because scheduling all jobs sequentially is impractical in multiuser systems and does not scale for realistic workloads.
Common Pitfalls:
A common pitfall is to implement custom locking without carefully designing commit and rollback behavior, leading to orphaned lock rows that block other users. Another mistake is to forget to handle lock timeouts or duplicate key errors gracefully in the application. Proper design requires clear conventions for when locks are acquired, how they are released, and how errors are surfaced to users or calling programs.
Final Answer:
In environments without direct record locking, the usual solution is to use a dedicated lock table or dummy update technique so that a transaction updates or marks a specific row and thereby holds a lock on it.
Discussion & Comments