my dog learned polymorphism*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes URLyBird delete method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "URLyBird delete method" Watch "URLyBird delete method" New topic
Author

URLyBird delete method

Didier Varon
Greenhorn

Joined: Jul 14, 2005
Posts: 23
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?

Thanks, for your help.
Kevin Conaway
Ranch Hand

Joined: Jan 27, 2006
Posts: 57
Something to think about:

Does "available for reuse" mean available to your program, or available to the Operating System?
Didier Varon
Greenhorn

Joined: Jul 14, 2005
Posts: 23
Hi Kevin,

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.
Kevin Conaway
Ranch Hand

Joined: Jan 27, 2006
Posts: 57
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.

Which do you think the spec is asking for?
Didier Varon
Greenhorn

Joined: Jul 14, 2005
Posts: 23
Thanks Kevin, I think I got it. =)
federico perletto
Greenhorn

Joined: Jan 19, 2006
Posts: 1
hi guys,

if i've understood, the correct way is to mark "delete" the record, so it will be available for reuse for the application.

It doesn't need to delete "phisically" the record from the file too, correct?

Thanks a lot

Federico
Zhixiong Pan
Ranch Hand

Joined: Jan 25, 2006
Posts: 239
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
Didier Varon
Greenhorn

Joined: Jul 14, 2005
Posts: 23
Hi Zhixiong

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.
Zhixiong Pan
Ranch Hand

Joined: Jan 25, 2006
Posts: 239
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?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: URLyBird delete method