This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Reusing deleted entries ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Reusing deleted entries ?" Watch "Reusing deleted entries ?" New topic
Author

Reusing deleted entries ?

Liviu Carausu
Ranch Hand

Joined: Oct 07, 2004
Posts: 157
Hi,
My "create" method from the DB interface looks like this :


How are you guys keeping track of deleted records ? I have a collection where I hold the indexes of the deleted indexes. I update the collection
at server start and when one element is deleted. Reading the collection is useful also in the "read" method, it can save reading from the disk the "delete flag"
Any other approaches, ideas ?
Thanks,
Liviu


Oracle Certified Master Java SE6 Developer(SCJD),
OCE JEE 6 JSP and Servlets Developer.
Jim Petersson
Ranch Hand

Joined: May 28, 2008
Posts: 48
I'm just reading the database file directly, checking for a deleted record.
The drawback of this is of course that it's pretty slow, but on the other hand there is no need to maintain a separate list of deleted records.


SCJP 5<br />SCJD
Liviu Carausu
Ranch Hand

Joined: Oct 07, 2004
Posts: 157
Originally posted by Jim Petersson:
I'm just reading the database file directly, checking for a deleted record.
The drawback of this is of course that it's pretty slow, but on the other hand there is no need to maintain a separate list of deleted records.


OK,Jim, but then how do you find the next free index when you are trying to create a new record ? I think that going through all db file to search for the first deleted index is pretty slow.

Thanks,
Liviu
rinke hoekstra
Ranch Hand

Joined: Apr 06, 2007
Posts: 152
I'm just not reusing deleted records. All records are appended.


_ _ ________________________ _ _ <br /> <br />Just SCJP (but 93%)
Liviu Carausu
Ranch Hand

Joined: Oct 07, 2004
Posts: 157
Originally posted by rinke hoekstra:
I'm just not reusing deleted records. All records are appended.


Hi Rinke,

That means that you are either ignoring the requirement "possibly reusing a deleted entry" (You are right, it is not a "must" ), or you are compacting somehow the database at startup . Am I right ?

Thanks,
Liviu
Jim Petersson
Ranch Hand

Joined: May 28, 2008
Posts: 48
Originally posted by Liviu Carausu:


OK,Jim, but then how do you find the next free index when you are trying to create a new record ? I think that going through all db file to search for the first deleted index is pretty slow.

Thanks,
Liviu


I'm going through the whole db-file, searching for the first deleted record.
And yes, it's slow
rinke hoekstra
Ranch Hand

Joined: Apr 06, 2007
Posts: 152
Originally posted by Liviu Carausu:

That means that you are either ignoring the requirement "possibly reusing a deleted entry" (You are right, it is not a "must" ), or you are compacting somehow the database at startup . Am I right ?


Yes, I am ignoring this.

I found that it makes the code quite a bit more complicated, and file size is normally not a problem on modern computers, especially not with this database type.

There is also a requirement to keep the code as simple and understandable as reasonably possible, and I chose to give more importance to this requirement then to the "possibly reusing deleted records" requirements.
Jo�o Batista
Ranch Hand

Joined: May 25, 2008
Posts: 40
I second what rinke said.
Though my code favors a bit of complexity regarding a more flexible solution at some points, I did not have enough arguments to go to the trouble of reusing deleted records, and kept my create method clean. It might be useful in other application that uses the file with deleted records (odd reason, but a possibility).
Joshua Fix
Ranch Hand

Joined: Sep 18, 2007
Posts: 57
I rebuild my index with each add or delete opertaion. Whenever a delete operation is performed, I add the Long byte position value to a LinkedList.

When I add a new reocrd, I check to see if my queue is empty. If it is, I append my new record. If it isn't, I poll() it and seek to that long value and write my new record there.

Then I re-index.


SCJP 5.0
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Reusing deleted entries ?
 
Similar Threads
UrlYBird - DuplicateKeyException in the create method ?
URLyBird's [Version 1.2.3] : create/update/delete
Delete & Update
URLyBird Primary Key
JavaDoc DB Interface & DuplicateKeyException