use of org.jdbi.v3.core.Handle in project jdbi by jdbi.
the class TestTooManyCursors method testFoo.
@Test
public void testFoo() throws Exception {
ConnectionFactory cf = dbRule.getConnectionFactory();
ConnectionFactory errorCf = new ErrorProducingConnectionFactory(cf, 99);
Jdbi db = Jdbi.create(errorCf);
db.useHandle(handle -> {
handle.setStatementBuilder(new DefaultStatementBuilder());
for (int idx = 0; idx < 100; idx++) {
handle.createQuery("SELECT " + idx + " FROM something").mapTo(int.class).findFirst();
}
});
}
use of org.jdbi.v3.core.Handle in project jdbi by jdbi.
the class TestArgumentFactory method testOnPreparedBatch.
@Test
public void testOnPreparedBatch() throws Exception {
Handle h = dbRule.getSharedHandle();
PreparedBatch batch = h.prepareBatch("insert into something (id, name) values (:id, :name)");
batch.registerArgument(new NameAF());
batch.bind("id", 1).bind("name", new Name("Brian", "McCallister")).add();
batch.bind("id", 2).bind("name", new Name("Henning", "S")).add();
batch.execute();
List<String> rs = h.createQuery("select name from something order by id").mapTo(String.class).list();
assertThat(rs.get(0)).isEqualTo("Brian McCallister");
assertThat(rs.get(1)).isEqualTo("Henning S");
}
use of org.jdbi.v3.core.Handle in project jdbi by jdbi.
the class TestTransactional method setUp.
@Before
public void setUp() throws Exception {
final JdbcDataSource ds = new JdbcDataSource() {
private static final long serialVersionUID = 1L;
@Override
public Connection getConnection() throws SQLException {
final Connection real = super.getConnection();
return (Connection) Proxy.newProxyInstance(real.getClass().getClassLoader(), new Class<?>[] { Connection.class }, new TxnIsolationCheckingInvocationHandler(real));
}
};
// in MVCC mode h2 doesn't shut down immediately on all connections closed, so need random db name
ds.setURL(String.format("jdbc:h2:mem:%s;MVCC=TRUE", UUID.randomUUID()));
db = Jdbi.create(ds);
db.installPlugin(new SqlObjectPlugin());
db.registerRowMapper(new SomethingMapper());
handle = db.open();
handle.execute("create table something (id int primary key, name varchar(100))");
}
use of org.jdbi.v3.core.Handle in project jdbi by jdbi.
the class TestRegisterJoinRowMapper method testSqlObjectJoinRow.
@Test
public void testSqlObjectJoinRow() {
Handle handle = dbRule.getSharedHandle();
// tag::joinrowusage[]
Multimap<User, Article> joined = HashMultimap.create();
handle.attach(UserArticleDao.class).getAuthorship().forEach(jr -> joined.put(jr.get(User.class), jr.get(Article.class)));
assertThat(joined).isEqualTo(JoinRowMapperTest.getExpected());
// end::joinrowusage[]
}
use of org.jdbi.v3.core.Handle in project jdbi by jdbi.
the class TestRegisteredMappersWork method testNoRootRegistrations.
@Test(expected = NoSuchMapperException.class)
public void testNoRootRegistrations() throws Exception {
try (Handle h = dbRule.openHandle()) {
h.execute("insert into something (id, name) values (1, 'Henning')");
h.createQuery("select id, name from something where id = 1").mapTo(Something.class).findFirst();
}
}
Aggregations