120 Transaction management catch (JDOException je) { //

Transaction strategies 121 whether the business partner object has been changed. This check verifies the optimistic concurrency assumptions and locks the underlying entity. 4 Assuming that the data store entity has not been changed, the updated data is synchronized to the data store and the short-lived pessimistic transaction is immediately committed. 5 The results of this commit are relayed back to the application. Thus, if the pessimistic transaction was rolled back for any reason, the application would be informed through an appropriate exception. 6 The optimistic concurrency assumptions would be false if the data was changed by someone else after the business partner was read, but before the optimistic transaction was committed. In this case, the short-lived pessimistic transaction would be rolled back and an appropriate exception thrown to the application. So that s how it works internally. Let s take a look at a code example of an optimistic transaction: Transaction t = pm.currentTransaction(); t.setOptimistic(true); t.begin() try { // do some work here which might take an extended time, // hence the use of optimistic locking. e.g. obtain a // BusinessPartner, show the field values to the user // and wait for the user to alte the data and press a // “save” button, before which the user might go out // for lunch! } catch (Exception e) { // rollback the transaction if it is still active if (t.isActive()) t.rollback(); } finally { try { // commit the transaction if it is still active if (t.isActive()) t.commit(); } catch (JDOUserException je) { // transaction rolled back advise the user that // the work they did has not been saved and must // be done again } } The only significant code differences between the two locking strategies are the setting of the Optimistic transaction property to false, and the catching of JDOUserException after commit().
Note: If you are looking for reliable and quality webspace company to host and run your servlet application check Actions servlet hosting services

Comments are closed.