aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes NX: How to delete records in database??? 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 "NX: How to delete records in database???" Watch "NX: How to delete records in database???" New topic
Author

NX: How to delete records in database???

Dave Knipp
Ranch Hand

Joined: Oct 14, 2003
Posts: 146
Hi,
I am curious if anyone knows how to delete certain portions of a file with RandomAccessFile.
Data.delete(int recNo) says this :
Deletes a record, making the record number and associated disk storage available for reuse.

So maybe it just means that we are supposed to reuse the space within the file for any records that get created ??? How did everyone implement this, I'm pretty sure im just going to have any new records that are created, use the space in the file where the deleted one is and then write over the deleted record's contents in the file with the contents of the new record. Is this similar to what everyone else did?
Thanks,
Dave
[ November 20, 2003: Message edited by: Dave Knipp ]
[ November 20, 2003: Message edited by: Dave Knipp ]

SCJP 1.4, SCJD 1.4, SCWCD 1.3, SCBCD 1.3, IBM Certified Solution Developer -WebSphere Studio V5.0
Bill Robertson
Ranch Hand

Joined: Mar 21, 2003
Posts: 234

I'm pretty sure im just going to have any new records that are created, use the space in the file where the deleted one is and then write over the deleted record's contents in the file with the contents of the new record. Is this similar to what everyone else did?

Yup, given there was a deleted flag in front of the record. Remember
when you delete you dont really delete the record from the file. You update
its flag indicator to indicate its a deleted record. So if you have 10
records and number 3 is deleted and you add a new record it would go in
space 3. If you have 10 records and none are deleted your new record would
become record number 11. Make sense?

I am curious if anyone knows how to delete certain portions of a file with RandomAccessFile.

Remember you dont need to, just overwrite the flag indicator, simply something like
1. Set your raf to the correct offset of the flag indicator of the given record (you must perform a raf.seek(xxxx);
2. In my case the flag was a short so I was writing a short
3. raf.writeShort(deleteIndicator);
in my case deleteIndicator = -32768 or 0X8000
Dave Knipp
Ranch Hand

Joined: Oct 14, 2003
Posts: 146
Bill,
Totally understand, thats what i was thinking but i just wanted to check and see if was on the right page. hmm interesting you have a short as your flag? I actually have a boolean as mine, heres what my instructions say:

1 byte flag. 00 implies valid record, 0xFF implies deleted record

So i just read it in with RAF.readBoolean(); and then write it with RAF.writeBoolean(deletedStatus).
Thanks for your reply,
Dave
Bill Robertson
Ranch Hand

Joined: Mar 21, 2003
Posts: 234
you got it. interesting yours is boolean
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: NX: How to delete records in database???