Hi ranchers, Thank you for caring my quesion.I really need your help.Now see my trouble first. So far as I know, to delete a record we should not really remove it from disk, instead we just mark it. Comments in assignment say
Data section. Repeat to end of file: 1 byte flag. 00 implies valid record, 0xFF implies deleted record
Okay, you understand that the first byte of each record is used to determine if a record is marked as deleted.
You now need to think about what impact that flag will have on the create, delete, read, update, find and other methods in your Data class.
For example the documentation for the create method states that
Creates a record in the database (Possibly reusing a deleted entry)
So for this method you would need to loop through the records in the file until you find a record which is marked for deletion i.e has a value of 0xFF. Then all you have to do is update the information for the record.
You also want to think why a RecordNotFoundException might be thrown.
Joined: Jan 25, 2006
Hi Jason, Thanks for your reply. If i want to delete a record, my RAF seek() to the top of every record and writeByte(255). Any comprehension errors here? One more quesion here. When read(recNo) received a deleted record's recNO, then how to deal with?
Joined: Dec 04, 2001
If i want to delete a record, my RAF seek() to the top of every record and writeByte(255). Any comprehension errors here?
You've got it! You will also need to consider your locking mechanism when deleting records.
When read(recNo) received a deleted record's recNO, then how to deal with?
This is were the RecordNotFoundException should be thrown.