Hi guys, in the interface the delete method signature is
// Deletes a record, making the record number and associated disk // storage available for reuse. public void delete(int recNo) throws RecordNotFoundException;
and the data file has a flag for every record that indicates if the record is deleted or active, but based on the method's comment, every call to this method will delete the record from the file, meaning that the file will only have active records.
And for the create method: // Creates a new record in the database (possibly reusing a // deleted entry). Inserts the given data, and returns the record // number of the new record. public int create(String  data) throws DuplicateKeyException;
Then my question is, do I really need remove the record from the file? It does not make sense to me, to have a flag when all records are valid, am I missing something here?
Does "available for reuse" mean available to your program, or available to the Operating System?
Joined: Jul 14, 2005
the thing that confused me was // making the record number and associated disk storage available for reuse
specially the "associated disk storage available" comment, first I was thinking mark the record using the flag value and remove it from the system, but here it seems that is requesting to remove it from the file too, but I could be wrong.
Joined: Jan 27, 2006
Like I said, if you mark the record as deleted in your file, then the associated disk storage becomes available for reuse by your program, but not the operating system. If you actually delete the record from the file, the disk storage becomes available to the operating system, but not to your program.
Hi Kevin, After reading your advice, i got a quesion.As delete() just mark the memery, when the Data is closed will all the things back to the initial states?
SCJP 1.4 SCJD
Joined: Jul 14, 2005
What I think, is to mark the record deleted on memory (using the flag value for it) and write the flag byte on disk and when a new record needs to be created you can find the first deleted record from the collection and overwrite it on memory and permament storage.
Joined: Jan 25, 2006
Hi Didier, I got your mean which is quite excutalbe in my opinion.However i still have another question, that is in what cases delete() should be called and in what cases create() should be called?