use of org.jdbi.v3.core.statement.Update in project metrics by dropwizard.
the class TimedAnnotationNameStrategyTest method testAnnotationOnClass.
@Test
public void testAnnotationOnClass() throws Exception {
when(ctx.getExtensionMethod()).thenReturn(new ExtensionMethod(Bar.class, Bar.class.getMethod("update")));
assertThat(timedAnnotationNameStrategy.getStatementName(ctx)).isEqualTo("com.codahale.metrics.jdbi3.strategies.TimedAnnotationNameStrategyTest$Bar.update");
}
use of org.jdbi.v3.core.statement.Update in project jdbi by jdbi.
the class Handle method execute.
/**
* Execute a SQL statement, and return the number of rows affected by the statement.
*
* @param sql the SQL statement to execute, using positional parameters (if any)
* @param args positional arguments
*
* @return the number of rows affected
*/
public int execute(String sql, Object... args) {
Update stmt = createUpdate(sql);
int position = 0;
for (Object arg : args) {
stmt.bind(position++, arg);
}
return stmt.execute();
}
use of org.jdbi.v3.core.statement.Update in project jdbi by jdbi.
the class TestStatements method testSimpleUpdate.
@Test
public void testSimpleUpdate() throws Exception {
h.execute("insert into something (id, name) values (1, 'eric')");
h.execute("update something set name = 'cire' where id = 1");
Something eric = h.createQuery("select * from something where id = 1").mapToBean(Something.class).list().get(0);
assertThat(eric.getName()).isEqualTo("cire");
}
use of org.jdbi.v3.core.statement.Update in project jdbi by jdbi.
the class TestStatements method testUpdate.
@Test
public void testUpdate() throws Exception {
h.execute("insert into something (id, name) values (1, 'eric')");
h.createUpdate("update something set name = 'ERIC' where id = 1").execute();
Something eric = h.createQuery("select * from something where id = 1").mapToBean(Something.class).list().get(0);
assertThat(eric.getName()).isEqualTo("ERIC");
}
use of org.jdbi.v3.core.statement.Update in project jdbi by jdbi.
the class TestUpdateGeneratedKeys method testUpdate.
@Test
public void testUpdate() throws Exception {
Handle h = dbRule.openHandle();
Update insert = h.createUpdate("insert into something_else (name) values (:name)");
insert.bind("name", "Brian");
Long id1 = insert.executeAndReturnGeneratedKeys().mapTo(long.class).findOnly();
assertThat(id1).isNotNull();
Update update = h.createUpdate("update something_else set name = :name where id = :id");
update.bind("id", id1);
update.bind("name", "Tom");
Optional<Long> id2 = update.executeAndReturnGeneratedKeys().mapTo(long.class).findFirst();
assertThat(id2.isPresent()).isFalse();
}
Aggregations