// Deletes a record, making the record number and associated disk
// storage available for reuse.
// Throws SecurityException if the record is locked with a cookie
// other than lockCookie.
public void delete(int recNo, long lockCookie)
throws RecordNotFoundException, SecurityException;
Originally posted by liqun chang:
Hi George: about the delete method
I do not understand why you are reading the record in the delete method. All we need to do in this method is to set the deleted flag to 1 implying that the record is deleted.
I have some questions as follow:
1: You can see:i use read() of Data class in delete(),Am i right? or i use direct reading from database file?
2: In this delete method there are two synchronized blocks. one in read of Data class,another in the delete method.Am i right?
Can you please explain of why you are reading the record that is supposed to be deleted? That way it will be easy to answer. Now all I can tell you is in this method, we seek to the record starting physical posistion in the db file using maybe seek of RAF and then write 1 there. That is all we have to do. Atleast that's what I think we have to do and am doing the same.
Any methods that throw RecordNotFoundException should do so if a specified record does not exist or is marked as deleted in the database file
Originally posted by liqun chang:
Hi Satish glad to meet you and thanks for your responding.
My meaning is to read record and see whether the record validate and throws
RecordNotFoundException,in this situation,simply reuse read method in Data
class can approach.or i can directly access the database file and judge flag.Am i right?
Any methods that throw RecordNotFoundException should do so if a specified record does not exist or is marked as deleted in the database file.
Originally posted by liqun chang:
My meaning is to read record and see whether the record validate and throws
RecordNotFoundException,in this situation,simply reuse read method in Data
class can approach.or i can directly access the database file and judge flag
.Am i right?
Well, you could do it that way, but you'd be doing more work than necessary. I agree with Satish, all you need to do is read the validity flag (which conveniently is at the beginning of each record). So I would recommend that you read only the validity flag rather than the entire record. If you want to reuse code there's an opportunity to factor out the code that reads the validity flag. This readValidityFlag method could be used in all sorts of database methods (read, delete, update), basically any of the database operations that can throw the RecordNotFoundException.
Hi George,you can see:the purpose of delete is write deleted flag to database file,but this method require throws RecordNotFoundException,so i must read record and judge whehter the recNo already has deleted flag or
doesn't exist in database file.Am i right? or you have another method?
I would use similar reasoning to that in my previous response. As Satish said you only need to write the validity flag to mark a record as deleted. So you might want to create a writeValidityFlag method that writes the valid or deleted value into the validity flag of the record. This method could possibly be used in the create method in the case where you're reusing a deleted record to store the newly created record.
Regards, George
SCJP, SCJD, SCWCD, SCBCD
Originally posted by liqun chang:
1: Am i right for update method?
Yes. I think your test for the deleted flag can be simplified. I think there are some good opportunities for refactoring some of the code into small private methods (for example, seek(int recNo), readValidityFlag(int recNo), writeValidityFlag(int recNo, boolean flag), and possibly others you might discover as well). I think these comments apply to the delete method too.
2: I find that delete and update both write to database file,one write the
flag,another write whole record.Am i right?
Yes, absolutely. Also the create method, right?
Regards, George
SCJP, SCJD, SCWCD, SCBCD
That which doesn't kill us makes us stronger. I think a piece of pie wouldn't kill me. Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
|