use of org.jdbi.v3.core.Something in project jdbi by jdbi.
the class TestPositionalParameterBinding method testSetPositionalInteger.
@Test
public void testSetPositionalInteger() throws Exception {
h.execute("insert into something (id, name) values (1, 'eric')");
h.execute("insert into something (id, name) values (2, 'brian')");
Something eric = h.createQuery("select * from something where id = ?").bind(0, 1).mapToBean(Something.class).list().get(0);
assertThat(eric.getId()).isEqualTo(1);
}
use of org.jdbi.v3.core.Something in project jdbi by jdbi.
the class TestPreparedBatchGenerateKeys method testBatchInsertWithKeyGeneration.
@Test
public void testBatchInsertWithKeyGeneration() throws Exception {
Jdbi db = Jdbi.create("jdbc:hsqldb:mem:jdbi-batch-keys-test", "sa", "");
try (Handle h = db.open()) {
h.execute("create table something (id integer not null generated by default as identity (start with 10000), name varchar(50) )");
PreparedBatch batch = h.prepareBatch("insert into something (name) values (?)");
batch.add("Brian");
batch.add("Thom");
List<Integer> ids = batch.executeAndReturnGeneratedKeys().mapTo(int.class).list();
assertThat(ids).containsExactly(10000, 10001);
List<Something> somethings = h.createQuery("select id, name from something").mapToBean(Something.class).list();
assertThat(somethings).containsExactly(new Something(10000, "Brian"), new Something(10001, "Thom"));
}
}
use of org.jdbi.v3.core.Something in project jdbi by jdbi.
the class TestPreparedBatchGenerateKeysPostgres method testBatchInsertWithKeyGenerationAndExplicitColumnNames.
@Test
public void testBatchInsertWithKeyGenerationAndExplicitColumnNames() {
PreparedBatch batch = h.prepareBatch("insert into something (name) values (?) ");
batch.add("Brian");
batch.add("Thom");
List<Integer> ids = batch.executeAndReturnGeneratedKeys("id").mapTo(Integer.class).list();
assertThat(ids).containsExactly(1, 2);
List<Something> somethings = h.createQuery("select id, name from something").mapToBean(Something.class).list();
assertThat(somethings).containsExactly(new Something(1, "Brian"), new Something(2, "Thom"));
}
use of org.jdbi.v3.core.Something in project jdbi by jdbi.
the class TestQueries method testIteratedResult.
@Test
public void testIteratedResult() throws Exception {
h.execute("insert into something (id, name) values (1, 'eric')");
h.execute("insert into something (id, name) values (2, 'brian')");
try (ResultIterator<Something> i = h.createQuery("select * from something order by id").mapToBean(Something.class).iterator()) {
assertThat(i.hasNext()).isTrue();
Something first = i.next();
assertThat(first.getName()).isEqualTo("eric");
assertThat(i.hasNext()).isTrue();
Something second = i.next();
assertThat(second.getId()).isEqualTo(2);
assertThat(i.hasNext()).isFalse();
}
}
use of org.jdbi.v3.core.Something in project jdbi by jdbi.
the class TestQueries method testMappedQueryObjectWithNulls.
@Test
public void testMappedQueryObjectWithNulls() throws Exception {
h.execute("insert into something (id, name, integerValue) values (1, 'eric', null)");
ResultIterable<Something> query = h.createQuery("select * from something order by id").mapToBean(Something.class);
List<Something> r = query.list();
Something eric = r.get(0);
assertThat(eric).isEqualTo(new Something(1, "eric"));
assertThat(eric.getIntegerValue()).isNull();
}
Aggregations