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?
精彩评论