Win a copy of 97 Things Every Java Programmer Should Know this week in the Java in General forum!
  • 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
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
  • Piet Souris
  • salvin francis
  • fred rosenberger

Do the unlock(int recNo) and isLocked(int recNo) methods have to throw RecordNotFoundException?

Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good day all.

The lock(int recNo) method throws RecordNotFoundException because before I lock a record, I first check in the database that it exists (not marked deleted). If the record is not found, I throw RecordNotFoundException.

When I unlock a record, I just remove it from the locked records map. If the record is not on that map, I just throw an IllegalArgumentException indicating that the record is not locked.

isLocked(int recNo) just checks that the record is in the locked records map. It does not check if the record exists in the databse or not.

My problem is, for isLocked(int recNo) and unlock(int recNo) methods, when should I throw RecordNotFoundException?

The way I have implemented the two methods currently is that they do not throw the RecordNotFoundException, and I have explained why in Data class source code.
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 Mxolisi,

My unlock-method also doesn't throw a RNFE, my isLocked-method does. And in my opinion the isLocked should throw one, because it is a requirement (but not a must one):

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 explained also in my choices.txt why the unlock-method (and also update and delete methods) don't throw a RNFE. So if you explained in choices.txt (which is the location where you have to explain your decisions), you'll be fine because you don't violate any must requirement.

Kind regards,
Who among you feels worthy enough to be my best friend? Test 1 is to read this tiny ad:
Devious Experiments for a Truly Passive Greenhouse!
    Bookmark Topic Watch Topic
  • New Topic