use of org.jdbi.v3.sqlobject.customizer.Bind in project jdbi by jdbi.
the class TestPositionalParameterBinding method testSetPositionalInteger.
@Test
public void testSetPositionalInteger() throws Exception {
h.execute("insert into something (id, name) values (1, 'eric')");
h.execute("insert into something (id, name) values (2, 'brian')");
Something eric = h.createQuery("select * from something where id = ?").bind(0, 1).mapToBean(Something.class).list().get(0);
assertThat(eric.getId()).isEqualTo(1);
}
use of org.jdbi.v3.sqlobject.customizer.Bind in project jdbi by jdbi.
the class CallTest method testCall.
@Test
public void testCall() {
Handle handle = db.getHandle();
handle.execute(findSqlOnClasspath("create_stored_proc_add"));
// tag::invokeProcedure[]
OutParameters result = handle.createCall(// <1>
"{:sum = call add(:a, :b)}").bind("a", // <2>
13).bind("b", // <2>
9).registerOutParameter("sum", // <3> <4>
Types.INTEGER).invoke();
// end::invokeProcedure[]
// tag::getOutParameters[]
int sum = result.getInt("sum");
// end::getOutParameters[]
assertThat(sum).isEqualTo(22);
}
use of org.jdbi.v3.sqlobject.customizer.Bind in project jdbi by jdbi.
the class TestGuavaOptional method testBindOptionalOfCustomType.
@Test
public void testBindOptionalOfCustomType() throws Exception {
handle.registerArgument(new NameArgumentFactory());
List<Something> result = handle.createQuery(SELECT_BY_NAME).bind("name", Optional.of(new Name("eric"))).mapToBean(Something.class).list();
assertThat(result).containsExactly(new Something(1, "eric"));
}
use of org.jdbi.v3.sqlobject.customizer.Bind in project jdbi by jdbi.
the class TestGuavaOptional method testBindOptionalPresent.
@Test
public void testBindOptionalPresent() throws Exception {
Something result = handle.createQuery(SELECT_BY_NAME).bind("name", Optional.of("brian")).mapToBean(Something.class).findOnly();
assertThat(result).isEqualTo(new Something(2, "brian"));
}
use of org.jdbi.v3.sqlobject.customizer.Bind in project jdbi by jdbi.
the class StatementsTest method testBatch.
@Test
public void testBatch() throws Exception {
// tag::batch[]
PreparedBatch batch = handle.prepareBatch("INSERT INTO user(id, name) VALUES(:id, :name)");
for (int i = 100; i < 5000; i++) {
batch.bind("id", i).bind("name", "User:" + i).add();
}
int[] counts = batch.execute();
// end::batch[]
int[] expected = new int[4900];
Arrays.fill(expected, 1);
assertThat(counts).isEqualTo(expected);
}
Aggregations