Java Reference
In-Depth Information
not update the row and instead alerts the user. To see how this pattern works, let's
look at an example.
13.2.1
Applying the Optimistic Offline Lock pattern
The scenario shown in figure 13.2 illustrates how the Optimistic Offline Lock pat-
tern can be used to handle concurrent updates for the Acknowledge Order use
case. In this scenario, user A is attempting to acknowledge the order while user B
cancels the order.
The sequence of events is as follows:
User A: Acknowledge Order
User B: Cancel Order
Transaction A.1:
BEGIN TRANSACTION
SELECT VERSION, ...
FROM PLACED_ORDER
WHERE ORDER_ID = ?
COMMIT
Transaction B.1:
BEGIN TRANSACTION
SELECT VERSION, ...
FROM PLACED_ORDER
WHERE ORDER_ID = ?
...
UPDATE
PLACED_ORDER
SET
STATUS='CANCELLED',
VERSION = VERSION + 1
WHERE ORDER_ID = ? AND
VERSION = ?
Transaction A.2:
COMMIT
BEGIN TRANSACTION
UPDATE
PLACED_ORDER
SET VERSION = VERSION + 1
...
WHERE ORDER_ID = ?
AND VERSION = ?
Figure 13.2
An example of how the Optimistic Offline
Lock pattern handles concurrent updates
...FAIL...
Time
 
 
Search WWH ::




Custom Search