hi Jason,
Thanks for your answer.
Pity that the makePersistence() implementation is to write the WHOLE object to the datastore and not only to the fields that were changed.
This fact is actually forcing ANY shared object update in GAE to use a transaction as a rule.
Further more - in such cases you must implement the "retry mechanism" as an exception in the transaction may occur.
So... updating any shared object in GAE should ALWAYS have these extras:
- do it within a transaction
- implement a retry mechanism
Most of Google's examples in their site are actually not taking that into account. As if they're assuming that most apps won't used shared objects
For example (http://code.google.com/appengine/docs/java/datastore/creatinggettinganddeletingdata.html):
public void updateEmployeeTitle(User user, String newTitle) {
PersistenceManager pm = PMF.get().getPersistenceManager();
try {
Employee e = pm.getObjectById(Employee.class, user.getEmail());
if (titleChangeIsAuthorized(e, newTitle) {
e.setTitle(newTitle);
} else {
throw new UnauthorizedTitleChangeException(e, newTitle);
}
} finally {
pm.close();
}
}
OR:
public void updateEmployeeTitle(Employee e, String newTitle) {
if (titleChangeIsAuthorized(e, newTitle) {
e.setTitle(newTitle);
PersistenceManager pm = PMF.get().getPersistenceManager();
try {
pm.makePersistent(e);
} finally {
pm.close();
}
} else {
throw new UnauthorizedTitleChangeException(e, newTitle);
}
}