aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Data integrity at reservation booking time? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Data integrity at reservation booking time?" Watch "Data integrity at reservation booking time?" New topic
Author

Data integrity at reservation booking time?

Cless Alvein
Ranch Hand

Joined: Jun 18, 2007
Posts: 39
I am concerned about the following scenario:

Client requests data from database and displays it to user. Record numbers are cached, client-side.
User looks through JTable and chooses their desired reservation (record entry).

--meanwhile--
An administrator decides to delete the record, making it available to be overwritten.
A new record entry is inserted, overwriting the old one. Because I am planning to use the index of the record as the record number, the new record and the deleted one share the same record number.

--back to the client--
The user decides to make a reservation.
The client tells the server/database to book the reservation with the specified record number.
Now, the client has booked the wrong reservation!

Do we have to worry about a scenario like this?? Because we do not have to handle dirty reads, I think the answer is no, but I would like to be sure, or if anyone has ideas for an easy-to-implement solution, that would be appreciated.

Thanks!
Jason Moors
Ranch Hand

Joined: Dec 04, 2001
Posts: 188
Hi Cless,

I think you can justify in your design decisions not implementing functionality to handle this scenario as you can assume only one program is accessing the file, therefore no other program should be deleting records.

You may assume that at any moment, at most one program is accessing the database file;


However it wouldn't be very difficult to include logic to handle the scenario, as when booking a record you are performing the following steps.

1) Lock record
2) Read the record to check that it hasn't been booked
3) Update the record to indicate that it has been booked
4) Unlock record

I don't see any reason why you couldn't also check that the fields match in step 2, before updating the record.

Regards
Jason
[ June 20, 2007: Message edited by: Jason Moors ]
Cless Alvein
Ranch Hand

Joined: Jun 18, 2007
Posts: 39
Jason,

Thanks for your input. I agree that the clause stating that only one program will be accessing the database does make things clearer. I will just assume that no delete operations will be called during normal use of the software.
Mandy Bowman
Ranch Hand

Joined: Jan 24, 2007
Posts: 32
Strictly speaking though is this needed:

1) Lock record
2) Read the record to check that it hasn't been booked
3) Update the record to indicate that it has been booked
4) Unlock record
Cless Alvein
Ranch Hand

Joined: Jun 18, 2007
Posts: 39
Hi Mandy,

that is exactly what I was going to implement in my program. My original question was: what if the record was updated between the time that the client read all the records and the time that they try to book a record? This is not a case of thread racing, but rather a possible design flaw.

To avoid it, I would have to keep track of all updates made to records, and then notify the client if their desired record has been changed between those two times. Since I am assuming that no server-side person will update or delete-then-overwrite any records, this problem can be overlooked.
Mandy Bowman
Ranch Hand

Joined: Jan 24, 2007
Posts: 32
Oh I see now. I was thinking on some other lines though. What I'm wondering is whether our read methods need to lock the record we want to read since just before we call read we lock the record anyway.
Lorenz Baylon
Ranch Hand

Joined: Jan 04, 2006
Posts: 99
Hi guys,

1) Lock record
2) Read the record to check that it hasn't been booked
3) Update the record to indicate that it has been booked
4) Unlock record


I'd like to ask, if a particular record has been locked for reading by a client-side user, can that record be still modified by a server-side user at any given instance, or do other users need to wait until the lock for that record has been released?

Regards,

Lhorenz


I just cant look, its killing me.
Cless Alvein
Ranch Hand

Joined: Jun 18, 2007
Posts: 39
@Mandy: A record does not have to be locked to read it - however, I would think that it would be wise to have all low-level I/O operations be synchronized, especially if you are using RandomAccessFile, as I am. This is because you do not want the file pointer to be inadvertently moved by one thread while another is trying to do something with it.

@Lhorenz: Since a server-side user would be calling the same methods as a client-side user, I would believe that if a client decides to lock a record, a server-side user would have to wait. However, in my project specifications, there is no mention of a server-side user (such as an administrator) so I don't think that this is a serious issue.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Data integrity at reservation booking time?
 
Similar Threads
Questions about automatic failure
URLyBird: Just started, have a few questions
Locking strategy URLyBird 1.1.1 with ReentrantLock
Handling Exceptions in Business Layer
recNo choice