Any methods that throw RecordNotFoundException should do so if a specified record does not exist or is marked as deleted in the database file. (my emphasis)
What you thought was right today may need a refactoring tomorrow...
Originally posted by Nicky Bodentien:
But if unlock() almost always throws RecordNotFoundException, how can you remove it from your unlock method?
Just to clarify, I assume you are talking about this interesting scenario:
1. Client A locks record 007 2. Client A deletes record 007 3. Client A unlocks record 007 --> RecordNotFoundException because 007 is deleted
Are not NOT throwing RecordNotFoundException in step 3? This would make sense if we assume that delete() will automatically release the lock, and then throw InvalidStateException in unlock() instead.
Originally posted by Nicky Bodentien:
But if unlock() almost always throws RecordNotFoundException, how can you remove it from your unlock method?
Just to clarify, I assume you are talking about this interesting scenario:
1. Client A locks record 007 2. Client A deletes record 007 3. Client A unlocks record 007 --> RecordNotFoundException because 007 is deleted
Are not NOT throwing RecordNotFoundException in step 3? This would make sense if we assume that delete() will automatically release the lock, and then throw InvalidStateException in unlock() instead.
Anton Golovin ([email protected]) SCJP, SCJD, SCBCD, SCWCD, OCEJWSD, SCEA/OCMJEA [JEE certs from Sun/Oracle]
Originally posted by peter wooster:
I agree and have taken the approach that delete unlocks the deleted record. Once the record is deleted, its no longer available in its old form. It could appear as a new record added by the create method, which doesn't check locks, so it makes no sense to let it remain locked.
An attempt to unlock the deleted record will throw RecordNotfoundException if the record hasn't been reused, and SecurityException if it has been reused. I assume that the SecurityException defined in UyB is the same as your InvalidStateException.
Anton Golovin ([email protected]) SCJP, SCJD, SCBCD, SCWCD, OCEJWSD, SCEA/OCMJEA [JEE certs from Sun/Oracle]
But if unlock() almost always throws RecordNotFoundException, how can you remove it from your unlock method?
What you thought was right today may need a refactoring tomorrow...
This would solve the problem of throwing the exception after a delete, but this may not work for all cases. If a client tried to unlock a record that has never existed the exception would not be thrown.If you implement the RecordNotFoundException, it would be with this check:
if(record is not locked and (&) record is deleted) then throw RecordNotFoundException
“Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.” - Rich Cook
Don't get me started about those stupid light bulbs. |