@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(); } }
@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"); } } }
@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(); } }
@Test public void testReadOnlyOuter() { try (Handle h = db.openHandle()) { RODao dao = h.attach(RODao.class); assertThatThrownBy(() -> dao.readTxn(() -> dao.writeTxn(() -> {}))).isInstanceOf(TransactionException.class); } }
@Before public void setup() { h = dbRule.openHandle(); h.execute("create extension if not exists \"hstore\""); h.execute("create table mappy (numbers hstore not null)"); }
@Before public void setUp() { handle = dbRule.openHandle(); handle.execute("create table something (id serial primary key, value jsonb)"); kvs = handle.attach(KeyValueStore.class); }
@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 testReadOnlyInner() { try (Handle h = db.openHandle()) { RODao dao = h.attach(RODao.class); dao.writeTxn(() -> dao.readTxn(() -> {})); } }
@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 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 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 testPreparedBatch() { PreparedBatch b = dbRule.openHandle().prepareBatch("insert into something (id, name) values (?,?)"); b.add(0, "a"); b.add(0, "a"); assertThatExceptionOfType(UnableToExecuteStatementException.class) .isThrownBy(b::execute) .satisfies(e -> assertSuppressions(e.getCause())); }
@Test public void testSimpleBatch() { Batch b = dbRule.openHandle().createBatch(); b.add("insert into something (id, name) values (0, 'Keith')"); b.add("insert into something (id, name) values (0, 'Keith')"); assertThatExceptionOfType(UnableToExecuteStatementException.class) .isThrownBy(b::execute) .satisfies(e -> assertSuppressions(e.getCause())); }
@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(); } }
@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(); } }
@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 testReadOnlyInner() { try (Handle h = db.openHandle()) { RODao dao = h.attach(RODao.class); dao.writeTxn(() -> dao.readTxn(() -> {})); } }
@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[])"); }); }