File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes B&S: unlocking in delete() and update() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "B&S: unlocking in delete() and update()" Watch "B&S: unlocking in delete() and update()" New topic

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

Lukasz Drukarz

Joined: Jun 10, 2009
Posts: 1
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:


and not:


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!)?

Roberto Perillo

Joined: Dec 28, 2007
Posts: 2271

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

Cheers, Bob "John Lennon" Perillo
SCJP, SCWCD, SCJD, SCBCD - Daileon: A Tool for Enabling Domain Annotations
I agree. Here's the link:
subject: B&S: unlocking in delete() and update()
jQuery in Action, 3rd edition