• 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
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Tim Cooke
Sheriffs:
  • Rob Spoor
  • Liutauras Vilda
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
  • Piet Souris
Bartenders:
  • Stephan van Hulst

URLyBird Reading Header

 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello all,

I just started with my project for SCJD. I started with reading the header from the db file. I know there is a tool on this site and I also used it but I think I also need to put into the deliveries the reading header piece of code(don't I?) since this is how I read the record's length and fields' number, and since the tool is not my own creation I decided to implement my own solution for it:

an enum as follows, which should be the only thing changed in case of changes over this section of the file structure:

[edit] don't post complete (real) code snippets (and use the code-tags if you want to post a code sample)

and a class which, for now, just makes use of it:

[edit] don't post complete (real) code snippets (and use the code-tags if you want to post a code sample)

I skipped my code comments. Now, my question is, is this to complex or less readable, or shouldn't I have considered adding the header reading part?
I chosed this design from the desire of separating what is likely to be changed from what is less likely.
 
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
Hi Georgiana,

Welcome to the JavaRanch and good luck with your assignment!

Let me make some remarks:
  • you don't need to submit a similar database reader tool like Roberto's database file reader. You can use it to have a look at the contents of your file and to get a better understanding of the database file structure (and according to the many questions about the database file it's surely an added value to this forum), but you don't have to add such a reader in your submission jar. You simply can use Roberto's file reader or create your own little program to read the database file (that's what I did)
  • For your Data class you can choose between using a static database schema (using constants) or a dynamic database schema (read the database file and store valuable information as data members, like the start position of the record section, how many fields a record has,... Both approaches are just fine (and valid, so you won't fail if you use just constants), each approach has its pros and cons, so it's just a decision you have to make (and document in your choices.txt). I didn't use constants (except for the magic cookie value) and read the database schema dynamically; Roberto used the static approach (using constants).
  • your code (with the enum), seems a bit complex to me. But that's just my opinion. And I don't see the true advantage of this approach. Because if the number of bytes of the magic cookie changes for example, you'll have to change the bytesNo + the implementation of retrieveValue too). The code I needed to read my database file header (anything from the start of the file to the section of the records section) contains 15 lines of simple and easy code (just using the API of RandomAccessFile: readInt, readShort, readFully,...), so no rocket science at all.

  • Hopefully my comments were helpful.
    Kind regards,
    Roel
     
    Georgiana Lungu
    Ranch Hand
    Posts: 34
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Thank you for response,
    What I meant by seapration of what can be changed was the fact that there would only the enum would be affected by the change and byteNo and retrieveValue belong to it. ANd of course, being me who wrote the code, I thought the changes that should be made are small and obvious, that is why I asked .
    But thank you a lot for the opinion, I will use it.
     
    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
    Don't forget your code has to be maintained/used by other developers (maybe even a junior developer), because you are on holiday, have left the company,...
     
    And then the flying monkeys attacked. My only defense was this tiny ad:
    Smokeless wood heat with a rocket mass heater
    https://woodheat.net
    reply
      Bookmark Topic Watch Topic
    • New Topic