@Override public Object inTransaction(Handle handle, TransactionStatus status) throws Exception { handle.insert("insert into something (id, name) values (:id, :name)", 0, "Keith"); throw new IOException(); } });
@Override public Object inTransaction(Handle handle, TransactionStatus status) throws Exception { handle.insert("insert into something (id, name) values (:id, :name)", 0, "Keith"); throw new IOException(); } });
private void doWriteDerby(Handle h, String id, InputStream file) { doDelete(h, id); try { Blob blob = h.getConnection().createBlob(); try (OutputStream out = blob.setBinaryStream(1)) { IOUtils.copy(file, out); } h.insert("INSERT INTO icon_filestore(id, data) values (?,?)", id, blob); } catch (IOException | SQLException ex) { throw IconDataAccessException.launderThrowable(ex); } }
@Override public Object inTransaction(Handle handle, TransactionStatus status) throws Exception { handle.insert("insert into something (id, name) values (:id, :name)", 0, "Keith"); status.setRollbackOnly(); return "Hi"; } });
@Test public void testPrintStream() throws Exception { ByteArrayOutputStream bout = new ByteArrayOutputStream(); h.setSQLLog(new PrintStreamLog(new PrintStream(bout))); String sql = "insert into something (id, name) values (?, ?)"; h.insert(sql, 1, "Brian"); assertTrue(new String(bout.toByteArray()) .matches("statement:\\[insert into something \\(id, name\\) values \\(\\?, \\?\\)\\] took \\d+ millis" + linesep)); }
@Test public void testBaz() throws Exception { Handle h = dbi.open(); h.insert("insert into something (id, name) values (1, 'Keith')"); } }
@Test public void testInsert() throws Exception { h.insert("insert into something (id, name) values (?, ?)", 1, "Hello"); assertEquals(1, logged.size()); assertEquals("insert into something (id, name) values (?, ?)", logged.get(0)); }
@Test public void testBaz() throws Exception { Handle h = dbi.open(); h.insert("insert into something (id, name) values (1, 'Keith')"); } }
@Test public void testRollbackOutsideTx() throws Exception { Handle h = openHandle(); h.insert("insert into something (id, name) values (?, ?)", 7, "Tom"); h.rollback(); }
@Test public void testCommentsInExternalSql() throws Exception { Handle h = openHandle(); h.insert("insert-eric-with-comments"); assertEquals(1, h.select("select name from something").size()); }
@Test public void testCommentsInExternalSql() throws Exception { Handle h = openHandle(); h.insert("insert-eric-with-comments"); assertEquals(1, h.select("select name from something").size()); }
@Test public void testLocateNamedWithSuffix() throws Exception { Handle h = openHandle(); h.insert("insert-keith.sql"); assertEquals(1, h.select("select name from something").size()); }
@Override public String withHandle(Handle handle) throws Exception { handle.insert("insert into something (id, name) values (1, 'Brian')"); return handle.createQuery("select name from something where id = 1").map(Something.class).first().getName(); } });
@Override 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(); } });
@Override public void useHandle(Handle handle) throws Exception { handle.insert("insert into something (id, name) values (1, 'Brian')"); String value = handle.createQuery("select name from something where id = 1").map(Something.class).first().getName(); assertEquals("Brian", value); } });
@Test public void testFoo() throws Exception { Handle h = openHandle(); try { h.insert("WOOF", 7, "Tom"); } catch (StatementException e) { assertEquals(e.getStatementContext().getRawSql(), "WOOF"); } } }
@Test public void testRead() throws Exception { Spiffy s = handle.attach(Spiffy.class); handle.insert("insert into something (id, name) values (17, 'Phil')"); Something phil = s.findByEqualsOnBothFields(new Something(17, "Phil")); assertEquals("Phil", phil.getName()); }
@Test public void testFoo() throws Exception { Handle h = dbi.open(); h.insert("insert into something (id, name) values (1, 'Keith')"); String name = h.createQuery("select name from something where id = ?") .bind(0, 1) .map(Something.class) .first() .getName(); assertEquals("Keith", name); }
@Test public void testBar() throws Exception { Handle h = dbi.open(); h.insert("insert into something (id, name) values (1, 'Keith')"); String name = h.createQuery("select name from something where id = ? and name = ?") .bind(0, 1) .bind(1, "Keith") .map(Something.class) .first().getName(); assertEquals("Keith", name); }
@Test public void testBar() throws Exception { Handle h = dbi.open(); h.insert("insert into something (id, name) values (1, 'Keith')"); String name = h.createQuery("select name from something where id = ? and name = ?") .bind(0, 1) .bind(1, "Keith") .map(Something.class) .first().getName(); assertEquals("Keith", name); }