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...
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
Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher
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
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
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.
Joined: May 02, 2002
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 ]
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com