Win a copy of The Business Blockchain this week in the Cloud forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

CreateRecord & lock

 
pkinuk Buler
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, all.

I started to write the lock() method for the DBAcess interface.



My scenario is pertty the same as Andrew's book. I used facade design pattern. A class called DatabaseFileAcess is created.

I used the input parameter recNO as a return value as the lock cookie number because they are unique. My question is :

1.

Should I just wait until the lock is released , or throw an InterruptedException in the method declare, or throw a RecordNotFoundException when the current thread is interrupted? Because from my assignment:

Any methods that throw RecordNotFoundException should do so if a specified record does not exist or is marked as deleted in the database file.


I am not sure if it is suitable to throw a RecordNotFoundException when the thread is interruptted.

2. If throws InterruptedException, how do I implement the DBAccess interface? Because the lock method in the interface doesn't throws InterruptedException.

3. In what situation I need to throw a DuplicateKeyException when I implement the method? Which field can indicate it is duplicate?



Finally, Happy Xmas for everyone in the forum.
 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi pkinuk,

I don't think it is wise to post your complete lock-code here, just to ask a question about InterruptedException and DuplicateKeyException, so I would advise to edit your previous post and completely delete that code fragment.

If you have used the search-function of this forum you would end up with a thread about InterruptedException (asnwering your question) and several threads about DuplicateKeyException, for example this one.

Happy Christmas to you too and best wishes for 2010 (including becoming a SCJD )!

Kind regards,
Roel
 
Roberto Perillo
Bartender
Posts: 2271
3
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Agreed. Pkinuk, my friend, please do not post your locking mechanism algorithm (please take a look here). Other than that, your locking mechanism has one problem: before locking a record, you still have to verify if it still exists, because the lock() method works for both updating and deleting a record, so it may have been deleted.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic