But if you use thick client approach:
1/ user hits book-button, record is locked, dialog opens, user enters customer-id, user confirms dialog/booking and record is updated and unlocked
2/ user hits book-button, dialog opens, user enters customer-id, user confirms dialog/booking and record is locked, updated and unlocked
I was going to ask exactly the same question about these two locking strategies :-)
I want to implement the first approach and these are my argumentations:
- When the CSR select the record and click "Book..." button, the record will be re-readed from database (to ensure that it is not stale), after that the records gets locked and booking dialog window opens, where only Owner ID field is editable. During this operation CSR will be confident that another CSR (who probably type faster) will not "intercept" his record in it's process of booking.
- because of slow typing or coffe break the lock may be held pretty long time, so I implemented the timed version of my lock record (beyound the base interface, of course) which tries to get lock no longer than n seconds (2sec. <= n <= 5sec.) and if this method return false, the message like "This record is temporarily locked by another CSR. Try again later" will appear.
approach 2 is easier in implementation, but IMO it has serious drawback: CSR certainly will not be happy if he picked up a free record, opened the booking dialog, type the client number, and after pressing "Confirm booking" button suddenly get an error, because another faster CSR has already booked the same record couple of seconds ago :-(
Please, answer me:
1) is my described approach sensible?
2) will I not be punished for using my timed version of lock() method, instead of timeless version provided by assignment interface? Of course, I created both versions to implement interface.
3) My GUI client will not allow to lock more than one record at a time, but what about business service layer? What if the same client already has a lock and is trying to obtain another record's lock? What do I need to do:
a) simply allow to obtain multiple lock but write some warning message to log about possible deadlock?
b) silently release the previous lock before obtaining the new one?
c) throw some kind of RuntimeException and do not allow to aquire second lock?
Thank you in advance for your valuable answers!