@Test public void testHandleReadOnly() throws Exception { try (Handle h = db.openHandle()) { assertThat(h.isReadOnly()).isFalse(); assertThat(h.getConnection().isReadOnly()).isFalse(); h.setReadOnly(true); assertThat(h.isReadOnly()).isTrue(); assertThat(h.getConnection().isReadOnly()).isTrue(); } }
@Before public void getHandle() { db = dbRule.getJdbi(); }
@Before public void setUp() { dbRule.getJdbi() .registerArrayType(Integer.class, "integer") .registerArrayType(UUID.class, "uuid"); h = dbRule.openHandle(); h.useTransaction(th -> { th.execute("DROP TABLE IF EXISTS arrays"); th.execute("CREATE TABLE arrays (u UUID[], i INT[])"); }); }
@Before public void setUp() { dbRule.getJdbi() .registerArrayType(Integer.class, "integer") .registerArrayType(UUID.class, "uuid"); h = dbRule.openHandle(); h.useTransaction(th -> { th.execute("DROP TABLE IF EXISTS arrays"); th.execute("CREATE TABLE arrays (u UUID[], i INT[])"); }); }
@Test public void testBindTypeErased() { try (Handle h = db.openHandle()) { assertThatThrownBy(() -> h.execute("SELECT * FROM something WHERE id = ANY(:ids)", Collections.singleton(1))) .isInstanceOf(UnsupportedOperationException.class) .hasMessageContaining("No type parameters found"); } } }
public Handle openHandle() { return getJdbi().open(); }
@Test public void testSqlObjectReadOnly() throws Exception { try (Handle h = db.openHandle()) { RODao dao = h.attach(RODao.class); assertThat(h.isReadOnly()).isFalse(); assertThat(dao.verifyReadOnly()).isTrue(); assertThat(h.isReadOnly()).isFalse(); } }
@Before public void getHandle() { h = dbRule.getJdbi().open(); }
@Test public void testReadOnlyOuter() { try (Handle h = db.openHandle()) { RODao dao = h.attach(RODao.class); assertThatThrownBy(() -> dao.readTxn(() -> dao.writeTxn(() -> {}))).isInstanceOf(TransactionException.class); } }
@Test public void testTransactions() { Dao dao = dbRule.getJdbi().onDemand(Dao.class); Something s = dao.insertAndFetch(1, "Brian"); assertThat(s).isEqualTo(new Something(1, "Brian")); }
@Before public void setup() { h = dbRule.openHandle(); h.execute("create extension if not exists \"hstore\""); h.execute("create table mappy (numbers hstore not null)"); }
@Test public void testUseRowMapperUpdate() { dbRule.getJdbi().useExtension(UseRowMapperDao.class, dao -> { dao.createTable(); IdCreateTime result = dao.insert("foo"); assertThat(result.id).isEqualTo(1); assertThat(result.createdOn).isNotNull(); }); }
@Before public void setUp() { handle = dbRule.openHandle(); handle.execute("create table something (id serial primary key, value jsonb)"); kvs = handle.attach(KeyValueStore.class); }
@Test public void testRegisterRowMapperUpdate() { dbRule.getJdbi().useExtension(RegisterRowMapperDao.class, dao -> { dao.createTable(); IdCreateTime result = dao.insert("foo"); assertThat(result.id).isEqualTo(1); assertThat(result.createdOn).isNotNull(); }); }
@Before public void setUp() { handle = dbRule.openHandle(); handle.execute("create table something (id serial primary key, name varchar)"); b = handle.attach(UsesBatching.class); }
@Test public void testBatch() { dbRule.getJdbi().useExtension(DAO.class, dao -> { dao.createSequence(); dao.createTable(); int[] ids = dao.insert(Arrays.asList("Burt", "Macklin")); assertThat(dao.findNameById(ids[0])).isEqualTo("Burt"); assertThat(dao.findNameById(ids[1])).isEqualTo("Macklin"); }); }
@Test public void testReadOnlyInner() { try (Handle h = db.openHandle()) { RODao dao = h.attach(RODao.class); dao.writeTxn(() -> dao.readTxn(() -> {})); } }
@Test public void testConnected() { int four = dbRule.getJdbi().withHandle(handle -> handle.createQuery("select 2 + 2").mapTo(Integer.class).findOnly()); assertThat(four).isEqualTo(4); }
@Before public void init() { handle = dbRule.openHandle(); handle.execute("create table something (id int primary key, name varchar(100))"); handle.execute("insert into something(id, name) values(1, null)"); handle.execute("insert into something(id, name) values(2, 'bla')"); handle.execute("insert into something(id, name) values(3, 'null')"); handle.execute("insert into something(id, name) values(4, '')"); }
@Before public void createTable() { dbRule.getJdbi().useHandle(h -> h.execute("create table something (id int primary key, name varchar(50), integerValue integer, intValue integer)")); }