use of org.jdbi.v3.core.Something in project jdbi by jdbi.
the class TestReentrancy method testTxnReentrant.
@Test
public void testTxnReentrant() throws Exception {
final TheBasics dao = db.onDemand(TheBasics.class);
dao.withHandle(handle1 -> {
handle1.useTransaction(h -> {
dao.insert(new Something(1, "x"));
List<String> rs = h.createQuery("select name from something where id = 1").mapTo(String.class).list();
assertThat(rs).hasSize(1);
h.createQuery("SELECT 1").mapTo(int.class).list();
});
return null;
});
}
use of org.jdbi.v3.core.Something in project jdbi by jdbi.
the class TestDefineParameter method testDefineParameter.
@Test
public void testDefineParameter() throws Exception {
handle.execute("create table stuff (id identity primary key, name varchar(50))");
handle.execute("create table junk (id identity primary key, name varchar(50))");
HoneyBadger badass = handle.attach(HoneyBadger.class);
Something ted = new Something(1, "Ted");
Something fred = new Something(2, "Fred");
badass.insert("stuff", ted);
badass.insert("junk", fred);
assertThat(badass.findById("stuff", 1)).isEqualTo(ted);
assertThat(badass.findById("junk", 1)).isNull();
assertThat(badass.findById("stuff", 2)).isNull();
assertThat(badass.findById("junk", 2)).isEqualTo(fred);
}
use of org.jdbi.v3.core.Something in project jdbi by jdbi.
the class TestDocumentation method testMappingExampleChainedIterator2.
@Test
public void testMappingExampleChainedIterator2() throws Exception {
try (Handle h = dbRule.openHandle()) {
h.execute("insert into something (id, name) values (1, 'Brian')");
h.execute("insert into something (id, name) values (2, 'Keith')");
Iterator<String> rs = h.createQuery("select name from something order by id").mapTo(String.class).iterator();
assertThat(rs.next()).isEqualTo("Brian");
assertThat(rs.next()).isEqualTo("Keith");
assertThat(rs.hasNext()).isFalse();
}
}
use of org.jdbi.v3.core.Something in project jdbi by jdbi.
the class TestDocumentation method testFiveMinuteFluentApi.
@Test
public void testFiveMinuteFluentApi() throws Exception {
try (Handle h = dbRule.openHandle()) {
h.execute("insert into something (id, name) values (?, ?)", 1, "Brian");
String name = h.createQuery("select name from something where id = :id").bind("id", 1).mapTo(String.class).findOnly();
assertThat(name).isEqualTo("Brian");
}
}
use of org.jdbi.v3.core.Something in project jdbi by jdbi.
the class TestDocumentation method testFoo.
@Test
public void testFoo() throws Exception {
try (Handle h = dbRule.openHandle()) {
h.attach(BatchInserter.class).insert(new Something(1, "Brian"), new Something(3, "Patrick"), new Something(2, "Robert"));
QueryReturningResultIterable qrri = h.attach(QueryReturningResultIterable.class);
ResultIterable<String> iterable = qrri.findById(1);
assertThat(iterable.findOnly()).isEqualTo("Brian");
}
}
Aggregations