I am working on urlybird assignment. From the decribed assignment there is no primary key to identify a particular record. (I am assuming a hotel can have more than one room to be rented.)
I have folowing test case: 1. User performs search. 2. fetches search results. 3. Recoed from result is updated (says room is set as booked).
Updated record should be reflected in the dbfile. As mentioned since I have no primary I have to ensure that appropiate record gets updated.
Here is what I do. Every record entry in the dbfile has a number assigned to it. This is a sequential number which also defines the record location in the db. This also helps me in jumping directly to a particular record location (to perform read/write).
A deleted record also gets a number. As deletion does not remove a record from the dbfile. Record is just marked as deleted.
I have kept this assigned number as primary key till the database session is alive. This number is not stored in the database file (as format of file cannot be modified)
Questions: 1. Am I doing things rite? anybody has any suggestions?? 2. In a concurrent user scenario, say 'A' & 'B' user performs search & yeild similar search results. I have taken care of concurrancy so there is no race condition. But say user A updates the record & save it. Now user B also perfoms some operation on same record as that of 'A'. Since search results are not locked, how should we handle this scenario? Actually 'A' has changed the state of a record & this is not reflected to 'B'. please let me know how should we handle this scenario??
I think, that it is not OK. Because recNo is an int and position is long. Unless you do some sort of conversion recno/(positionInFile/recordLength). [ October 26, 2007: Message edited by: Pavel Kubal ]
Maybe, you can think about constraints instead of key fields. For example, you may assume that during creation of a new record, the same customer cannot make 2 reservations for the same day. This time, you may also say in the assignment (at least in mine) there is such statement
... The system you're writing does not interact with these numbers (owner-customer id), rather it simply records them. ...
As you may guess, I am also in trouble about that topic