| Author |
Delete Method
|
Tom Henricksen
Ranch Hand
Joined: Mar 23, 2004
Posts: 135
|
|
I am working on B&S and my deleteRecord method is not working. I have a unit test that I run and it doesn't seem to delete the record. It seems to delete the record in cache only. The file valid record indicator is always true. I suspect it may be my seek distance. Thanks, Tom
|
 |
Thomas Paul Bigbee
Ranch Hand
Joined: Jun 28, 2005
Posts: 71
|
|
There are a couple of things, that stand out, like not using constants and opening and closing the file for each delete, also it looks like the record is not being locked before the update, however, I believe you may be right is assuming the seek is wrong try this... databaseFile.seek(HEADER_OFFSET + (RECORD_LENGTH * (recordNumber - 1))); Therefore, if you wanted to delete record #1, you are just positioning the file pointer to the byte at the end of the HEADER_OFFSET + (0) I believe that you are deleting the next record after the one you really want to delete.
|
 |
Alex Sharkoff
Ranch Hand
Joined: Apr 11, 2004
Posts: 209
|
|
Thomas Paul Bigbee wrote databaseFile.seek(HEADER_OFFSET + (RECORD_LENGTH * (recordNumber - 1)));
Very nice, Tom
Thomas Paul Bigbee wrote also it looks like the record is not being locked before the update
I guess the client would lock it before calling delete method
|
Alex (SCJP 1.4, SCBCD 1.3, SCWCD 1.4, SCJD 1.4)
|
 |
Tom Henricksen
Ranch Hand
Joined: Mar 23, 2004
Posts: 135
|
|
Thanks for your advice I will try that out. Tom
|
 |
Jesse Xie Y.S.
Greenhorn
Joined: Feb 09, 2004
Posts: 20
|
|
if (locks.containsKey(recordNo) && locks.containsValue(lockLongCookie)) {
If recordNo=1 locked cookie=001 and recordNo=2 locked cookie=002 when invoke deleteRecord(1,002); then...
unlock(recNo, lockCookie);
I don't think it's a good way that invoke unlock in the deleteRecord method.
catch IOException and then just print the message, is it really OK?
|
MOON -- SCJP1.2
|
 |
 |
|
|
subject: Delete Method
|
|
|