Hello Jim,
You asked in the criteriaFind()
thread:
Hi Bharat,
This URLy bird project looks cryptic to me. U state that u do not allow the client to view any deleted records. My concern is
1. Can u explain what happens to the deleted record. Do we compress the file or mark it deleted and reuse. And if we do delete, how does this record ever get re-used since the requirement states that the update method throws RecordNotFoundException, meaning if trying to update deleted record , throw an e!
There is talk of adding new records to this database. Does this mean:
2. we can willy nilly add new records to the database, and if we can under what conditions do we do so, do we add a record as long as we have keep the hotel name and location or are there other factors.
I am really puzzled about this.
Thanks.
If you are an "old" dbase/Clipper/FoxPro person like me, you would recall that these tools used to have ".dbf" files which allowed to you to go to a particular record and delete them. When deleting, you didn't really (I mean physically) delete the record but only marked it for deletion. If you issued a "pack" command however, the system will physically remove the record and compress the "dbf" file.
If none of the above makes sense to you, don't worry about it. Most likely you are not "old", you are lucky!
Seriously, for the URLy Bird assignment; You do not do "pack", i.e., you only mark the record for deletion. My instructions state:
1 byte "deleted" flag. 0 implies valid record, 1 implies deleted record.
What you do is for a given record you first locate this byte, and to delete it, you just set it to "1". As simple as that. So the next time your program is reading the records, it checks this byte. If it is turned "on", i.e., set to 1, you want to skip the record since you don't want the user to see a deleted record.
When you want to add a record, however, you start at the first record and read sequentially down until you locate a deleted record. If you find one, you can reuse it for storing the record that you want added to this file. Simply replace, i.e., write over, the data in the deleted record with data for your new record. Also set the deleted flag to "not deleted," i.e., equal to 0. Remember, you are reading FixedLengthStrings, therefore,
you should be writing FixedLengthStrings as well. That is the only way you can guarantee the integrity of the given datafile.
I hope this is of help to you.
Regards.
Bharat