Clayton Arends
Member²
Dear Board (most likely MKALTER
),
I am looking for a little help concerning design of the following scenario. I am trying to make my application make use of the database in a manner in which multiple users (from different machines) can edit in the system at the same time and not step on each others toes. If a user is currently editing a record it is locked while the user is editing and unlocked when the user saves or cancels changes. If another user attempts to edit the same record an error message displays telling the user to "wait in line." All of this currently works with the following caviots.
The problem I have is that if I have multiple locks for different records (on the same machine) and a change to one of the records is committed then the locks for the other records are removed (because that's what happens when Commit() or Rollback() is invoked for the session). What I am currently doing is keeping track of all records that should be locked and after a commit or rollback I iterate through the list and relock the remaining records.
The problem I have with what I'm doing is two-fold. 1) There is a moment (however tiny) between the Commit and the relocking where another user might be able to gain a lock on the record and begin editing before the lock is reissued to the user who is really the one editting the record. 2) I have to add the call to relock the records everywhere in my code that can possibly commit or rollback the session. This is quite redundant and messy.
So my question is this. How can I make this system of locking better, more efficient?
1) Should I make my own Commit and Rollback methods which will invoke the real Commit or Rollback and then relock the records? This would be okay but obviously isn't very good since I would have to make sure all of my code invokes the correct method.
2) Is there an event that will fire after any commit or rollback? This would be better since I can even perform a commit or rollback inside a query and not have to worry about missing the call.
3) Is there a better method of locking records of a table that I'm missing? I'm basically an intermediate Oracle developer (and then only slightly knowledgable of all that is available to me). For instance, I just found out today that I can lock a record in a table.
Here is the method I use for locking a record. Whenever I want to lock a record of a table I perform a query somewhat like the following:
SELECT * FROM table WHERE conditions FOR UPDATE NOWAIT;
If there is a better method then please instruct me. The solution has to be able to work in Oracle 7, 8, 8i +, and it has to work with the basic packages that are installed on every Oracle installation since I cannot rely on all users having all of the cool packages installed.
Also, this is a medium sized system that stores many different sorts of data. It isn't rare that a user will be editing five records at the same time. So limiting a user to editing one record at a time is not an options.
Thanks for any help,
Clayton

I am looking for a little help concerning design of the following scenario. I am trying to make my application make use of the database in a manner in which multiple users (from different machines) can edit in the system at the same time and not step on each others toes. If a user is currently editing a record it is locked while the user is editing and unlocked when the user saves or cancels changes. If another user attempts to edit the same record an error message displays telling the user to "wait in line." All of this currently works with the following caviots.
The problem I have is that if I have multiple locks for different records (on the same machine) and a change to one of the records is committed then the locks for the other records are removed (because that's what happens when Commit() or Rollback() is invoked for the session). What I am currently doing is keeping track of all records that should be locked and after a commit or rollback I iterate through the list and relock the remaining records.
The problem I have with what I'm doing is two-fold. 1) There is a moment (however tiny) between the Commit and the relocking where another user might be able to gain a lock on the record and begin editing before the lock is reissued to the user who is really the one editting the record. 2) I have to add the call to relock the records everywhere in my code that can possibly commit or rollback the session. This is quite redundant and messy.
So my question is this. How can I make this system of locking better, more efficient?
1) Should I make my own Commit and Rollback methods which will invoke the real Commit or Rollback and then relock the records? This would be okay but obviously isn't very good since I would have to make sure all of my code invokes the correct method.
2) Is there an event that will fire after any commit or rollback? This would be better since I can even perform a commit or rollback inside a query and not have to worry about missing the call.
3) Is there a better method of locking records of a table that I'm missing? I'm basically an intermediate Oracle developer (and then only slightly knowledgable of all that is available to me). For instance, I just found out today that I can lock a record in a table.
Here is the method I use for locking a record. Whenever I want to lock a record of a table I perform a query somewhat like the following:
SELECT * FROM table WHERE conditions FOR UPDATE NOWAIT;
If there is a better method then please instruct me. The solution has to be able to work in Oracle 7, 8, 8i +, and it has to work with the basic packages that are installed on every Oracle installation since I cannot rely on all users having all of the cool packages installed.
Also, this is a medium sized system that stores many different sorts of data. It isn't rare that a user will be editing five records at the same time. So limiting a user to editing one record at a time is not an options.
Thanks for any help,
Clayton