This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes [B&S] - Delete & Unlock Questions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "[B&S] - Delete & Unlock Questions" Watch "[B&S] - Delete & Unlock Questions" New topic
Author

[B&S] - Delete & Unlock Questions

Laura Pecoraro
Ranch Hand

Joined: Mar 31, 2009
Posts: 45
Hi all...

I tried to fix my locking mechanism... BUT... I do have some doubt about the delete and unlock methods...

See below

Lock(#1) -> ( do something ) -> Unlock(#1) ---> ( no problem )

Unlock(#1) ---> ( the record #1 exists but not lock by someone... I must thows an Exception???... I must warn the caller's method that specified record not locked )

Lock(#1) -> Update(#1) -> Unlock(#1) ---> ( no problem )

Lock(#1) -> Delete(#1) -> Unlock(#1) ---> ( the Sun specification about the unlock method says: Releases the lock on a record... its OK, but the signature have a RecordNotFoundException, so, I can not lock a record that will be removed Suggestions???)

Laura






Roberto Perillo
Bartender

Joined: Dec 28, 2007
Posts: 2258
    
    3

Howdy, Laura!


Lock(#1) -> ( do something ) -> Unlock(#1) ---> ( no problem )


Alright!


Unlock(#1) ---> ( the record #1 exists but not lock by someone... I must thows an Exception???... I must warn the caller's method that specified record not locked )


Very well observed. In my case, I throw an IllegalStateException in this case.


Lock(#1) -> Update(#1) -> Unlock(#1) ---> ( no problem )


Alright!


Lock(#1) -> Delete(#1) -> Unlock(#1) ---> ( the Sun specification about the unlock method says: Releases the lock on a record... its OK, but the signature have a RecordNotFoundException, so, I can not lock a record that will be removed Suggestions???)


So basically the question is "how can I unlock a record if it was already deleted?". In my case, I just verify if the record exists in the Map that controls the locked records. If it doesn't exist, then I throw a RecordNotFoundException. You may also choose to throw an IllegalStateException and not to throw a RecordNotFoundException. Since this is one of the ambiguous points of this certification, I advise you to mention your choice in your choices.txt file.


Cheers, Bob "John Lennon" Perillo
SCJP, SCWCD, SCJD, SCBCD - Daileon: A Tool for Enabling Domain Annotations
Laura Pecoraro
Ranch Hand

Joined: Mar 31, 2009
Posts: 45
Roberto Perillo wrote:Howdy, Laura!


Lock(#1) -> ( do something ) -> Unlock(#1) ---> ( no problem )


Alright!


Unlock(#1) ---> ( the record #1 exists but not lock by someone... I must thows an Exception???... I must warn the caller's method that specified record not locked )


Very well observed. In my case, I throw an IllegalStateException in this case.


Lock(#1) -> Update(#1) -> Unlock(#1) ---> ( no problem )


Alright!


Lock(#1) -> Delete(#1) -> Unlock(#1) ---> ( the Sun specification about the unlock method says: Releases the lock on a record... its OK, but the signature have a RecordNotFoundException, so, I can not lock a record that will be removed Suggestions???)


So basically the question is "how can I unlock a record if it was already deleted?". In my case, I just verify if the record exists in the Map that controls the locked records. If it doesn't exist, then I throw a RecordNotFoundException. You may also choose to throw an IllegalStateException and not to throw a RecordNotFoundException. Since this is one of the ambiguous points of this certification, I advise you to mention your choice in your choices.txt file.


Thanks Roberto...
 
Don't get me started about those stupid light bulbs.
 
subject: [B&S] - Delete & Unlock Questions
 
Similar Threads
B&S RecordNotFoundException: what exactly does it mean?
Release or not the lock inside the delete method?
URLyBird: Question about update e delete methods
Locking problem
B&S 2.1.1: lock(), delete() and unlock() confusion