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

lock systems and RecordNotFoundException

 
Iván Párraga
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys,

I�m finishing my SCJD assignment (Bodgitt and Scarper) but I still have a doubt which makes me not to submit yet.

Browsing the Ranch, I�ve seen that many of you, even having passed the certification, are not getting so good results as it should be in the locking part. In my assignment I have the lock, unlock, isLock methods which throw RecordNotFoundException. I have written a method which checks the existence of a record, so it would be very easy to have this method called as the first line of the implementation of the locking methods. This works, in general, well, but there is a �conflictive� scenario: record removal.

When the user orders �Remove Record� from the GUI, this is translated to the following method calls in the server (Data) class:

- lock record
- remove record
- unlock record

I suppose many of you can guess what my doubt is. When unlocking the record, if the first thing it does is to check for the record existence, the RecordNotFoundException will be thrown and, in fact, it won�t be unlocked. Having this, I can think of the following possibilities (perhaps you can think of some more):

- not check the existence for the lock method and delegate the responsibility to do the things well to the client. This will work for the application but it seems not very elegant solution and I�m afraid of possible automated tests crashing my Data class;
- perform the unlock code (even if the record does not exist for the file access module it is still locked for the locking module), launch the exception and the called method catch the exception and handle accordingly
- reinterpret the meaning of the RecordNotFoundException for the unlock method as �this record was not locked previously by the client who is trying to unlock it�

What do you think? Any suggestions?

Cheers,

Iv�n
 
Roman Yankin
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Iv�n, honestly I did not understand your solutions to the described problem, but why don't you check the existence of record when you call lock()? Thus you'll make sure that requested record exists and you will lock it without any problems.
 
Iván Párraga
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I do check this in the lock method. The problem is when unlocking the same record after having removed it.

Cheers,

Iv�n
 
Roman Yankin
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK I got your point, well this is where you should wrap the call to unlock with try/catch(RecordNotFoundException) block
 
Jethro Borsje
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am rather curious as to which version of the B&S assignment you are having. In my assignment the DBClient interface which I have to implement does not require me to throw the RecordNotFoundException in the unlock method.
 
Iván Párraga
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You made me doubt ;-) But I've checked, I have the Exception. My version is 2.3.3.

Cheers,

Iv�n
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic