Huh?

As you are only able to do work in a single transactional unit-of-work
on a single entity-group, rollback must be considered "usefull".
In the above mentioned snippet, an Account entity is looked-up,
updated and a child entity TransactionRecord is added, all in a single
entity-group, namely the Account's. So a rollback will undo all
operations.
If you had added TransactionRecord to, lets say a "TransactionRecords"
entity-group, you would have gotten an error if you were operating in
a transactional scope, or no-transaction support at all, hence a
rollback would not have been possible.

Cheers, Lars Borup Jensen

On 1 Jun., 06:21, Didier Durand <durand.did...@gmail.com> wrote:
> Hi,
>
> entity group is not useful at rollback but rather limits you to which
> updates you can do: all the entities you touch in a single transaction
> must be in the same entity group.
>
> So, designing your groups properly is a key design issue in GAE to
> avoid unnecessary complexity when you later need to update at once
> entities that you created before in various groups.
>
> regards
>
> didier
>
> On May 30, 7:57 am, Jacob <jacob.rho...@gmail.com> wrote:
>
>
>
>
>
>
>
> > I am writing some code that needs to do a rollback on a secondary
> > object/table should the transaction fail, I believe this can be done
> > via entity groups, however I am not sure if this is how it would be
> > implemented. I have written some sample code to check if what I would
> > be doing is correct?
>
> > Would the following code ensure the "Account" object is never updated
> > if the insert of the "TransactionRecord" object fails.
>
> >         public void addTransaction(String account, Double value, String
> > description, Date date) throws EntityNotFoundException {
> >                 DatastoreService datastore =
> > DatastoreServiceFactory.getDatastoreService();
>
> >                 int retries = 3;
> >                 while (true) {
> >                         Transaction txn = datastore.beginTransaction();
> >                         try {
>
> >                                 // Update the bank balance
> >                                 Key key = KeyFactory.createKey("Account", 
> > account);
> >                                 Entity e = datastore.get(key);
> >                                 Double balance = (Double) 
> > e.getProperty("balance");
> >                                 balance += value;
> >                                 e.setProperty("balance", value);
> >                                 datastore.put(e);
>
> >                                 // Record transaction details
> >                                 Entity d = new Entity("TransactionRecord", 
> > key);
> >                                 d.setProperty("account_key", key);
> >                                 d.setProperty("date", date);
> >                                 d.setProperty("value", value);
> >                                 d.setProperty("description", description);
>
> >                                 txn.commit();
> >                                 break;
> >                         } catch (ConcurrentModificationException e) {
> >                                 if (retries == 0)
> >                                         throw e;
> >                                 --retries;
> >                         } finally {
> >                                 if (txn.isActive())
> >                                         txn.rollback();
> >                         }
> >                 }
>
> >         }
>
> > Thanks for any feedback!

-- 
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 google-appengine-java@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.

Reply via email to