• 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

B&S: Majic Cookie Value

 
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
So far, I assume that end user is responsible to select correct db file.

Can we use majic cookie value as db id so that user should change this value before changing db file? It creates many parameters like knowing of majic cookie value before selecting a new db file, etc.

Pleas comment!!

Shafique
 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Muhammad Shafique
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
author and jackaroo
Posts: 12200
280
Mac IntelliJ IDE Firefox Browser Oracle C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Shafique,

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.

Regards, Andrew
 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Muhammad Shafique
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

Tim:

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.

Thanks,
Shafique
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic