An easier approach is to add two columns. LockedBy and LockedOn. When a user begins an edit, lock the record recording the ID and the Time. When they commit remove the lock. Don't let anyone edit the record if it has a lock, or let them see who locked it when and force remove the lock. This way you can also expire locks that are X minutes old, or when a users session ends, remove all there locks. I've used this approach before and it works rather well.
___________
Eric Hodges
$_='y==QAe=e?y==QG@>@?iy==QVq?f?=a@iG?=QQ=Q?9';
s/(.)/ord($1)-50/eigs;tr/6123457/- \/|\\\_\n/;print;
| [reply] |
Do you know what the management loves? They love a little javascript ticker that shows how long until the lock times out - gives the person editing a sense of urgency and when it clicks down to 0 seconds they know they will have to start again...
Now I find it a naff idea - but I don't pay my wages.
| [reply] |
Why are you looking at these complex solutions? Is there a problem with a simple pessimistic locking approach, like creating a lock file when someone goes to the edit page and removing it when they save or adding a "signed_out_by" column in the database table? There are issues with people leaving that screen open and walking away, but you can use javascript and timeouts to help with that. | [reply] |
hi,
Across consistency in web pages, you can go with explicit locking and don't allow more that one user to transact with table at-a-time, rather handling it with in CGI or front-end.
-kulls
| [reply] |
Optimistic locking may work for your application, but for some apps it's not an acceptable solution:
- When the user queries a row for editing generate a hash of said row
- When the user requests that the row is saved, regenerate the hash of the existing row. If it matches the original hash, then complete the save - otherwise let the user now that the row was changed by someone else
The problem that I've encountered with locking web apps, is that rows get checked out/locked, and then the user gets distracted, called into a meeting etc and they never remember to unlock the record. Optimistic locking solves this problem, but it may not suit your business rules
| [reply] |