Java Reference
In-Depth Information
Methods such as updateDeliveryInfo() and updateQuantities() , which are
called during the use case, verify that the order is still locked. The saveChanges-
ToOrder() and cancelModifyOrder() , which are called at the end of the use case,
first verify that the order is still locked and then unlock it.
Let's now see how using the Pessimistic Offline Lock pattern to implement the
Modify Order use case affects the implementation of other use cases.
13.7.3
Adapting the other use cases
We saw in section 13.5.3 that one consequence of using the Pessimistic Offline
Lock pattern is that all use cases that update the same shared data must lock and
unlock objects. In the Food to Go application, this means that if the implementa-
tion of the Modify Order use case uses a LockManager , then the other use cases
that update orders must do so as well. This section examines the impact that this
has on the Send Orders to Restaurant and Acknowledge Order use cases.
Changing the Send Orders to Restaurant use case
Even though the Send Orders to Restaurant use case consists of a single database
transaction, it must use the LockManager to lock the orders before sending them
and unlock them afterward. Listing 13.5 shows the domain model version of the
business logic that does this.
Listing 13.5
DomainRestaurantNotificationService
public class DomainRestaurantNotificationService
bb public boolean sendOrders(String caller) {
bbbb Collection orders =orderRepository.findOrdersToSendToRestaurant();
bbbb Collection lockedOrders = new ArrayList();
bbbb for (Iterator it = orders.iterator(); it.hasNext();) {
Order order = (Order) it.next();
bbbbbb b if(!lockOrder(caller,order))
continue;
Locks the order
Skips already locked orders
Remembers locked order
lockedOrders.add(order);
b Restaurant restaurant = order.getRestaurant();
NotificationDetails notificationDetails = notificationGateway
.sendOrder(order);
Date timestamp = notificationDetails.getTimestamp();
String messageId = notificationDetails.getMessageId();
order.noteSent(messageId, timestamp);
}
unlockOrders(lockedOrders);
return !orders.isEmpty();
}
Unlocks previously
locked orders
 
 
 
Search WWH ::




Custom Search