@Override public Object invoke(HandleDing h, Object target, Object[] args, MethodProxy mp) { h.retain("transaction#explicit"); h.getHandle().begin(); return null; } }
public Object invoke(HandleDing h, Object target, Object[] args, MethodProxy mp) { h.retain("transaction#explicit"); h.getHandle().begin(); return null; } }
private void withTransaction(Consumer<Handle> cb) { try (Handle h = dbi.open()) { try { h.begin(); cb.accept(h); h.commit(); } catch (@SuppressWarnings("PMD.AvoidCatchingGenericException")RuntimeException e) { h.rollback(); throw e; } } }
private void withTransaction(Consumer<Handle> cb) { try (final Handle h = dbi.open()) { try { h.begin(); cb.accept(h); h.commit(); } catch (@SuppressWarnings("PMD.AvoidCatchingGenericException")RuntimeException e) { h.rollback(); throw e; } } }
@Override public ParamServerClientConnection getConnection() { Handle handle = dbi.open(); try { handle.getConnection().setAutoCommit(false); } catch (SQLException ex) { throw new TransactionFailedException("Failed to set auto commit: " + false, ex); } handle.begin(); return new PostgresqlServerClientConnection(handle); }
@Test public void testLogRollback() throws Exception { h.begin(); h.rollback(); assertTrue(logged.contains("rollback")); }
@Test public void testLogBegin() throws Exception { h.begin(); assertTrue(logged.contains("begin")); h.commit(); }
@Test public void testLogRollback() throws Exception { h.begin(); h.rollback(); assertTrue(logged.contains("rollback")); }
@Test public void testLogCommit() throws Exception { h.begin(); h.commit(); assertTrue(logged.contains("commit")); }
@Test public void testLogBegin() throws Exception { h.begin(); assertTrue(logged.contains("begin")); h.commit(); }
public void lock(final String personalityName) { transactionHandle = migratoryContext.getDBI().open(); transactionHandle.begin(); if (METADATA_MIGRATION_NAME.equals(personalityName)) { // Can't lock the actual metadata migration, because the table might not exist yet. return; } if (migratoryContext.getDbSupport().supportsLocking()) { transactionHandle.createStatement(METADATA_PREFIX + "lock") .bind("personality_name", personalityName) .execute(); } }
@Test public void testLogCommit() throws Exception { h.begin(); h.commit(); assertTrue(logged.contains("commit")); }
// TODO: add try/catch/finally to close things properly DBI dbi = new DBI("jdbc:h2:mem:test"); Handle h = dbi.open(); h.begin(); Dao1 dao1 = h.attach(Dao1.class); Dao2 dao2 = h.attach(Dao2.class); dao1.save(myBean1); dao2.save(myBean2); h.commit(); h.close();
@Test public void testCheckpoint() throws Exception { h.begin(); h.checkpoint("a"); assertTrue(logged.contains("checkpoint a created")); h.rollback("a"); assertTrue(logged.contains("checkpoint a rolled back to")); h.checkpoint("b"); assertTrue(logged.contains("checkpoint b created")); h.release("b"); assertTrue(logged.contains("checkpoint b released")); h.commit(); } }
@Test public void testCheckpoint() throws Exception { Handle h = openHandle(); h.begin(); h.insert("insert into something (id, name) values (:id, :name)", 1, "Tom"); h.checkpoint("first"); h.insert("insert into something (id, name) values (:id, :name)", 1, "Martin"); assertEquals(Integer.valueOf(2), h.createQuery("select count(*) from something").mapTo(Integer.class).first()); h.rollback("first"); assertEquals(Integer.valueOf(1), h.createQuery("select count(*) from something").mapTo(Integer.class).first()); h.commit(); assertEquals(Integer.valueOf(1), h.createQuery("select count(*) from something").mapTo(Integer.class).first()); }
@Test public void testCheckpoint() throws Exception { Handle h = openHandle(); h.begin(); h.insert("insert into something (id, name) values (:id, :name)", 1, "Tom"); h.checkpoint("first"); h.insert("insert into something (id, name) values (:id, :name)", 1, "Martin"); assertEquals(Integer.valueOf(2), h.createQuery("select count(*) from something").map(new IntegerMapper()).first()); h.rollback("first"); assertEquals(Integer.valueOf(1), h.createQuery("select count(*) from something").map(new IntegerMapper()).first()); h.commit(); assertEquals(Integer.valueOf(1), h.createQuery("select count(*) from something").map(new IntegerMapper()).first()); }
@Test public void testJustJdbiTransactions() throws Exception { Handle h1 = dbi.open(); Handle h2 = dbi.open(); h1.execute("insert into something (id, name) values (8, 'Mike')"); h1.begin(); h1.execute("update something set name = 'Miker' where id = 8"); assertEquals("Mike", h2.createQuery("select name from something where id = 8").mapTo(String.class).first()); h1.commit(); h1.close(); h2.close(); }
@Test public void testJustJdbiTransactions() throws Exception { Handle h1 = dbi.open(); Handle h2 = dbi.open(); h1.execute("insert into something (id, name) values (8, 'Mike')"); h1.begin(); h1.execute("update something set name = 'Miker' where id = 8"); assertEquals("Mike", h2.createQuery("select name from something where id = 8").map(StringMapper.FIRST).first()); h1.commit(); h1.close(); h2.close(); }