• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Delete() implementation

 
Matt Pavlovich
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone,

I currently have this method implemented such that it writes " " for the length of the record to be deleted. However, I am contemplating truncating it instead so I am hoping to gather a few opinions as to whether or not just over-writing the record with " " satisfies what the interface calls for: "Deletes a record, making the record number and associated disk storage available for reuse." I could make an argument for and against using " " to just over-write. Thoughts?

Thanks.
Matt
 
Roel De Nijs
Sheriff
Posts: 10456
137
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Some people just change the deleted flag and that's it, other ones just change deleted flag and write an empty record. That's simply up to you and what you prefer.
 
Dennis Grimbergen
Ranch Hand
Posts: 159
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would just write the same record back to the file with the deleted flag set to 1 (instead of 0). The deleted flag is present in every record, so why not just use it? This way you don't have to deal with things like reusing deleted records and stuff.

 
Roberto Perillo
Bartender
Posts: 2271
3
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I myself used a record cache (Map<Long, Room>), so when a record is deleted, I first replace its entry in the map with null. When the application finishes and the records are written back to the file, for each entry whose values are null, I just write the deleted flag for each particular record.
 
Matt Pavlovich
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Guys,

You have once again spared me from unnecessary work.

Thanks very much!
Matt
 
David Byron
Rancher
Posts: 175
Clojure Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I worked directly with the file rather than using a cache. For deletes, I checked for the existence of the record and if I found it, I set the flag. For saves, then, I reused record space in the file where possible and padded to the end of the record to overwrite any debris.
 
Sean Keane
Ranch Hand
Posts: 582
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Roberto Perillo wrote:I myself used a record cache (Map<Long, Room>), so when a record is deleted, I first replace its entry in the map with null. When the application finishes and the records are written back to the file, for each entry whose values are null, I just write the deleted flag for each particular record.


Is the key in the record cache the record number? If it is, then this seems strange that a Long would be used as the key.

All of the assignments use Integer (or more precisely int) as the record number - see list of unlock methods here. For example:

Based on this, shouldn't your record cache instead be an Integer as the key i.e. Map<Integer, Room>?
 
Roel De Nijs
Sheriff
Posts: 10456
137
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sean Keane wrote:All of the assignments use Integer (or more precisely int) as the record number - see list of unlock methods here.

I think you definitely need a pair of glasses (or maybe you just have to go and put the assignment aside for a bit )
 
Roberto Perillo
Bartender
Posts: 2271
3
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Roel De Nijs wrote:I think you definitely need a pair of glasses (or maybe you just have to go and put the assignment aside for a bit


That's my good buddy Roel!
 
Sean Keane
Ranch Hand
Posts: 582
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Apologies Roberto, I knew I should never have doubted you! I blame it on sleep deprivation

Of course this was my error. The full list of unlock methods listed on the FAQ page is:

Version Signature of Unlock method
1.1.1 public void unlock(int recNo, long cookie) throws RecordNotFoundException, SecurityException;
1.2.1 public void unlock(long recNo, long cookie) throws SecurityException;
1.2.2 public void unlock(long recNo, long cookie) throws SecurityException;

1.3.1 public void unlock(int recNo) throws RecordNotFoundException;
1.3.3 public void unlock(int recNo) throws RecordNotFoundException;


As can be seen, when I wake up , two of the methods actually take long as the record number.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic