use of org.jdbi.v3.core.Something in project jdbi by jdbi.
the class TestVavrValueArgumentFactoryWithDB method createTestData.
@Before
public void createTestData() {
Handle handle = dbRule.openHandle();
handle.createUpdate("insert into something (id, name) values (1, 'eric')").execute();
handle.createUpdate("insert into something (id, name) values (2, 'brian')").execute();
}
use of org.jdbi.v3.core.Something in project jdbi by jdbi.
the class TestOracleReturning method testReturningDmlNamedParams.
@Test
public void testReturningDmlNamedParams() {
Handle h = dbRule.getSharedHandle();
List<Integer> ids = h.createUpdate("insert into something(id, name) values (:id, :name) returning id into :result").bindBean(new Something(17, "Brian")).addCustomizer(returnParameters().register("result", OracleTypes.INTEGER)).execute(returningDml()).mapTo(int.class).list();
assertThat(ids).containsExactly(17);
}
use of org.jdbi.v3.core.Something in project jdbi by jdbi.
the class TestJdbiFactoryBean method testFailsViaException.
@Test
public void testFailsViaException() throws Exception {
assertThatExceptionOfType(ForceRollback.class).isThrownBy(() -> {
service.inPropagationRequired(jdbi -> {
Handle h = JdbiUtil.getHandle(jdbi);
final int count = h.execute("insert into something (id, name) values (7, 'ignored')");
if (count == 1) {
throw new ForceRollback();
} else {
throw new RuntimeException("!ZABAK");
}
});
});
try (final Handle h = Jdbi.open(ds)) {
int count = h.createQuery("select count(*) from something").mapTo(int.class).findOnly();
assertThat(count).isEqualTo(0);
}
}
use of org.jdbi.v3.core.Something in project jdbi by jdbi.
the class TestJdbiFactoryBean method testNested.
@Test
public void testNested() throws Exception {
assertThatExceptionOfType(ForceRollback.class).isThrownBy(() -> {
service.inPropagationRequired(outer -> {
final Handle h = JdbiUtil.getHandle(outer);
h.execute("insert into something (id, name) values (7, 'ignored')");
assertThatExceptionOfType(ForceRollback.class).isThrownBy(() -> {
service.inNested(inner -> {
final Handle h1 = JdbiUtil.getHandle(inner);
h1.execute("insert into something (id, name) values (8, 'ignored again')");
int count = h1.createQuery("select count(*) from something").mapTo(Integer.class).findOnly();
assertThat(count).isEqualTo(2);
throw new ForceRollback();
});
});
int count = h.createQuery("select count(*) from something").mapTo(Integer.class).findOnly();
assertThat(count).isEqualTo(1);
throw new ForceRollback();
});
});
service.inPropagationRequired(jdbi -> {
final Handle h = JdbiUtil.getHandle(jdbi);
int count = h.createQuery("select count(*) from something").mapTo(Integer.class).findOnly();
assertThat(count).isEqualTo(0);
});
}
use of org.jdbi.v3.core.Something in project jdbi by jdbi.
the class TestJdbiFactoryBean method testRequiresNew.
@Test
public void testRequiresNew() throws Exception {
service.inPropagationRequired(outer -> {
final Handle h = JdbiUtil.getHandle(outer);
h.execute("insert into something (id, name) values (7, 'ignored')");
assertThatExceptionOfType(ForceRollback.class).isThrownBy(() -> {
service.inRequiresNewReadUncommitted(inner -> {
final Handle h1 = JdbiUtil.getHandle(inner);
int count = h1.createQuery("select count(*) from something").mapTo(Integer.class).findOnly();
assertThat(count).isEqualTo(1);
h1.execute("insert into something (id, name) values (8, 'ignored again')");
throw new ForceRollback();
});
});
int count = h.createQuery("select count(*) from something").mapTo(Integer.class).findOnly();
assertThat(count).isEqualTo(1);
});
}
Aggregations