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