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);
}
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);
}
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"));
}
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')");
}
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;
});
}
Aggregations