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

B&S: unlocking in delete() and update()

 
Lukasz Drukarz
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
B&S 2.1.3

Hello All,

I'd like to implement my update and delete methods of the Data class in such a way that the record is unlocked automatically after successful delete or update.

So the client calls:

lock()
update()

and not:

lock()
update()
unlock()

The unlock() method would serve only as some kind of cancel operation.

The reasoning behind is that it doesn't make sense to hold the lock longer, because if we wanted to update then it is already done, and if we wanted to delete then why update it before. Another reason is that my unlock() method should throw a RecordNotFoundException if a record is marked as deleted. If I would require the client to call unlock() after delete() then it would always throw the RNFE.

Did anyone do it like that (and passed!)?

Thanks,
Lukasz
 
Roberto Perillo
Bartender
Posts: 2271
3
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Howdy, champion!

First, I'd like to welcome you to the JavaRanch family!

Now, in my opinion, this isn't really necessary. It shouldn't be a problem to call lock/{update|delete}/unlock. If you want to only call lock/{update|delete}, then you would have to unlock the record after updating or deleting it, and this would mean that these methods would have more responsibility than they should. Also, in my case, I only throw RecordNotFoundException in the unlock method when trying to unlock a record that was not previously locked.

Stick with lock/{update|delete}/unlock. This is what is expected
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic