Unlocking a cursor
542197Jun 12 2007 — edited Jun 13 2007I worked out a piece of code sometime ago with the help of Greybird, which basically looks up a record in a database, if it is there updates it, if not creates it. It works for multiple threads doing the same thing, locking the record with an RMW lock with the initial getSearchKey() cursor call.
Problem is, at the end of this routine it must release the lock, or you get horrendous deadlock problems. I used to do this by calling getNext(). Thing is, there was not always a next record (as you could be updating the last record). So now I do a getNext() if doing an update, followed by a getLast() if that failed. In the case of an insert, I do a getPrev() and if that fails, a getFirst(). It all seems a little random to me. Is there a better way of doing this (unlocking a cursor)? For example, it is shame you can't reposition on the current position, and lose the lock.