Package org.sql2o.data

Examples of org.sql2o.data.LazyTable


            }
        }
    }

    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);
            }
        });
View Full Code Here


        return lt;
    }

    public Table executeAndFetchTable() {
        LazyTable lt =  executeAndFetchTableLazy();
        List<Row> rows = new ArrayList<Row>();
        try {
            for (Row item : lt.rows()) {
                rows.add(item);
            }
        }
        finally {
           lt.close();
        }
        // lt==null is always false
        return new Table(lt.getName(), rows, lt.columns());
    }
View Full Code Here

    @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));
    }
View Full Code Here

TOP

Related Classes of org.sql2o.data.LazyTable

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.