• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Database Header hard code it or not?

 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic