This week's book giveaway is in the OCPJP forum. We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line! See this thread for details.
User1 View RecNo1 User2 Del RecNo1 User3 Add new record (as RecNo will be reuse, user 3 will use back RecNo1 for difference data) Back to user1 he decide to edit/delete the RecNo1 after view...
Problem came as the RecNo1 expected by User1 are not the one in database now.
To prevent that problem, I will using timestamp as below:
- Read the database during system startup and build a hashtable contain recNo and assign each with a timestamp value. - When user get the Record (will return as JavaBean object), timestamp associate with that recNo (from hashtable) will be set. - That timestamp will be use to compare the current timestamp associate wit h that record during edit/delete.
There for: User1 View RecNo1 (current db, RecNo1 have timestamp x) User2 Del RecNo1 (current db, RecNo1 had remove) User3 Add new record (as RecNo will be reuse, user 3 will use back RecNo1 for difference data) (current db, RecNo1 have timestamp y) so when User1 want to edit/delete, system will alert user that timestamp in the object are difference from database.
My approach is ok? Anyone have a better suggestion or alternative approach?
Note: I using service side locking as lock() method implement didn't return any value (it is void), so not able implement client side locking.