use of org.jdbi.v3.core.Jdbi in project jdbi by jdbi.
the class TestDocumentation method testObtainHandleInCallback.
@Test
public void testObtainHandleInCallback() throws Exception {
Jdbi db = Jdbi.create("jdbc:h2:mem:" + UUID.randomUUID());
db.useHandle(handle -> handle.execute("create table silly (id int)"));
}
use of org.jdbi.v3.core.Jdbi in project jdbi by jdbi.
the class TestUseConfiguredDefaultParameterCustomizerFactory method setUp.
@Before
public void setUp() throws Exception {
Jdbi db = dbRule.getJdbi();
ParameterCustomizerFactory defaultParameterCustomizerFactory = (sqlObjectType, method, param, index, type) -> {
invocationCounter.incrementAndGet();
return (stmt, arg) -> stmt.bind("mybind" + index, arg);
};
db.configure(SqlObjects.class, c -> c.setDefaultParameterCustomizerFactory(defaultParameterCustomizerFactory));
handle = db.open();
}
use of org.jdbi.v3.core.Jdbi in project jdbi by jdbi.
the class TestVavrMapCollectorWithDB method testMapCollectorWithGlobalKeyValue_shouldSucceed.
@Test
public void testMapCollectorWithGlobalKeyValue_shouldSucceed() {
Jdbi jdbiWithKeyColAndValCol = dbRule.getJdbi().setMapKeyColumn("key_c").setMapValueColumn("val_c");
Boolean executed = jdbiWithKeyColAndValCol.withHandle(h -> {
HashMap<String, String> valueMap = h.createQuery("select val_c, key_c from keyval").collectInto(new GenericType<HashMap<String, String>>() {
});
assertThat(valueMap).containsOnlyElementsOf(expectedMap);
return true;
});
assertTrue(executed);
}
use of org.jdbi.v3.core.Jdbi in project jdbi by jdbi.
the class BindBeanListTest method init.
@BeforeClass
public static void init() {
final Jdbi db = dbRule.getJdbi();
db.installPlugin(new SqlObjectPlugin());
db.registerRowMapper(new SomethingMapper());
handle = db.open();
handle.execute("insert into something(id, name) values(1, '1')");
handle.execute("insert into something(id, name) values(2, '2')");
// "control group" element that should *not* be returned by the queries
handle.execute("insert into something(id, name) values(3, '3')");
expectedSomethings = Arrays.asList(new Something(1, "1"), new Something(2, "2"));
}
use of org.jdbi.v3.core.Jdbi in project jdbi by jdbi.
the class BindListNullTest method init.
@BeforeClass
public static void init() {
final Jdbi db = dbRule.getJdbi();
db.registerRowMapper(new SomethingMapper());
db.installPlugin(new SqlObjectPlugin());
handle = db.open();
handle.execute("insert into something(id, name) values(1, null)");
handle.execute("insert into something(id, name) values(2, null)");
handle.execute("insert into something(id, name) values(3, null)");
handle.execute("insert into something(id, name) values(4, null)");
handle.execute("insert into something(id, name) values(5, 'bla')");
handle.execute("insert into something(id, name) values(6, 'null')");
handle.execute("insert into something(id, name) values(7, '')");
}
Aggregations