开发者

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

开发者 https://www.devze.com 2023-02-18 02:19 出处:网络
There are two different ways to perform transactions (JDO) in the App Engine datastore. Method 1: Use PersistenceManager

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

精彩评论

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

关注公众号