• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
  • Piet Souris
  • Frits Walraven
  • Carey Brown

CreateRecord & lock

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 :


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.
Posts: 11604
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • 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,
Posts: 2292
Eclipse IDE Spring Java
  • 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.
Consider Paul's rocket mass heater.
    Bookmark Topic Watch Topic
  • New Topic