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.