122 Transaction management Here we now see the

122 Transaction management Here we now see the fundamental difference between the two approaches. In the pessimistic case, an exception at commit time might mean that the user entered data that violated integrity constraints or was otherwise invalid. If the user s data had been valid, the commit would have been successful (system failures aside). In the optimistic case, even valid data changes might be rolled back at transaction completion time, simply because the data had been changed by someone else in the interim. The user must review the now-changed data, and then perform the required changes again if they still apply. Given that the likelihood of concurrency assumptions failing is usually small, such rework is unlikely to be required often. In some cases this is acceptable if a user does go out for lunch whilst updating a business partner s details, they increase the risk of having to redo the work. They should complete the task at hand before leaving! In other cases, however, such strategies are not acceptable. Almost all server- side transactions will be pessimistic (except those which must be open across user interaction on a remote client). It is up to the designer to make an appropriate choice based upon the concurrency requirements of the system, and the cost (in terms of staff time and morale as well as any financial implications) of work needing to be redone should optimistic concurrency assumptions fail. 7.3.3 Optimistic transactions and refresh Before we look at more advanced transaction management features, I d like to mention two potential uses of the persistence manager s refresh() methods within optimistic transactions. 7.3.3.1 Last commit wins When an instance is passed as an argument to one of the persistence manager s refresh() methods, the field values are restored to those currently in the data store. After an instance has become part of an optimistic transaction, there is a possibility that the persistent entity will have been changed before the optimistic transaction is committed, causing optimistic concurrency assumptions to fail and the transaction to be rolled back. The incidence of this can be reduced if field values in an optimistically locked instance are refreshed immediately before they are updated. By retrieving field values, the optimistic currency assumptions are reset to reflect the current state of the instance. If refresh() is invoked immediately before the instance is updated and the transaction committed, then the likelihood of concurrency assumptions proving to be incorrect is greatly reduced.
Note: If you are looking for cheapest and affordable webspace to host and run your servlet application check Astra servlet hosting services

Comments are closed.