• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Partial Integrity test on Data file

 
Abhinav Anand
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys,
I have read some post by Michael & Nate in which they have stressed importance of verifying whether the data file is a valid "db.db" data file before creating the Data instance. To do so they have recommended partial integrity test, in which the header length, record length and field structure is hardcoded into a class and is compared with that of the concerned data file. If the properties mentioned match then the data file is valid otherwise the data file is invalid.
I want to know that is it an elegant design to hardcode a data file's header length, record length and total fields along with their corresponding field size into a class ?
In my view hardcoding a database file(s) structure into a class in order to check its integrity can be justified only when we want to make sure that the data file being processed is THAT specific type of data file which the application expects.
FYI I am implementing partial integrity test in my submission, but I want to be sure that the grader won't score me down.
Any suggetions...
 
Michael Morris
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Vishal,
Actually, I didn't hard encode the header info into my integrity check. I read the header in based on the "published" Data format. That is hard coded but it is also in Data. The elegant solution would be to have an interface that both Data and the DBFileCheck used to read the db file. That way, the format could be changed at will.
Hope this helps,
Michael Morris
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wait a sec, Michael did you include this in your SJCD Submission. I'm not talking about the Beta.
Why? The code they give you checks that it is a valid db.db file, and you put the db.db file and code the location of the db.db file, so that the only db.db file you open is the actual db.db file. So you wouldn't have to do any kind of checking. In the submission I mean, in the real world you might provide this, or might not.
Mark
 
Michael Morris
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Mark,
Yep, I did.

Why? The code they give you checks that it is a valid db.db file, and you put the db.db file and code the location of the db.db file, so that the only db.db file you open is the actual db.db file. So you wouldn't have to do any kind of checking. In the submission I mean, in the real world you might provide this, or might not.

The reason I did is that Data's integrity check fails in the constructor on the indicated line:

if for some reason the header is corrupted or the user selected a bogus db file.
The Data constructor, should have verified the MAGIC number at least before reading the header and constructing the schema.
As I recall in your implementation you did not allow the selecting of any file other than db.db in the home directory, so there would never be a problem. I opted to allow a different db file on the command line or from the server's file menu.
I don't suggest that it is necessary to do the integrity check but once I got that OutOfMemoryError error, I decided to do it.
Michael Morris
 
Pete Lyons
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I also added the integrity check since I allow the db.db to be any file, and since passing in a plain text file instead crashed the program.
I'm not familiar with the details of most binary file formats, but wouldn't have been much simpler for SUN to put the magic number right at the beginning of the file? As I recall, doesn't the .class file format require 0xCAFEBABE right at the beginning?
Also, just a note that have trying to write a client application that does not need to be updated when the data schema changes is (in my opinion) an excercise in futility and often results in some of the least-usable user interfaces. I have absolsutely no qualms about hard-coding abbreviated column names ("From", "To", etc) into my TableModel subclass.
 
Abhinav Anand
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have hardcoded the db.db file's header size and total number of fields in a class name FBN_DataFileStructure. I don't want to do so in the Data class due to re-usability issues...
So on client/server startup i check that the file provided is a valid fly by night db.db file by calling FBN_DataFileStructure.isValidFBNdb(String) method. If the file is invalid then an InvalidDataFile exception is thrown
Any suggetions...
[ September 20, 2002: Message edited by: Vishal Sinha ]
[ September 20, 2002: Message edited by: Vishal Sinha ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic