• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Check of the record in the unlock method.

 
Elena Taube
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everyone,

do you check in the unlock method, if the current record is deleted or not?

My unlock method looks like:

// checks if the record exist in the database
// checks if the record is locked
synchronize block {
// remove locks
}

I have a doubt about the check if the record is deleted or not in the unlock method.
But I am not sure, why the RecordNotFoundException should be thrown. Should it be thrown if the record is deleted in the database or if the record does not exist in the array where I save the record number with the lock cookie?

Thanks a lot for your help!
 
Jan Groth
Ranch Hand
Posts: 456
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi elena,

i'd say that this is one of the design decisions sun wants us to take...

i went the same way then you, thinking and discussing about the problem. finally i decided that i explictly remove those locks at the end of the delete method. so you cannot unlock a record which you just deleted. this makes a lot of sense in my eyes ;-)

i documented this decision and passed.

hope it helps,
jan.
 
Anton Golovin
Ranch Hand
Posts: 527
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, if you wish for the program to behave correctly, you must check for the deleted record in all the places where it matters; and yes, RecordNotFoundException will sometimes reflect what really happened: a record was not found.

You should check for deleted record before 1) deleting it (no Exception unless you wish to it to be there), updating it (RecordNotFoundException), reading it (RecordNotFoundException). However, it is impossible to know what your design is, and hence, you may or may not need to do this in every instance above. Please check when there is any waiting and hence possibility for record modification.

Moreover, you must check that a record is still deleted when you are creating a new record and your program reuses deleted records.

If you have more questions, I would be willing to answer in more detail.
[ January 06, 2006: Message edited by: Anton Golovin ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic