本文整理汇总了Java中org.motechproject.mds.service.MotechDataService.doInTransaction方法的典型用法代码示例。如果您正苦于以下问题:Java MotechDataService.doInTransaction方法的具体用法?Java MotechDataService.doInTransaction怎么用?Java MotechDataService.doInTransaction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.motechproject.mds.service.MotechDataService
的用法示例。
在下文中一共展示了MotechDataService.doInTransaction方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setUpTestData
import org.motechproject.mds.service.MotechDataService; //导入方法依赖的package包/类
private void setUpTestData() throws Exception {
MotechDataService service = getService();
final Object instance1 = objectInstance("one", asList("one", "two"));
final Object instance2 = objectInstance("two", asList("two", "one", "four"));
final Object instance3 = objectInstance("four", asList("four", "four", "four"));
final Object instance4 = objectInstance("five", singletonList("five"));
final Object instance5 = objectInstance("one", asList("one", "two", "four", "three"));
final Object instance6 = objectInstance(null, null);
final Object instance7 = objectInstance(null, singletonList(null));
final Object instance8 = objectInstance("", singletonList(""));
service.doInTransaction(new TransactionCallbackWithoutResult() {
@Override
protected void doInTransactionWithoutResult(TransactionStatus status) {
service.create(instance1);
service.create(instance2);
service.create(instance3);
service.create(instance4);
service.create(instance5);
service.create(instance6);
service.create(instance7);
service.create(instance8);
}
});
assertEquals("There were issues creating test data", 8, service.count());
}
示例2: setUpTestData
import org.motechproject.mds.service.MotechDataService; //导入方法依赖的package包/类
private void setUpTestData() throws Exception {
Class<?> clazz = getEntityClass();
DateTime threeDaysAgo = NOW.minusDays(3);
DateTime eightDaysAgo = NOW.minusDays(8);
DateTime notThisMonth = NOW.minusMonths(2);
DateTime notThisYear = NOW.minusYears(2);
MotechDataService service = getService();
final Object instance1 = objectInstance(clazz, true, NOW.toDate(), NOW, "now");
final Object instance2 = objectInstance(clazz, true, threeDaysAgo.toDate(), threeDaysAgo, "threeDaysAgo");
final Object instance3 = objectInstance(clazz, false, eightDaysAgo.toDate(), eightDaysAgo, "eightDaysAgo");
final Object instance4 = objectInstance(clazz, false, notThisMonth.toDate(), notThisMonth, "notThisMonth");
final Object instance5 = objectInstance(clazz, false, notThisYear.toDate(), notThisYear, "notThisYear");
service.doInTransaction(new TransactionCallbackWithoutResult() {
@Override
protected void doInTransactionWithoutResult(TransactionStatus status) {
service.create(instance1);
service.create(instance2);
service.create(instance3);
service.create(instance4);
service.create(instance5);
}
});
assertEquals("There were issues creating test data", 5, service.count());
}