• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

URLyBird delete method

 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Something to think about:

Does "available for reuse" mean available to your program, or available to the Operating System?
 
Didier Varon
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Kevin, I think I got it. =)
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 239
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Didier Varon
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 239
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
reply
    Bookmark Topic Watch Topic
  • New Topic