This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Delete Method

 
Tom Henricksen
Author
Ranch Hand
Posts: 144
5
Eclipse IDE jQuery Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 209
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
 
Tom Henricksen
Author
Ranch Hand
Posts: 144
5
Eclipse IDE jQuery Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your advice I will try that out.
Tom
 
Jesse Xie Y.S.
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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 (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}

catch IOException and then just print the message, is it really OK?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic