aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Delete function in B and S DBMain 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 function in B and S DBMain" Watch "Delete function in B and S DBMain" New topic
Author

Delete function in B and S DBMain

H Praveen
Greenhorn

Joined: Jun 18, 2006
Posts: 2
Hi,

I am new to the forum. I have question about the delete function:

the instruction says:
// Deletes a record, making the record number and associated disk
// storage available for reuse.

But the Data file format says:
1 byte "deleted" flag. 0 implies valid record, 1 implies deleted record

It is not clear whether I should delete the record in the file or just mark the record with the delete flag.

Appreciate your help

Praveen
Jeroen T Wenting
Ranch Hand

Joined: Apr 21, 2006
Posts: 1847
what's not clear? By marking the record as deleted you delete the record, that's how your database engine should interpret the data and that's all that counts.

So do take care to when READING a record to skip any that has the delete flag set.


42
Joseph Schulz
Greenhorn

Joined: Jun 14, 2006
Posts: 25
Hi guys,

I have been pondering this issue myself lately and I run into the following issue:

If you do not allow for the "deleted" records to be returned by the Data layer, how would you ever access them? E.g. undelete them?

I thought about returning every record from the file and then filter out "deleted" records before showing them to the user.

Any thoughts on this approach?

Thanks a bunch!
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
The only thing that needs access to records marked as deleted is the create method. To create a record you first select a record marked as deleted if one exists, otherwise you extend the file by at least one record. That is, of course, if you choose to bother to implement the create method.


Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Jeroen T Wenting
Ranch Hand

Joined: Apr 21, 2006
Posts: 1847
There is no undelete specified in the DB interface, so you don't need to worry about it.

The retrieval methods do NOT retrieve deleted records, if they did what would be the point in deleting them?
Joseph Schulz
Greenhorn

Joined: Jun 14, 2006
Posts: 25
Barry & Jeroen,

Thank you very much for quick reply, it clarified a lot to me!

However, I have a quick couple follow up questions.

1. If you never account for the deleted records you still need to be aware of the fact that (e.g.) record #10 is deleted and therefore if someone asks for it they would get RecordNotFoundException, is that right?

2. So, then following the logic if someone is creating a new record (which I implemented in my code) and there is only 1 deleted record (#10) I would replace it with the new record, correct?

Originally posted by Barry Gaunt:
The only thing that needs access to records marked as deleted is the create method. To create a record you first select a record marked as deleted if one exists, otherwise you extend the file by at least one record. That is, of course, if you choose to bother to implement the create method.


ThankS!
H Praveen
Greenhorn

Joined: Jun 18, 2006
Posts: 2
Hi
Thanks a lot!

It really helped.

Praveen
Jeroen T Wenting
Ranch Hand

Joined: Apr 21, 2006
Posts: 1847
yup, if someone requests a record by number that's been deleted you get an exception.
If a new record is inserted you should first check if there's an empty spot in the datafile (so a deleted record) and reuse that space before appending it to the end of the file.
Mihai Radulescu
Ranch Hand

Joined: Sep 18, 2003
Posts: 918

Hi, Jeroen

if someone requests a record by number that's been deleted you get an exception.


This is not always, that depends on the specs. I just hear(ok read) about some findRecond method without throw cause.

Regards, M


SCJP, SCJD, SCWCD, OCPJBCD
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Delete function in B and S DBMain