问题是:ds.put(employee)是否发生在事务中?或者外部事务是否被saveRecord(..)中的事务清除/重写?谷歌应用程序引擎数据存储上的嵌套事务3
- 一旦在for循环(假设i == 5)中的某个点处在行datastore.put(..)处引发错误,以前的放置将始发在同一行上是否会回滚?
- 那么在saveRecord(..)中发生的情况如何。我想那些不会被回滚。
DatastoreService datastore = DatastoreServiceFactory.getDatastoreService() Transaction txn = datastore.beginTransaction(); try { for (int i=0; 1<10; i++) { Key employeeKey = KeyFactory.createKey("Employee", "Joe"); Entity employee = datastore.get(employeeKey); employee.setProperty("vacationDays", 10); datastore.put(employee); Entity employeeRecord = createRecord("record", employeeKey); saveRecord(employeeRecord); } txn.commit(); } finally { if (txn.isActive()) { txn.rollback(); } } public void saveRecord(Entity entity) { datastore.beginTransaction(); try { // do some logic in here, delete activity and commit txn datastore.put(entity); } finally { if (datastore.getCurrentTransaction().isActive()) { datastore.getCurrentTransaction().rollback(); } } }
是'ds.beginTransaction()'你的自定义代码吗?每次通话都会返回相同的交易还是新的交易? – 2012-08-06 15:48:42
ds仅仅是对API DataStore对象的引用。 – honzajde 2012-08-06 18:02:54
我编辑了过于模糊的原始示例...请回答最后一次。谢谢。 – honzajde 2012-08-08 12:36:08