Search in sources :

Example 1 with LazyTable

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;
}
Also used : LazyTable(org.sql2o.data.LazyTable) Iterator(java.util.Iterator) TableResultSetIterator(org.sql2o.data.TableResultSetIterator) Row(org.sql2o.data.Row) TableResultSetIterator(org.sql2o.data.TableResultSetIterator)

Example 2 with LazyTable

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));
}
Also used : LazyTable(org.sql2o.data.LazyTable) Row(org.sql2o.data.Row) Test(org.junit.Test)

Aggregations

LazyTable (org.sql2o.data.LazyTable)2 Row (org.sql2o.data.Row)2 Iterator (java.util.Iterator)1 Test (org.junit.Test)1 TableResultSetIterator (org.sql2o.data.TableResultSetIterator)1