use of com.cadenzauk.siesta.Transaction in project siesta by cadenzauk.
the class UpdateTest method update.
@Test
void update() {
Database database = Database.newBuilder().defaultSchema("SIESTA").table(WidgetRow.class, t -> t.builder(WidgetRow.Builder::build)).build();
database.update(WidgetRow.class, "w").set(WidgetRow::name).to("Fred").set(WidgetRow::description).to(Optional.of("Bob")).where(WidgetRow::widgetId).isEqualTo(1L).and(column(WidgetRow::description).isBetween("A").and("w", WidgetRow::name).or(column(WidgetRow::description).isNull())).execute(transaction);
verify(transaction).update(sql.capture(), args.capture());
assertThat(sql.getValue(), is("update SIESTA.WIDGET w " + "set NAME = ?, " + "DESCRIPTION = ? " + "where w.WIDGET_ID = ? " + "and (" + "w.DESCRIPTION between ? and w.NAME " + "or w.DESCRIPTION is null" + ")"));
assertThat(args.getValue(), is(toArray("Fred", "Bob", 1L, "A")));
}
Aggregations