• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Database Header hard code it or not?

 
Margarita Babkova
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 9934
113
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
Margarita Babkova
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 9934
113
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic