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
@@ -1,5 +1,7 @@
package com.avaje.tests.query;
import javax.persistence.PersistenceException;
import org.junit.Assert;
import org.junit.Test;
@@ -40,4 +42,50 @@ public class TestQueryFindIterate extends BaseTestCase {
Assert.assertEquals(2, count);
}
@Test(expected=PersistenceException.class)
public void testWithExceptionInQuery() {
ResetBasicData.reset();
EbeanServer server = Ebean.getServer(null);
// intentionally a query with incorrect type binding
Query<Customer> query = server.find(Customer.class)
.setAutofetch(false)
.where().gt("id","JUNK_NOT_A_LONG")
.setMaxRows(2);
// this throws an exception immediately
QueryIterator<Customer> it = query.findIterate();
it.hashCode();
Assert.assertTrue("Never get here as exception thrown", false);
}
@Test(expected=IllegalStateException.class)
public void testWithExceptionInLoop() {
ResetBasicData.reset();
EbeanServer server = Ebean.getServer(null);
Query<Customer> query = server.find(Customer.class)
.setAutofetch(false)
.where().gt("id", 0)
.setMaxRows(2);
QueryIterator<Customer> it = query.findIterate();
try {
while (it.hasNext()) {
Customer customer = it.next();
if (customer != null) {
throw new IllegalStateException("cause an exception");
}
}
} finally {
it.close();
}
}
}