• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Create record on deleted position

 
Martin Wallgren
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When I create a new record I reuse old deleted positions as stated as a possibility in the DBAccess interface.
I have no cache in my solution so I'll have to check the file for a non-valid record flag. My way of finding a empty position is just reading all the flags in the file until I reach a non valid flag. If I reach EOF before I find an empty slot I add the new record at the end.

This is off course very time consuming if the file contains many posts with no empty slots. I don't think that an advanced search algorithm is in line with the "keep it simple" concept. What's your thoughts?

I don't like the idea of wasting disk space on deleted records, but then again permanent storage is cheap now days.
 
mohamed sulibi
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi;

I think you are right, you can reuse deleted entry or simple add in the
last of the file. don't forget to synchronized the access to the file.
i think the diff between add to the last and reuse deleted entry is
just one line ( for loop).

BR;

Mohamed Darim.
SCJP, SCJD in progress ... (upload date : 1/april/2008).
 
Jason Moors
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Martin,

I don't think there is necessarily a right answer, I personally looped through the records, as you mentioned you only need to check the delete flag byte, so you can skip record length number of bytes so I don't think the overhead is great.

I guess other options would be to not implement the reuse or to maintain a list of deleted records, but this may complicate your design.

I think as long as you document your decisions you should be fine.

Regards,
Jason
 
Martin Wallgren
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm leaning towards keeping it as it is (looping through from the first until an empty spot is found). my argument for not reusing empty slots would depend of the usage of the program. If there's a praxis for not deleting old posts (maybe for logging purposes) then one would be better of to just add new posts at the end. But as far as the exam goes that's an unknown factor and I'll just mention it as an alternative in my documentation.

Finding empty positions for new records is definitely something that would benefit from an cache in the design but I still think that a cache complicates more than it's worth.

Thanks for the input...
 
Roberto Perillo
Bartender
Posts: 2271
3
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Howdy, Martin.
Well, whether is your approach of how to keep the deleted/valid records, I think we should stick to the requirements and use deleted positions. But, quick question, when do you plan to use these methods? For instance, I'm currently working on the URLyBird 1.3.1, and, here are some pieces of my requirements:

Under Application Overview

The new application, using the existing data file format, must allow the CSRs to generate a list of accomodations that match a customer's criteria.


Under User Interface:

- It must be composed exclusively with components from the Java Foundation Classes (Swing components).
- It must allow the user to search the data for all records, or for records where the name and/or location fields exactly match values specified by the user.
- It must present search results in a JTable.
- It must allow the user to book a selected record, updating the database file accordingly.

So I created all methods that the DB interface requests (and I'm looping through all records to find their positions), but I'll never use the create() method or the delete() method, because it is not asked anywhere on my requirements to create or delete records. I'll only use the update() method (to book a record) and the find() method (to allow users to perform full/and/or searches). I still don't know if I'll have to use the methods that relate to locking of records, I'll have to think about how I'll do the locking... so, I don't know about your requirements, but I guess you don't really have to spend too much time on the create()/delete() methods.

Have a good evening, partner!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic