• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

updateRecord (with lockCookie) question

 
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!
 
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.
 
Ranch Hand
Posts: 158
  • 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!
 
She's brilliant. She can see what can be and is not limited to what is. And she knows this tiny ad:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic