aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Database Header hard code it or not? 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 Header hard code it or not?" Watch "Database Header hard code it or not?" New topic
Author

Database Header hard code it or not?

Margarita Babkova
Ranch Hand

Joined: May 09, 2012
Posts: 32
Hi there,

I have a question about database header.
I checked out both the Roberto's database file reader tool, and Text Pad to verify my file layout and all the field lengths in a header.

So, I do know what is total header length, magic cookie value, along with each individual field length, and data record length.
So, I can use a correct length in database.seek method to find a beginning of actual data.

Question: should I create separate method like getHeaderInfo() and call it once from the FileAccess constructor to show how I got
All these numbers?

Or can I simply hard code them to avoid over complication?

I am definitely reading a magic cookie when program just starts up, to validate that I got a right db file.

But even than, I am hard coding its value for a validation and if they do not match throw a DatabaseException.
In my Room class I used a hard coded field lengths – because they are knows from database schema description.

Thank you.
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5599
    
  15

That's completely up to you. Both approaches are valid: Roberto hard-coded his database schema, I used a complete dynamic approach. We both passed!

Good luck!


SCJA, SCJP (1.4 | 5.0 | 6.0), SCJD
http://www.javaroe.be/
Margarita Babkova
Ranch Hand

Joined: May 09, 2012
Posts: 32
I will try to change question a bit:
So, if I know that my file header length is 81 (fictitious ) , can I just declare a variable
int fileHeader = 81; and just use this value in raf.seek(81+recordLength); without showing how I came up with an actual value of 81?

thank you very much.
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5599
    
  15

I'm not the most appropriate person to answer this question (because I used a dynamic approach). But I think it's no problem to have private static final int FILE_HEADER = 81; in your code (as a constant) and explain in your decisions document (choices.txt) why you opted for the hard-coded approach + how you came up with the actual values.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Database Header hard code it or not?