• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

updateRecord (with lockCookie) question

 
Anne Crace
Ranch Hand
Posts: 223
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I am currently implementing all the CRUD methods that are in the supplied interface, and of course my Data class. I have URLyBird 1.2.2. Here's my update method signature: I have my cookie generator done, no problem there. I added another method inside Data like this:
I call this method from inside lockRecord(long recNo) like this: All good, except for update, which has the lockCookie as a parameter in its method signature. I am wondering if I should ignore it, and just generate another one with the passed in record number (how I did it for the other 2), or rethink my design? I am trying to think how Sun will test my application. Create, update and delete will never be called from the client, so not sure how the parameters will be sent in. I know how I will send them in. I'm just confused Any and all help is appreciated!
 
Fola Fadairo
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Anne,

To update or delete, the sequence should be:
1.) Lock record.
2.) Update/Delete record.
3.) Unlock record.

The lock method returns a lock cookie which is used by the update and delete methods to validate that the client owns the lock on the record before allowing the update or delete.

The unlock method releases the restriction placed on the record by the lock cookie.

You can look at this link. I hope this is helpful.

Regards.
 
Alecsandru Cocarla
Ranch Hand
Posts: 158
posted 7 years ago
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Be careful with your createLockCookie() method... When creating a new Random at every call, you'll always end up with the same cookie for the same record!
 
Anne Crace
Ranch Hand
Posts: 223
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks all! I do have to redo this. Delete has the cookie as a parameter too, create is the only one that doesn't. Alecsandru, you are so right. Maybe I need to use the timestamp with the number to generate the cookie. I think many others have taken this approach.
 
Alecsandru Cocarla
Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I used System.nanoTime(), but you can also use Random, just don't generate a new one at every call (it also affects performance). Just have a static or member Random and use that one.
 
Anne Crace
Ranch Hand
Posts: 223
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, Alecsandru. I have as a class variable. It should never be the same using the time to generate it. Next to impossible anyway!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic