This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Delete Method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Delete Method" Watch "Delete Method" New topic

Delete Method

Tom Henricksen
Ranch Hand

Joined: Mar 23, 2004
Posts: 136

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.

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... + (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 + (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: 136

Thanks for your advice I will try that out.
Jesse Xie Y.S.

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

catch IOException and then just print the message, is it really OK?

Have you checked out Aspose?
subject: Delete Method
It's not a secret anymore!