This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
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.
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?
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.