The suggestion of using the http session (its id actually) was pretty cool I thought. That allows you to "timeout" the checkout/lock. You need to make sure (as pointed out) that the locks don't get orphaned, thereby locking everyone out of the object/record perpetually (obviously you could write an admin screen to unlock it).
On 2/20/07, Barry Books <[EMAIL PROTECTED]> wrote:
Murray, I also have records that need to be 'checked out' for some time and your solution seems simple and elegant. So much so I may steal it. I use one sequence for every primary key in the database so a table named "lock" with key primary key timestamp timestamp userid should do it. UserId lets me know who has it. to see if a record is locked and get lock key select count(*) as locked, key, timestamp from lock where key = ? and timestamp less than 20 minutes old group by key, timestamp 1 is locked 0 unlocked timestamp is the key to lock the recored to lock a record if key == null insert into lock values ( key, now, userid) else update lock set timestamp = now, userid = ? where key = ? and timestamp = ? if you update 1 row you've got it otherwise someone else does to unlock update lock set timestamp = null where key = ? and timestamp = ? if you don't get 1 row updated something bad happened Seems easy. Records are locked a max of 20 minutes and no races I can see. --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]