For the database file, how should I manipulate it? Should I 1) read the file and store information as objects and then manipulate the objects and rewrite the file each time there is a call to the Data.java to the methods that change record content?
2) Read information from the DB file and manipulate the file directly as changes occurs to the record.
Anyone can advice me on which approach should I use or are there any other better approaches?
Reading the file into memory and just updating the file whenever a change occurs will give you better performance.
It has also been suggested that the fact that the Data methods do not throw any IOExceptions could be easier to deal with if most of the methods are dealing with a memory cache - then there are only a couple of update methods that will require exception wrapping.
But you may find that there is less coding if you always read and write directly to the physical file. Which means that there is less code in which you could possibly make a mistake, and less code for the examiner to read and understand.
Either way can lead to a pass, so in many respects it comes down to you making a design decision and going with it. Whatever you choose, make sure you document in the appropriate document.
I understand your point, thanks for your advice. One more question arise - the using of record numbers to identify each record. The physical file itself does not have record numbers together with the records or schema descriptions. My question is whether everyone has such a requirement and whether the record numbers had to be fixed for every run of the program.
Joined: May 22, 2004
Regarding the flag that implies whether the record is deleted anot, I feel that it is redundant, Can I just dun write the deleted records to the physical file, in that I just simply do a rewrite to drop all records marked deleted? I still leave the flag information intact, it is just that the records in the physical file will have all its record marked as valid instead of deleted after the rewrite. Cause if I actually cache the contents, I can easily do a rewrite of the file. And deleted entries will be omitted in the cache before I write to the physical db file.