Fix for #159 - Refactor - cleanup clode when closing query only transaction + change default option

This commit is contained in:
Rob Bygrave
2014-07-05 22:10:53 +12:00
parent 1ddc103582
commit cceb7c035c
11 changed files with 162 additions and 144 deletions
@@ -39,4 +39,34 @@ public class TestQueryFindVisit extends BaseTestCase {
Assert.assertEquals(2, counter.get());
}
/**
* Test the behaviour when an exception is thrown inside the findVisit().
*/
@Test(expected=IllegalStateException.class)
public void testVisitThrowingException() {
ResetBasicData.reset();
EbeanServer server = Ebean.getServer(null);
Query<Customer> query = server.find(Customer.class).setAutofetch(false)
.fetch("contacts", new FetchConfig().query(2)).where().gt("id", 0).orderBy("id")
.setMaxRows(2);
final AtomicInteger counter = new AtomicInteger(0);
query.findVisit(new QueryResultVisitor<Customer>() {
public boolean accept(Customer bean) {
counter.incrementAndGet();
if (counter.intValue() > 0) {
throw new IllegalStateException("cause a failure");
}
return true;
}
});
Assert.assertFalse("Never get here - exception thrown", true);
}
}