wood burning stoves 2.0*
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
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
Author

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

Lukasz Drukarz
Greenhorn

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:

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

Joined: Dec 28, 2007
Posts: 2258
    
    3

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
 
jQuery in Action, 2nd edition
 
subject: B&S: unlocking in delete() and update()
 
Similar Threads
My locking model
create method
delete in B&S
unlock method question
update and delete shouldnt throw RNFE?