aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Database access 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 "Database access" Watch "Database access" New topic
Author

Database access

Clivant Yeo
Ranch Hand

Joined: May 22, 2004
Posts: 124
Hi ranchers,

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?

Or

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?

Thanks.


Clivant Yeo
My Personal Website
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11460
    
  94

Hi Clivant,

Welcome to JavaRanch and this forum.

There are good and bad points to both 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.

Regards, Andrew


The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
Clivant Yeo
Ranch Hand

Joined: May 22, 2004
Posts: 124
Hi Andrew,

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.
Clivant Yeo
Ranch Hand

Joined: May 22, 2004
Posts: 124
Hi ranchers,

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.
Philippe Maquet
Bartender

Joined: Jun 02, 2003
Posts: 1872
Hi Clivant,

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.


As the file contains fixed-length records, record numbers don't need to be stored in the file. You use them to compute the position where to read a given record in the file.

Regards,

Phil.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Database access