• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Delete Method

 
Author
Posts: 144
5
jQuery Eclipse IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 209
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 144
5
jQuery Eclipse IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your advice I will try that out.
Tom
 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Politics n. Poly "many" + ticks "blood sucking insects". Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic