public void testMappedQueryObject() throws Exception { h.insert("insert into something (id, name) values (1, 'eric')"); h.insert("insert into something (id, name) values (2, 'brian')"); Query<Something> query = h.createQuery("select * from something order by id").map(Something.class); List<Something> r = query.list(); Something eric = r.get(0); assertEquals("eric", eric.getName()); assertEquals(1, eric.getId()); }
public void testMappedQueryObjectWithNullForPrimitiveIntField() throws Exception { h.insert("insert into something (id, name, intValue) values (1, 'eric', null)"); Query<Something> query = h.createQuery("select * from something order by id").map(Something.class); List<Something> r = query.list(); Something eric = r.get(0); assertEquals("eric", eric.getName()); assertEquals(1, eric.getId()); assertEquals(0, eric.getIntValue()); }
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()); }
public void testMapper() throws Exception { h.insert("insert into something (id, name) values (1, 'eric')"); h.insert("insert into something (id, name) values (2, 'brian')"); Query<String> query = h.createQuery("select name from something order by id") .map( new ResultSetMapper<String>() { public String map(int index, ResultSet r, StatementContext ctx) throws SQLException { return r.getString(1); } }); String name = query.list().get(0); assertEquals("eric", name); }