It sounds to me like all of this should either be: 1. In a single transaction - but you'll want to question how important this is. Distributed transactions are hard to do an expensive: http://danielwilkerson.com/dist-trans-gae.html 2. Versioned objects: you update each set of objects with a version and bump it up. You update an entity last with the newest version number, and retrieve based on that number. This is not a one-size-fits-all solution and will only work for some data sets.
On Wed, Mar 3, 2010 at 7:58 PM, DutrowLLC <[email protected]> wrote: > I was hoping to have several transactions going at the same time and > if anything failed in anyone of them, then I could roll back all of > them. > > I set up some code to do this, looks something like the code below, > there may be some other problems, but the one that I see is that what > if there is an Exception thrown in the loop where I commit the > transactions, then I've already committed some of them, but not > others? Is this not something that I should be doing? If not, how > should I handle this sort of situation? > > Vector<Transaction> txnVector = new Vector<Transaction>(); > DatastoreService ds; > Transaction txn; > > try{ > ds = DatastoreServiceFactory.getDatastoreService(); > txn = ds.beginTransaction(); > txnVector.add(txn); > ds.put( entity, txn ); > > ds = DatastoreServiceFactory.getDatastoreService(); > txn = ds.beginTransaction(); > txnVector.add(txn); > ds.put( entity2, txn ); > } > // ROLL BACK IF THERE IS A PROBLEM > catch( Exception e ){ > for( Transaction txn : txnVector ){ > if( txn.isActive() ){ > txn.rollback(); > } > } > } > // COMMIT ALL > for( Transaction txn : txnVector ){ > if( txn.IsActive() ){ > txn.commit(); > } > } > > > > > -- > 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. > > -- 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.
