There's a boolean in my datafile that marks whether a record is deleted or not. When my app starts up it scans the list of records, and keeps a list of the ones that haven't been deleted.
I'd like to keep another list of the ones that have been deleted (just an index for their position in the file, eg. Record 1, 2, 3 etc.) This is so my app will know the records it can overwrite and only have to search for them once on startup. The deleteRecord method will add records to this list as they're deleted.
This sound like a good idea? I presume it's reasonable to overwrite deleted records in the data file.
So I'll have two LinkedHashSets; one containing the record index numbers, the other containing deleted record index numbers. Then one ReadWriteLock to cater for both of these.
That depends, but it looks redundant to me. If you are not caching the records, there is no reason for keeping two sets, since you can use set.contains() and !set.containg(). I am using one Queue for deleted records only.
I agree with Jason, just implement what is required, and buy yourself some rest.
During runtime I do not reuse any deleted records. All new records are appended to the end of data file. I only purges deleted records from data file at startup, and then build up a full cache in memory.
This database is not a SQL database, so the record number is very important. Because a client may keep a record number and access it later again. Based on this concept, I do not even allow a client to change the key of a record (I assume name and location are key fields).
Creates new record in the database (Possibly reusing a deleted entry)
I interpreted this to mean that we should reuse record locations that are marked for delete so that you don't unnecessarily increase the size of the database.
Regarding the client, I don't think the record id should be a problem as it shouldn't know about the deleted records, and if you implement delete functionality in your GUI, deleted records could be handled by the RecordNotFoundException.
Jason. [ March 13, 2006: Message edited by: Jason Moors ]
I'm happy enough with my solution, I think it can be explained through the code quite easily. I'm not caching records, just reusing deleted records on the fly.
Another question though, somewhat unrelated:
In Java 1.5, is there a quicker/more efficient/better-looking way of moving elements from a list into an array than this:
I can't call arrayList.toArray() there, as 'array' is an array of primitives. Do I need that count variable there, or is there some hidden trick I'm unaware of? [ March 14, 2006: Message edited by: Mickey Mulligan ]