This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan 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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Delete Method" Watch "Delete Method" New topic
Author

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.



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: 136

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

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


MOON -- SCJP1.2
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Delete Method
 
Similar Threads
nx:All of URLy Bird 1.1.3 about delete and update method
Data access class desing
Reusing the record number
Lock on reading records
my question about LockManager.java