Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Delete method not checking delete flag

 
rinke hoekstra
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When reviewing my own delete method, I realized it was not checking if the record to be deleted has already been deleted.

By then, I just didn't bother to check this, because it would mean an extra check on the record, and who cares anyway if a record which has already been deleted is deleted again.
In that case, the RecordNotFoundException is only thrown in case of an impossible record number (negative, or completely out of bounds).

Now I'm wondering: is this sensible? Isn't it better to just check the condition and raise the exception, even though there seems to be no problem in deleting a deleted record again? Would you want to bother the user with silly error messages as "deleting not succeeded because record is deleted"?

The advantage is that raising of RecordNotFoundException is consistant over all methods throwing it.

I realize this "problem" is rather peanuts, but I'm just wondering what people would think of this.
 
Mihai Radulescu
Ranch Hand
Posts: 918
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi rinke,

I presume that you mean the about the delete record from the Data class, and in this case this kind of "peanuts", can cost you the exam because the documentation is strict with the RNF exception. Take a look on your specification, more precisely on the API specification.

Regards
M
 
rinke hoekstra
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Mihai,

Thanks for your answer.

The comment by Sun on the interface of the delete method says:

// Deletes a record, making the record number and associated disk
// storage available for reuse.
// Throws SecurityException if the record is locked with a cookie
// other than lockCookie.


However, it throws RecordNotFoundException, even though the comment does not mention this. Below it says:

Any methods that throw RecordNotFoundException should do so if a specified record does not exist or is marked as deleted in the database file.


I was doing the first of the "or statement" here, but not the last. If you think they are very strict on this rule, then I'd better be on the safe side and just implement that. However, I don't see a "must" here. But, presumably, better safe then sorry.
 
Ken Boyd
Ranch Hand
Posts: 329
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yeah it is not MUST but it will be nice to put additional three lines in Delete method of data class. I have done that and thought exactly like why to check deleted record if they delete it again without harming any cow on ranch.

Also you do the same in create method



getDelrecord();

if (no_deleted_rec)
create new at the end of file
else
now lock the record which we are re-using to create record and verify after locking that it is still deleted and if not deleted then go in above loop otherwise just create



Ken
 
chris bajada
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In my case i am also throwing RecordNotFoundException when the record is deleted. Thus if anyone is following my scenario- it would be simpler just to call a 'readrecord(recno);'
in the delete method. This would throw a RecordNotFoundException if the record to be deleted is already deleted, which would then be handled at upper levels.

Thus in this way the only part in the code where you check for the deleted flag is in the readrecord method
 
Mihai Radulescu
Ranch Hand
Posts: 918
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is true, is not a must is a should - the polite way of must.

Any methods that throw RecordNotFoundException should do so if a specified record does not exist or is marked as deleted in the database file.


In my interpretation this statement define (quite strict) the RecordNotFoundException, there are not so many way to interpret it. More, I am pretty shore that SUN have some test - general test (according with the specification) any the first thing before they will jump to the code or to choices.txt (where may be you justify your decision) is to prove the deploy against the specs. More precisely, I presume that they have a test which tries to delete a deleted record - if you fail it, well ....

Regards,
M
[ June 26, 2007: Message edited by: Mihai Radulescu ]
 
chris bajada
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well however strictly speaking, if the application (or test) happens to try and delete a record which is already deleted... nothing weird would happen - just the deleted flag would be overwritten with the same deleted flag, so I do not think that we really need to worry so much about this.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic