如果我希望所有删除都执行全有或全无。
// inside event plan dao public void delete(EventPlan eventPlan) { final Objectify ofy = Objectify.beginTransaction(); try { final ActivityDAO activityDao = new ActivityDAO(); for (final Activity activity : eventPlan.getActivities()) { activityDao.delete(activity); } ofy.getTxn().commit(); } finally { if (ofy.getTxn().isActive()) { ofy.getTxn().rollback(); | } }
// inside activity dao public void delete(Activity activity) { final Objectify ofy = Objectify.beginTransaction(); try { // do some logic in here, delete activity and commit txn } finally { // check and rollback as normal } }
答案 0 :(得分:0)
如果您使用Objectify 3.1,那么所有交易都是XG-transactions,它可以在最多5个不同的实体组上运行,即如果您的活动没有共同的父级(=将它们放在同一个实体组中),那么您可以只删除一次交易中的最多五次。