42
Originally posted by kaymen ji:
Help please, I am very close to upload my assignment. But I suddenfly found this statement "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 have a readRecord() method, which read the record from database. It throws RecordNotFoundException only when that record physically non-exist in the database file. If I stick to the requirement, check deleted flag in my readRecord() and throws RecordNotFoundException, I would cause myself problem in find() method. Because in my find() method, I need to call this readRecord(), if readRecord() throws RecordNotFoundException when encounter a deleted record, my search would be interrupted and exit.
My question is : could I keep my old implementation? throws RecordNotFoundException in readRecord() only when record non-existing in database file? But if I keep it this way, is it risky for the accessor to fail me? Does it deviate the requirement? Nearly to submit, any change on the codes would be a cost to me .
By the way, I do have a isValidRecord() to check if that record is marked as deleted. In my lock() method, before locking a record, I need to make sure that record is not deleted, if record is deleted, RecordNotFoundException would be thrown from lock() method.
SCJP<br />SCJD
Originally posted by kaymen ji:
Hi, there,
Thanks for your guys suggestion. I got some idea from your posts. One more doubt came out : "Search All" means find only those record not marked as deleted? God! my current implementation when user want to search all, i return all records including those marked as deleted and display on GUI, with a status showing "deleted/active". It seems my understanding of "search all" is wrong? right? suggestion please! Thanks!
SCJP<br />SCJD
I suppose it comes down to whether or not you consider a deleted record to be a record at all.
Originally posted by Mike Ng:
You should NOT consider a deleted record to be a record at all. The way database file is designed, when a record is deleted it is marked as "deleted" for performance reason. When a record is deleted, there are 2 ways to handle it:
1) Delete it and shift all records up so there is no wasted space between records. Obviously, this is going to be painful slow if you have lots of records.
2) Mark it as deleted and ignore it on querying/updating operations. The space of the deleted record can be reused by an insert. If the insert appends new record at end of file, the file will keep growing. Either way, a database file compress will removed all deleted records so that there are no wasted space between records.
SCJP<br />SCJD
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime. |