Search in sources :

Example 16 with Something

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"));
}
Also used : SomethingDao(org.jdbi.v3.sqlobject.subpackage.SomethingDao) Something(org.jdbi.v3.core.Something) Test(org.junit.Test)

Example 17 with Something

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"));
}
Also used : SomethingDao(org.jdbi.v3.sqlobject.subpackage.SomethingDao) BrokenDao(org.jdbi.v3.sqlobject.subpackage.BrokenDao) Something(org.jdbi.v3.core.Something) Handle(org.jdbi.v3.core.Handle) Test(org.junit.Test)

Example 18 with Something

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");
}
Also used : Something(org.jdbi.v3.core.Something) Test(org.junit.Test)

Example 19 with Something

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"));
}
Also used : Jdbi(org.jdbi.v3.core.Jdbi) SqlObjects(org.jdbi.v3.sqlobject.SqlObjects) Something(org.jdbi.v3.core.Something) Test(org.junit.Test)

Example 20 with Something

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();
}
Also used : Handle(org.jdbi.v3.core.Handle) Before(org.junit.Before)

Aggregations

Test (org.junit.Test)170 Something (org.jdbi.v3.core.Something)123 Handle (org.jdbi.v3.core.Handle)80 SomethingMapper (org.jdbi.v3.core.mapper.SomethingMapper)17 Before (org.junit.Before)11 ArrayList (java.util.ArrayList)6 Jdbi (org.jdbi.v3.core.Jdbi)6 HashMap (java.util.HashMap)5 Map (java.util.Map)5 GenericType (org.jdbi.v3.core.generic.GenericType)5 List (java.util.List)4 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)4 H2DatabaseRule (org.jdbi.v3.core.rule.H2DatabaseRule)4 Rule (org.junit.Rule)4 Connection (java.sql.Connection)3 LinkedHashMap (java.util.LinkedHashMap)3 Collector (java.util.stream.Collector)3 Collectors.toList (java.util.stream.Collectors.toList)3 JdbcDataSource (org.h2.jdbcx.JdbcDataSource)3 NoSuchMapperException (org.jdbi.v3.core.mapper.NoSuchMapperException)3