Search in sources :

Example 51 with Something

use of org.jdbi.v3.core.Something in project jdbi by jdbi.

the class TestDefineListParameter method testWithBindList.

@Test
public void testWithBindList() throws Exception {
    TestDao testDao = handle.attach(TestDao.class);
    List<Object> values = new ArrayList<>();
    values.add(1);
    values.add("Some Pig");
    List<Object> valuesNull = new ArrayList<>();
    valuesNull.add(2);
    valuesNull.add(null);
    testDao.insert("test", testColumns, values);
    testDao.insert("testNullable", testColumns, valuesNull);
    Something something = new Something(1, "Some Pig");
    Something nothing = new Something(2, null);
    assertThat(testDao.findById(testColumns, "test", 1)).isEqualTo(something);
    assertThat(testDao.findById(testColumns, "testNullable", 1)).isNull();
    assertThat(testDao.findById(testColumns, "test", 2)).isNull();
    assertThat(testDao.findById(testColumns, "testNullable", 2)).isEqualTo(nothing);
}
Also used : ArrayList(java.util.ArrayList) Something(org.jdbi.v3.core.Something) Test(org.junit.Test)

Example 52 with Something

use of org.jdbi.v3.core.Something in project jdbi by jdbi.

the class TestDefineListParameter method testWithBindBean.

@Test
public void testWithBindBean() throws Exception {
    TestDao testDao = handle.attach(TestDao.class);
    Something something = new Something(1, "Some Pig");
    Something nothing = new Something(2, null);
    testDao.insert("test", testColumns, something);
    testDao.insert("testNullable", testColumns, nothing);
    assertThat(testDao.findById(testColumns, "test", 1)).isEqualTo(something);
    assertThat(testDao.findById(testColumns, "testNullable", 1)).isNull();
    assertThat(testDao.findById(testColumns, "test", 2)).isNull();
    assertThat(testDao.findById(testColumns, "testNullable", 2)).isEqualTo(nothing);
}
Also used : Something(org.jdbi.v3.core.Something) Test(org.junit.Test)

Example 53 with Something

use of org.jdbi.v3.core.Something in project jdbi by jdbi.

the class TestPaging method pagingExample.

@Test
public void pagingExample() throws Exception {
    Sql sql = handle.attach(Sql.class);
    int[] rs = sql.insert(asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13), asList("Ami", "Brian", "Cora", "David", "Eric", "Fernando", "Greta", "Holly", "Inigo", "Joy", "Keith", "Lisa", "Molly"));
    assertThat(rs).hasSize(13).containsOnly(1);
    List<Something> page_one = sql.loadPage(-1, 5);
    assertThat(page_one).containsExactly(new Something(1, "Ami"), new Something(2, "Brian"), new Something(3, "Cora"), new Something(4, "David"), new Something(5, "Eric"));
    List<Something> page_two = sql.loadPage(page_one.get(page_one.size() - 1).getId(), 5);
    assertThat(page_two).containsExactly(new Something(6, "Fernando"), new Something(7, "Greta"), new Something(8, "Holly"), new Something(9, "Inigo"), new Something(10, "Joy"));
}
Also used : Something(org.jdbi.v3.core.Something) Test(org.junit.Test)

Example 54 with Something

use of org.jdbi.v3.core.Something in project jdbi by jdbi.

the class TestReentrancy method testGetHandleProvidesSeperateHandle.

@Test(expected = UnableToCreateStatementException.class)
public void testGetHandleProvidesSeperateHandle() throws Exception {
    final TheBasics dao = db.onDemand(TheBasics.class);
    Handle h = dao.getHandle();
    h.execute("insert into something (id, name) values (1, 'Stephen')");
}
Also used : Handle(org.jdbi.v3.core.Handle) Test(org.junit.Test)

Example 55 with Something

use of org.jdbi.v3.core.Something in project jdbi by jdbi.

the class TestReentrancy method testHandleReentrant.

@Test
public void testHandleReentrant() throws Exception {
    final TheBasics dao = db.onDemand(TheBasics.class);
    dao.withHandle(handle1 -> {
        dao.insert(new Something(7, "Martin"));
        handle1.createQuery("SELECT 1").mapToMap().list();
        return null;
    });
}
Also used : Something(org.jdbi.v3.core.Something) Test(org.junit.Test)

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