Here's a blog post Max Ross wrote about optimistic locking using built in
features of JDO/JPA

On Thu, Apr 8, 2010 at 2:42 AM, mscwd01 <[email protected]> wrote:

> Thanks John. So basically the process should be:
>
> - Query for the object inside a transaction
> - Update the object counter
> - Commit
>
> - If commit fails - re-query the datastore for the same object?
>
> Is it possible to just catch the exception and try committing the
> object again or will I have to query the datastore for the object
> again?
>
> Also will it work when you query for a parent object and then update
> the counter of a child object?
>
> Thanks again.
>
> On Apr 8, 10:33 am, John Patterson <[email protected]> wrote:
> > You will need to read and update the object in a transaction which
> > will throw an exception on commit if another thread updates the same
> > entity.  You can then refresh the object and try again.  Also look
> > into memcache which has an atomic counter increment method that is
> > much faster than reading and writing to the datastore.  The downside
> > is that the counts could be reset so you may need to periodically
> > store them in the datastore.
> >
> > On 8 Apr 2010, at 16:17, mscwd01 wrote:
> >
> >
> >
> > > Hey,
> >
> > > How do you ensure, once you have queried an object from the datastore,
> > > that another call to that object cannot be made?
> > > I basically have a bunch of objects with counters which get
> > > incremented during each call to that object.
> >
> > > What I need to ensure is the object doesn't get called by two threads,
> > > each of which increment the counter by 1 and persist the object back
> > > to the datastore, only for the counter to be incremented by 1 and not
> > > by 2.
> >
> > > Thanks
> >
> > > --
> > > You received this message because you are subscribed to the Google
> > > Groups "Google App Engine for Java" group.
> > > To post to this group, send email to
> [email protected]
> > > .
> > > To unsubscribe from this group, send email to
> [email protected]<google-appengine-java%[email protected]>
> > > .
> > > For more options, visit this group athttp://
> groups.google.com/group/google-appengine-java?hl=en
> > > .
>
> --
> You received this message because you are subscribed to the Google Groups
> "Google App Engine for Java" group.
> To post to this group, send email to
> [email protected].
> To unsubscribe from this group, send email to
> [email protected]<google-appengine-java%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/google-appengine-java?hl=en.
>
>


-- 
Ikai Lan
Developer Programs Engineer, Google App Engine
http://googleappengine.blogspot.com | http://twitter.com/app_engine

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine for Java" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.

Reply via email to