Hi all,
I'm new to GoogleAppEngine and I'm not sure about the right procedure
to update an object.

Let's say that in a servlet I have to fetch an object with a query
(not with its key), update some of its attributes and then save to DB.
I accomplish this task with the following code (up to now it is the
only way I'm able to correctly run this example):
*****************************************************************************
PersistenceManager pm = //get from factory
MyPersistedObject obj = queryToDB(pm, other_args);
obj.setXXX(...);
//other stuff that needs obj

//save to DB:
try {
pm.makePersistent(obj);
} finally {
pm.close();
}
*****************************************************************************
Now the questions:
1) if the object retrieved in the query changes while the "//other
stuff" is computed, the pm.close() statement throws a
ConcurrentModification exception e my work is gone. Given that "//
other stuff" may take quite a long to complete, this scenario is not
negligible. How can I face this problem?
2) Is it possible to fetch the object with one PersistenceManager
instance and save it with another? This may allow me not to pass pm in
the arguments of queryToDB() method...
3) How can I make this piece of code thread-safe? I mean, I would like
to block the execution of another thread which makes use of the object
fetched with queryToDB(), so that I can never occur into a
ConcurrentModification exception: is it possible? Perhaps with a
clever use of MemCache?
4) I also tried to wrap pm.close() in a loop with a number of retries
until the change is correctly saved onto DB, but once the
ConcurrentModification exception is thrown, seems that the object now
is dirty and cannot be saved anymore...

Please, give me some hints about these topics!!

Thank you very much
Best
cghersi


-- 
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