use of org.jdbi.v3.core.Something in project jdbi by jdbi.
the class TestSqlObject method testPassThroughMethodWithDaoInAnotherPackage.
@Test
public void testPassThroughMethodWithDaoInAnotherPackage() throws Exception {
SomethingDao dao = handle.attach(SomethingDao.class);
dao.insert(3, "Cora");
Something c = dao.findByIdHeeHee(3);
assertThat(c).isEqualTo(new Something(3, "Cora"));
}
use of org.jdbi.v3.core.Something in project jdbi by jdbi.
the class TestSqlObject method testSqlUpdateWithTransaction.
@Test
public void testSqlUpdateWithTransaction() {
Handle handle = Mockito.spy(dbRule.getSharedHandle());
Dao dao = handle.attach(Dao.class);
dao.insert(1, "foo");
verify(handle, never()).begin();
assertThat(dao.findById(1)).isEqualTo(new Something(1, "foo"));
assertThat(dao.insertTransactional(2, "bar")).isEqualTo(1);
verify(handle, times(1)).begin();
assertThat(dao.findById(2)).isEqualTo(new Something(2, "bar"));
}
use of org.jdbi.v3.core.Something in project jdbi by jdbi.
the class TestUseSqlParser method testFoo.
@Test
public void testFoo() throws Exception {
// test will raise exceptions if SQL is bogus -- if it uses the colon prefix form
Hashed h = handle.attach(Hashed.class);
h.insert(new Something(1, "Joy"));
Something s = h.findById(1);
assertThat(s.getName()).isEqualTo("Joy");
}
use of org.jdbi.v3.core.Something in project jdbi by jdbi.
the class TestSqlLocator method testLocateConfigDriven.
@Test
public void testLocateConfigDriven() {
Jdbi jdbi = dbRule.getJdbi();
jdbi.useHandle(h -> {
h.execute("create table something (id int, name text)");
h.execute("insert into something (id, name) values (?, ?)", 2, "Alice");
h.execute("insert into something (id, name) values (?, ?)", 1, "Bob");
});
jdbi.getConfig(SqlObjects.class).setSqlLocator((type, method, config) -> config.get(TestConfig.class).sql);
jdbi.getConfig(TestConfig.class).sql = "select * from something order by id";
assertThat(jdbi.withExtension(TestDao.class, TestDao::list)).containsExactly(new Something(1, "Bob"), new Something(2, "Alice"));
jdbi.getConfig(TestConfig.class).sql = "select * from something order by name";
assertThat(jdbi.withExtension(TestDao.class, TestDao::list)).containsExactly(new Something(2, "Alice"), new Something(1, "Bob"));
}
use of org.jdbi.v3.core.Something in project jdbi by jdbi.
the class TestVavrOptionMapperWithDB method addData.
@Before
public void addData() {
Handle handle = dbRule.openHandle();
handle.createUpdate("insert into something (id, name) values (1, 'eric')").execute();
handle.createUpdate("insert into something (id) values (2)").execute();
}
Aggregations