Hi,
If a client read a record during another client update it(It could happen if I only use lock for update/delete record), the client that read the record would show incorrect information.
This can't be helped. Whenever a record is displayed in the gui,
you should always assume that it is outdated. What happens if the user performs a search, goes out to lunch, comes back, and then tries booking one of the records? So think of the information in your GUI as a snapshot of the database from a previous instance in time.
Locking the record comes into play when you actually want to manipulate the data in a record (for example, when you want to book a record). This is when it becomes important that the record you read does not change. You need to insure that you can read the record, change the data, and write the record as one atomic operation.
How do you deal with this problem?
When a request comes from the client to the server to book a particular record, I do not sent that request directly to the Data class. This is because booking a record isn't just updating the owner field of the record. It involves several steps:
1. lock the record to be booked to insure it's data cannot be changed by another client2. read the record from the database to get its current state3. if the record is already booked, inform the client that the record is already booked4. if not booked, update the record5. unlock the record Instead, I have a DataAdapter class that talks to the Data class. In the DataAdapter class, I have a method called bookRecord. Inside this method, I call Data.lock(recNo), Data.read(recNo), verify some information, Data.update(recNo, newData), Data.unlock(recNo).
[ November 06, 2004: Message edited by: Jared Chapman ]