I used the cookie value for validating the DB File. If a file is loaded it checks if the cookie value is right.
If this fail a InvalidDBFile exeption is thrown and handled by the client.
Joined: Sep 30, 2006
I did the same thing but after encountering some issues, I removed it. If we hard code cookie value, it means our application can't load another file with same schema but with different cookie value. If we let user enter and change cookie value it means user should know this value in advance for all new files or we should provide some extra utility to read and display this value for each file.
To save user from this, I decided to check the first 4 bytes for valid digits but, again, some invalid file can have all digits in first 4 bytes.
The final decision is: Application server loads all files but when a client tries to connect, it simply thorws an exception for client if file is invalid.
There could be another approach. Server should send loaded db schema information for each client on very first call and client should accommodate all changes in data and display - too complex and above all "not required".
I think we can leave this on user to select valid file. Am I right?
If we hard code cookie value, it means our application can't load another file with same schema but with different cookie value.
Ahhh - but what if the cookie identifies the schema?
Take a look at the JavaRanch SCJD FAQ entries for cookies - you will see examples of how schemas change with different versions of the assignment. And investigation by JavaRanch members indicates that the cookie value is tied to the assignment version.
I also check the db-File and I check not only the magic cookie. Column-count/Field-length/.. are checked also.
Of course I limit the possible db-Files to only that one with the expected schema, BUT that is exactly what I want! IMHO is everything else a risky little game, what you only can lose.
SCJP<br />SCJD (in progress)
Joined: Sep 30, 2006
Thanks guys, My app does implement a fixed schema file. Any other file is loaded by the server but when client connects to the server, it recveices an exception bucause of different schema. This is what I wrote in last email.
If this fail an InvalidDBFile exeption is thrown and handled by the client.
Assume remote server user uploads a wrong file and he is not aware of this, all clients shall recieve exceptions after sending connection requiests. I think we should check it when user selects the db file before running the server (server side check). We should keep our client away from this. This is what I did and then removed. But after this discussion, I am going to add this again.