use of org.jdbi.v3.sqlobject.customizer.Bind in project jdbi by jdbi.
the class TestOracleReturning method testReturningDmlPositionalParams.
@Test
public void testReturningDmlPositionalParams() {
Handle h = dbRule.getSharedHandle();
List<Integer> ids = h.createUpdate("insert into something(id, name) values (?, ?) returning id into ?").bind(0, 17).bind(1, "Brian").addCustomizer(returnParameters().register(2, OracleTypes.INTEGER)).execute(returningDml()).mapTo(int.class).list();
assertThat(ids).containsExactly(17);
}
use of org.jdbi.v3.sqlobject.customizer.Bind in project jdbi by jdbi.
the class TestUpdateGeneratedKeys method testInsert.
@Test
public void testInsert() throws Exception {
Handle h = dbRule.openHandle();
Update insert1 = h.createUpdate("insert into something_else (name) values (:name)");
insert1.bind("name", "Brian");
Long id1 = insert1.executeAndReturnGeneratedKeys().mapTo(long.class).findOnly();
assertThat(id1).isNotNull();
Update insert2 = h.createUpdate("insert into something_else (name) values (:name)");
insert2.bind("name", "Tom");
Long id2 = insert2.executeAndReturnGeneratedKeys().mapTo(long.class).findOnly();
assertThat(id2).isNotNull();
assertThat(id2).isGreaterThan(id1);
}
use of org.jdbi.v3.sqlobject.customizer.Bind in project jdbi by jdbi.
the class TestGuavaOptional method testBindOptionalEmpty.
@Test
public void testBindOptionalEmpty() throws Exception {
List<Something> result = handle.createQuery(SELECT_BY_NAME).bind("name", Optional.absent()).mapToBean(Something.class).list();
assertThat(result).containsExactly(new Something(1, "eric"), new Something(2, "brian"));
}
use of org.jdbi.v3.sqlobject.customizer.Bind in project jdbi by jdbi.
the class BindFactory method createForParameter.
@Override
public SqlStatementParameterCustomizer createForParameter(Annotation annotation, Class<?> sqlObjectType, Method method, Parameter param, int index, Type type) {
Bind b = (Bind) annotation;
String nameFromAnnotation = b == null ? Bind.NO_VALUE : b.value();
Optional<String> name = ParameterUtil.findParameterName(nameFromAnnotation, param);
return (stmt, arg) -> {
stmt.bindByType(index, arg, type);
name.ifPresent(n -> stmt.bindByType(n, arg, type));
};
}
use of org.jdbi.v3.sqlobject.customizer.Bind in project jdbi by jdbi.
the class TestSqlCall method testFoo.
@Test
public void testFoo() throws Exception {
Dao dao = handle.attach(Dao.class);
// OutParameters out = handle.createCall(":num = call stored_insert(:id, :name)")
// .bind("id", 1)
// .bind("name", "Jeff")
// .registerOutParameter("num", Types.INTEGER)
// .invoke();
dao.insert(1, "Jeff");
assertThat(handle.attach(Dao.class).findById(1)).isEqualTo(new Something(1, "Jeff"));
}
Aggregations