use of org.jdbi.v3.core.statement.Update in project metrics by dropwizard.
the class TimedAnnotationNameStrategyTest method testAnnotationOnMethodWithCustomAbsoluteName.
@Test
public void testAnnotationOnMethodWithCustomAbsoluteName() throws Exception {
when(ctx.getExtensionMethod()).thenReturn(new ExtensionMethod(Foo.class, Foo.class.getMethod("absoluteUpdate")));
assertThat(timedAnnotationNameStrategy.getStatementName(ctx)).isEqualTo("absolute-update");
}
use of org.jdbi.v3.core.statement.Update in project metrics by dropwizard.
the class TimedAnnotationNameStrategyTest method testAnnotationOnMethodWithCustomName.
@Test
public void testAnnotationOnMethodWithCustomName() throws Exception {
when(ctx.getExtensionMethod()).thenReturn(new ExtensionMethod(Foo.class, Foo.class.getMethod("customUpdate")));
assertThat(timedAnnotationNameStrategy.getStatementName(ctx)).isEqualTo("com.codahale.metrics.jdbi3.strategies.TimedAnnotationNameStrategyTest$Foo.custom-update");
}
use of org.jdbi.v3.core.statement.Update in project jdbi by jdbi.
the class TestNamedParams method testMapKeyBinding.
@Test
public void testMapKeyBinding() throws Exception {
Handle h = dbRule.openHandle();
Update s = h.createUpdate("insert into something (id, name) values (:id, :name)");
Map<String, Object> args = new HashMap<>();
args.put("id", 0);
args.put("name", "Keith");
s.bindMap(args);
int insert_count = s.execute();
Query q = h.createQuery("select * from something where id = :id").bind("id", 0);
final Something fromDb = q.mapToBean(Something.class).findOnly();
assertThat(insert_count).isEqualTo(1);
assertThat(fromDb).extracting(Something::getId, Something::getName).containsExactly(0, "Keith");
}
use of org.jdbi.v3.core.statement.Update in project jdbi by jdbi.
the class TestNamedParams method testCascadedLazyArgs.
@Test
public void testCascadedLazyArgs() throws Exception {
Handle h = dbRule.openHandle();
Update s = h.createUpdate("insert into something (id, name) values (:id, :name)");
Map<String, Object> args = new HashMap<>();
args.put("id", 0);
s.bindMap(args);
s.bindBean(new Object() {
@SuppressWarnings("unused")
public String getName() {
return "Keith";
}
});
int insert_count = s.execute();
assertThat(insert_count).isEqualTo(1);
Something something = h.createQuery("select id, name from something").mapToBean(Something.class).findOnly();
assertThat(something).isEqualTo(new Something(0, "Keith"));
}
use of org.jdbi.v3.core.statement.Update in project jdbi by jdbi.
the class TestNamedParams method testInsert.
@Test
public void testInsert() throws Exception {
Handle h = dbRule.openHandle();
Update insert = h.createUpdate("insert into something (id, name) values (:id, :name)");
insert.bind("id", 1);
insert.bind("name", "Brian");
int count = insert.execute();
assertThat(count).isEqualTo(1);
}
Aggregations