aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Difference b/w Cookie and LockCookie Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Difference b/w Cookie and LockCookie" Watch "Difference b/w Cookie and LockCookie" New topic
Author

Difference b/w Cookie and LockCookie

Tahir Abbas
Ranch Hand

Joined: May 05, 2007
Posts: 45
Hi,

I've B&S2.2.1 I restarted it after many months. Can anyone of you please explain the following things:-

1) The passed value in String[] data should be used to update the owner field in database or what ? whats the field n.
2) Whats difference between Cookie and LockCookie ?



Thanks!
Tahir

K. Tsang
Bartender

Joined: Sep 13, 2007
Posts: 2528
    
    8

Howdy Tahir, I did URLyBird so I can't answer the cookie bit. But the update part goes like this:

Original record in file = {"FieldA", "FieldB"..."FieldN"}
FieldN is the owner field you need to update

So in your client side you pass this owner field data to your array then pass this array to your update method in Data class. And when you do, all the other fields A to n-1 should be intact (not empty or blank).

So when you read your file you either need to produce an array [0] represents the first field [1] the 2nd and so on or a OO class each field is an instance variable. Then depending on your design, using the OO class or array in the client code, you may need a conversion method like toRoom(String[] ary) and toArray(Room rm).

I'll let those B&S people answer your cookie question.


K. Tsang JavaRanch SCJP5 SCJD/OCM-JD OCPJP7 OCPWCD5 OCPBCD5
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5407
    
  13

Hi Tahir,

I also had an URLyBird assignment without a lockCookie in the interface, but I will try answering your question about the lockCookie as good as I can.

The lockCookie is used to verify that a record can be updated (or deleted) by the client that has locked the record (and only and alone by that client). So if a client locks a record it will get a unique cookie that this client has to use when he wants to update/delete that record. If another client tries to update the same record with another cookie, a SecurityException is thrown.

If you use the search-function on this forum you will find a whole lot of threads about the lockCookie. This thread will be very useful (I hope) for you.

@K. Tsang: some versions of the URLyBird assignment have the lockCookie in the interface as well, so it's not B&S only (just for your information).

Kind regards,
Roel


SCJA, SCJP (1.4 | 5.0 | 6.0), SCJD
http://www.javaroe.be/
Tahir Abbas
Ranch Hand

Joined: May 05, 2007
Posts: 45
Thanks! K. Tsang and Roel De Nijs for the response.

1) When we pass the record number as argument then we can read the record information with the help of record Number (just in few lines) exactly before updating it, then why do we need to send fields data in other parmeter String[] data. Do you not think it is more secure to read record just before updation. It will keep the record lock just for minimum time. Another thing is that we just need to update owner field then why do we need read/write the other fieds we can just move our record pointer to the start of owner field, ofcourse in the required record then write the information.

2) Infact about cookies i am confused with the wording
if the record is locked with a cookie other than lockCookie
Does it mean cookie and LockCookie are separate things. okay LockCookie we can generate with record Number and random method but whats the meaning of first given word "cookie" that is not Lockcookie, where it come from.

Thanks! for your help.

Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5407
    
  13

Hi Tahir,

The parameter String[] data in the update-method contains the new values to update the record with parameter recNo. You have to implement the update-method to update every possible field of a record (and not only the customer field). You are right in the application you will only have to update customer field. But you have also to implement create- and delete-method, 2 methods you won't use at all.

if the record is locked with a cookie other than lockCookie

cookie = the cookie you stored in some structure (map, set, list,...), in the lock-method (so you know which cookie belongs to which locked record
lockCookie = the parameter in the uypdate-method

Kind regards,
Roel
Tahir Abbas
Ranch Hand

Joined: May 05, 2007
Posts: 45
Thanks! Roel De Nijs.

updateRecord(long recNo, String[] data, long lockCookie)

If we send all record in String[] data including the fields those are not required to update then what will be the purpose of fields those are not required to be modified. I was thinking to display all fields except "owner" field in labels because user is allowed to change only the "owner" field that I could show in text box.

But after the discussion I think in form all the record fields should show in textboxes and user should be allowed to change any field because in update method wording "Modifies the fields of a record" is used . Am I right or what will be more suitable.

Cookie and LockCookie: For updation or deletion we need to first apply the lock method "public long lockRecord(long recNo)" that returns cookie that we can generate with record number and a random number and store the same value in Map(recNo, randomly generate number) in lock method, this map should be public. . So it will not be more feasible to pass same cookie as lockCookie parameter This can be used to unlock or to know that: is this record in use. Do you think it a reasonable solution.

I know its taking long time. I'm very thankful for your help.
Best Regards!
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5407
    
  13

Hi Tahir,

My approach was similar to yours: I created a room dialog (I had the URLyBird assignment) showing all info about a selected room. When user wanted to book a room the dialog was shown and only the customer input field was enabled (all other ones were disabled, I could used labels instead too). I don't think it's a good idea to let user modify other fields than the customer field when they want to book a contractor. It will be confusing for a user.
This is my approach of the update-method: a field value is updated as its corresponding element in the array is not a null-value. So null-values are allowed in the array, but those elements are ignored (the corresponding fields will keep their original value).

I don't think making your lockedRecords-map public is the right thing to do. It should be hidden and only be accessed through the lock, unlock and isLocked methods (and also of course in the update/delete method, to check if the record was locked and to see if the cookie passed as a parameter matches the cookie stored in the lockedRecords-map). Seems you have really problems understanding what the lockCookie (or just cookie, it's the same) is about.

A call to the lock-method will result in a unique value (= the cookie) being generated and returned. This value must be used to update/delete and unlock the record. If some client tries to update/delete that same record with another cookie, a SecurityException must be thrown. So here's a little example of a possible scenario:

So if you are going to make your lockedRecords-map public, every client can access this map and get the cookie he wants to update some record on which he doesn't own the lock. So you got something like this:

So client 1 has locked record 1 and another client was able to retrieve the secret unique cookie and can update the record (and maybe even delete it). That's not what you want.

Kind regards,
Roel
Tahir Abbas
Ranch Hand

Joined: May 05, 2007
Posts: 45
Thank you very much Roel De Nijs. I know you spend a lot of time in writing all this. Its highly appreciatable, Thanks again.

I got it I should start coding now.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Difference b/w Cookie and LockCookie