use of org.jdbi.v3.core.Something 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.Something 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.Something in project jdbi by jdbi.
the class TestTransactionAnnotation method testTx.
@Test
public void testTx() throws Exception {
Dao dao = handle.attach(Dao.class);
Something s = dao.insertAndFetch(1, "Ian");
assertThat(s).isEqualTo(new Something(1, "Ian"));
}
use of org.jdbi.v3.core.Something in project jdbi by jdbi.
the class TestTransactional method testDoublyTransactional.
@Test
public void testDoublyTransactional() throws Exception {
final TheBasics dao = db.onDemand(TheBasics.class);
dao.inTransaction(TransactionIsolationLevel.SERIALIZABLE, transactional -> {
transactional.insert(new Something(1, "2"));
inTransaction.set(true);
transactional.insert(new Something(2, "3"));
inTransaction.set(false);
return null;
});
}
use of org.jdbi.v3.core.Something 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))");
}
Aggregations