Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

[B&S] - Delete & Unlock Questions

 
Laura Pecoraro
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2271
3
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Laura Pecoraro
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic