public void testFirstResult() throws Exception { h.insert("insert into something (id, name) values (1, 'eric')"); h.insert("insert into something (id, name) values (2, 'brian')"); Something r = h.createQuery("select * from something order by id").map(Something.class).first(); assertNotNull(r); assertEquals("eric", r.getName()); }
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 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 testIteratorBehavior3() throws Exception { h.insert("insert into something (id, name) values (1, 'eric')"); h.insert("insert into something (id, name) values (2, 'eric')"); int count = 0; for (Something s : h.createQuery("select * from something order by id").map(Something.class)) { count++; assertEquals("eric", s.getName()); } assertEquals(2, count); }
private static String výpisČárkyObjekty(Collection<Something> věci) { boolean první = true; String výstup = ""; for (Something věc : věci) { if (první) { první = false; } else { výstup += ","; } výstup += " " + věc.getName(); } return výstup; }
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 static void main(String[] args) { System.out.println("BEGIN"); try { Something.method(3000); } catch (InterruptedException e) { } System.out.println("END"); }
public void testRegisterInferredOnDBI() throws Exception { dbi.registerMapper(new SomethingMapper()); Something sam = dbi.withHandle( new HandleCallback<Something>() { public Something withHandle(Handle handle) throws Exception { handle.insert("insert into something (id, name) values (18, 'Sam')"); return handle .createQuery("select id, name from something where id = :id") .bind("id", 18) .mapTo(Something.class) .first(); } }); assertEquals("Sam", sam.getName()); }