use of org.sql2o.data.LazyTable in project sql2o by aaberg.
the class Query method executeAndFetchTableLazy.
public LazyTable executeAndFetchTableLazy() {
final LazyTable lt = new LazyTable();
lt.setRows(new ResultSetIterableBase<Row>() {
public Iterator<Row> iterator() {
return new TableResultSetIterator(rs, isCaseSensitive(), getConnection().getSql2o().getQuirks(), lt);
}
});
return lt;
}
use of org.sql2o.data.LazyTable in project sql2o by aaberg.
the class Sql2oTest method testLazyTable.
@Test
public void testLazyTable() throws SQLException {
createAndFillUserTable();
Query q = sql2o.createQuery("select * from User");
LazyTable lt = null;
try {
lt = q.executeAndFetchTableLazy();
for (Row r : lt.rows()) {
String name = r.getString("name");
assertThat(name, notNullValue());
}
// still in autoClosable scope. Expecting connection to be open.
assertThat(q.getConnection().getJdbcConnection().isClosed(), is(false));
} finally {
// simulate autoClose.
lt.close();
}
// simulated autoClosable scope exited. Expecting connection to be closed.
assertThat(q.getConnection().getJdbcConnection().isClosed(), is(true));
}
Aggregations