• 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 all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Delete & Update

Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?

Is a solution 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 ???
Ranch Hand
Posts: 1847
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The delete method will mark a record as deleted, that removes the record from the database.
You could also overwrite all the fields with garbage for security reasons (or as an extra indication it's really gone), but IMO that goes beyond the scope of the assignment.

I just mark the record as deleted myself, and add the record ID to an internal list of deleted records I keep in the server.
The latter too isn't strictly needed but makes it a lot faster to find places to store new records (if there's space in that list I don't have to search through the entire file to find an empty spot).
    Bookmark Topic Watch Topic
  • New Topic