/** Returns a single value (or null) */ public <T> T queryValue(CharSequence sql, ResultIterator.ResultWrapper<T> rc) throws SQLException { ResultIterator<T> results = new ResultIterator<T>(query(sql), rc); T result = results.nextOrNull(); results.close(); return (result); }
/** @since 3.2 */ @Override public <T> void iterate(Select<T> query, ResultIteratorCallback<T> callback) { ResultIterator<T> it = iterator(query); try { for (T t : it) { callback.next(t); } } finally { it.close(); } }
public void testIteratorBehavior2() throws Exception { h.insert("insert into something (id, name) values (1, 'eric')"); h.insert("insert into something (id, name) values (2, 'brian')"); ResultIterator<Something> i = h.createQuery("select * from something order by id").map(Something.class).iterator(); Something first = i.next(); assertEquals("eric", first.getName()); Something second = i.next(); assertEquals(2, second.getId()); assertFalse(i.hasNext()); i.close(); }
public void testFetchSize() throws Exception { h.createScript("default-data").execute(); Query<Something> q = h.createQuery("select id, name from something order by id").map(Something.class); q.setFetchSize(1); ResultIterator<Something> r = q.iterator(); assertTrue(r.hasNext()); r.next(); assertTrue(r.hasNext()); r.next(); assertFalse(r.hasNext()); }