According to the specification of the lock method this method
Locks a record so that it can only be updated or deleted by this client.
In the case of delete, does this mean that we do the following:
Problem is if we lock, then delete then attempt to unlock then we should get a RecordNotFoundException in the unlock method as that is what the unlock method should return for a record that is marked as deleted. Anyone have any ideas as to how this should be written?
mine doesn't state under which conditions RecordNotFoundException is thrown so I've decided to never throw it in unlock(). Would be pointless to throw it there anyway, you're trying to get rid of something that's not there, fine by me
42
Mark Smyth
Ranch Hand
Joined: Feb 04, 2004
Posts: 288
posted
0
Originally posted by Keith Jones: Surely that's not possible since the specification for the unlock method says that we must throw an exception if we try to unlock a deleted record.
I think that it is an easily defendable option to take with regards to this issue as is dropping DuplicateKeyException in the create method. If the RecordNotFound exception is thrown by the unlock method before the record is unlocked then the record will never be unlocked. But if you unlock the record before checking it exists then whats was the point of the check in the first place?
I would say if you are deleting record which is already make deleted (check using flag) then throw RecordNotFoundException since my assignment says clearly
Any methods that throw RecordNotFoundException should do so if a specified record does not exist or is marked as deleted in the database file.
[ February 12, 2007: Message edited by: Ken Boyd ] [ February 12, 2007: Message edited by: Ken Boyd ]
There exists also a different opinion than Ken's one.
If a record should be delete and it is already deleted, then the goal of deletion is already achieved in the client's view point. So that means for the client point of view, do not throw any exception.
Anyway, if in your assignment is mentioned to throw such an exception, then the client want such an exception and you have to throw it.
Originally posted by Keith Jones: Surely that's not possible since the specifcation for the unlock method says that we must throw an exception if we try to unlock a deleted record.
Surely that can't be in your spec? This is what mine look like:
It only throws the SecurityException. There is also nothing that says I can't unlock a deleted record. You could prevent "locking" of a deleted record, but once it's locked, then you don't have to worry about its existence to unlock.