in my instruction: // Modifies the fields of a record. The new value for field n // appears in data[n]. Throws SecurityException // if the record is locked with a cookie other than lockCookie. public void update(int recNo, String data, long lockCookie) throws RecordNotFoundException, SecurityException;
why not throws DuplicateKeyException while create method throws DuplicateKeyException ? how to deal with update method's DuplicateKeyException?
One way - assume that one or more "fields" of your records make up a "key". An update would then not change the key, but just the other "fields" in that record. If you need to change the key - then that would be a create (or first delete, then create).
I made my update method throw IllegalStateException with the DuplicateKeyException as a cause (ie IllegalStateException#getCause() returns DuplicateKeyException) should the given record be a duplicate of another one.
Alex (SCJP 1.4, SCBCD 1.3, SCWCD 1.4, SCJD 1.4)
Anything worth doing well is worth doing poorly first. Just look at this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop