• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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,
Roel
 
reply
    Bookmark Topic Watch Topic
  • New Topic