开发者

Two different methods for Google App Engine Datastore Transactions -- which to use?

There are two different ways to perform transactions (JDO) in the App Engine datastore.

Method 1: Use PersistenceManager

try {
   pm.currentTransaction().begin();
   // do stuff
   pm.currentTransaction().commit();
}
finally {
    if (pm.currentTransaction().isActive()) 
        pm.currentTransaction().rollback();
}

Method 2: Use DatastoreService

DatastoreService datastore = DatastoreServiceFactory.getDatastoreService()
try {
    Transaction txn = datastore.beginTransaction();
    // do stuff
    txn.commit();
}
finally {
    if (txn.isActive()) {
 开发者_开发知识库       txn.rollback();
    }
}

What is the functional difference between these two approaches?


I believe that JDO in itself uses the low level DatastoreService APIs for transaction handling.

If you are using JDO to work with objects, you should use it's (JDOs/JPAs) persistence managers transaction methods. Otherwise, how would your objects be persisted to the underlying datastore?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜