Hi,

I have a scenario where I try to delete a number of entities from the 
datastore.
The operation fails with a ConcurrentModificationException, and I expect my 
code below to handle this scenario and rollback.
The exception is thrown in transactionsHandler.commit(), more specifically 
on transaction.commit(); - this causes the flow to go to the finally block, 
but it turns out the transaction is no longer active, and thus the 
transaction is not rolled back, causing an inconsistent datastore.
How should I handle the scenario instead?

Thanks,
-Louise

Code:

Transaction transaction = transactionHandler.begin();

try {
    execute(transaction);//Delete entities from datastore
    logger.info("Initiating commit of transaction");
    transactionHandler.commit();
} finally {
    transactionHandler.tryRollback();
}


public class TransactionHandler{
    private Logger logger = Logger.getLogger(this.getClass().getName());
    private Transaction transaction;

    public Transaction begin(){
        DatastoreService datastore = 
DatastoreServiceFactory.getDatastoreService();
        TransactionOptions options = TransactionOptions.Builder.withXG(true);
        transaction = datastore.beginTransaction(options);
        return transaction;
    }

    public void commit(){
        if (transaction.isActive()){
            transaction.commit();
            logger.info("Transaction comittet");
        }else{
            logger.warning("Transaction was not active - transaction was not 
comittet");
        }
    }

    public void tryRollback(){
        if (transaction.isActive()){
            transaction.rollback();
            logger.info("Transaction rolled back as transaction was still 
active");
        }else{
            logger.info("Transaction was not active - transaction was not 
rolledback");
        }
    }
}

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/google-appengine.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-appengine/93f3abed-53e3-4361-a182-5fe0d8d80809%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
  • [google-appengine]... Louise Elmose Hedegaard

Reply via email to