• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

intentions of variable cookie on methods.

 
�verton Amorim
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Ranchers !!
Somebody could explain me which the intention of the variable cookie in the methods update, delete and unlock in the DBAcess interface of the B&S?



Thanks
�verton
SCJP, SCJD(UD)
 
peter wooster
Ranch Hand
Posts: 1033
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by �verton Amorim:
Hello Ranchers !!
Somebody could explain me which the intention of the variable cookie in the methods update, delete and unlock in the DBAcess interface of the B&S?



Thanks
�verton
SCJP, SCJD(UD)


It is used to confirm that the record is locked with the cookie. That way only the user that locked the record can update it or unlock it.
 
Paul Bourdeaux
Ranch Hand
Posts: 783
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is how I interpreted the cookie... Please feel free to correct me if needed.

When a client locks a record, a unique long is generated by the server and associated with the record number (I plan on doing this with a lockedRecord collection - this will also ensure that duplicate cookies are not used at the same time). The long is returned to the client as the cookie.

When the client tries to update, delete, or unlock the record, it must provide the same cookie value that was provided when it locked the record. If it doesn't have the correct cookie value, then a SecurityException is thrown (at least in my version - B&S 2.2.3)
 
No�l Verdurmen
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Now we now what the cookie does, the question remains why would you (or actually: why would the specification) use cookies.

I think it is to reduce the amount of synchronization needed to make your application thread-safe, and thus faster.

Besides, I actually think a cookie should be stored at the client.
 
Paul Bourdeaux
Ranch Hand
Posts: 783
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think it is to reduce the amount of synchronization needed to make your application thread-safe, and thus faster.

Yes, that is exactly what it is for. If cookies were not specified in the assignment, you have to rely on a contract with the clients that no client will attempt to unlock a record that it did not lock in the first place. The cookie just enforces this contract.
[ September 09, 2004: Message edited by: Paul Bourdeaux ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic