try {
service.inPropagationRequired(new Callback()
{
public void call(IDBI outer)
{
final Handle h = DBIUtil.getHandle(outer);
h.insert("insert into something (id, name) values (7, 'ignored')");
try {
service.inNested(new Callback()
{
public void call(IDBI inner)
{
final Handle h = DBIUtil.getHandle(inner);
h.insert("insert into something (id, name) values (8, 'ignored again')");
int count = h.createQuery("select count(*) from something").map(new IntegerMapper()).first();
assertEquals(2, count);
throw new ForceRollback();
}
});
fail("should have thrown an exception");
}
catch (ForceRollback e) {
assertTrue(true);
}
int count = h.createQuery("select count(*) from something").map(new IntegerMapper()).first();
assertEquals(1, count);
throw new ForceRollback();
}
});
fail("should have thrown an exception");
}
catch (ForceRollback e) {
assertTrue(true);
}
service.inPropagationRequired(new Callback()
{
public void call(IDBI dbi)
{
final Handle h = DBIUtil.getHandle(dbi);
int count = h.createQuery("select count(*) from something").map(new IntegerMapper()).first();
assertEquals(0, count);
}
});
}