[英]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. 在App Engine数据存储区中有两种不同的执行事务(JDO)的方式。
Method 1 : Use PersistenceManager 方法1 :使用PersistenceManager
try {
pm.currentTransaction().begin();
// do stuff
pm.currentTransaction().commit();
}
finally {
if (pm.currentTransaction().isActive())
pm.currentTransaction().rollback();
}
Method 2 : Use DatastoreService 方法2 :使用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. 我相信JDO本身使用低级DatastoreService API进行事务处理。
If you are using JDO to work with objects, you should use it's (JDOs/JPAs) persistence managers transaction methods. 如果使用JDO处理对象,则应使用其(JDO / JPA)持久性管理器事务方法。 Otherwise, how would your objects be persisted to the underlying datastore? 否则,您的对象将如何持久保存到基础数据存储中?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.