use of com.cadenzauk.siesta.model.WidgetRow in project siesta by cadenzauk.
the class SelectProjectionTest method projectIntoObject.
@Test
void projectIntoObject() {
Database database = TestDatabase.testDatabase(new AnsiDialect());
database.from(WidgetRow.class, "w").join(ManufacturerRow.class, "m").on(ManufacturerRow::manufacturerId).isEqualTo(WidgetRow::manufacturerId).selectInto(WidgetViewRow.class, "v").with(WidgetRow::widgetId).as(WidgetViewRow::widgetId).with(WidgetRow::name).as(WidgetViewRow::widgetName).with(WidgetRow::description).as(WidgetViewRow::description).with(WidgetRow::manufacturerId).as(WidgetViewRow::manufacturerId).with(ManufacturerRow::name).as(WidgetViewRow::manufacturerName).list(transaction);
verify(transaction).query(sql.capture(), args.capture(), rowMapper.capture());
assertThat(sql.getValue(), is("select w.WIDGET_ID as v_WIDGET_ID, " + "w.NAME as v_WIDGET_NAME, " + "w.DESCRIPTION as v_DESCRIPTION, " + "w.MANUFACTURER_ID as v_MANUFACTURER_ID, " + "m.NAME as v_MANUFACTURER_NAME " + "from SIESTA.WIDGET w " + "join SIESTA.MANUFACTURER m on m.MANUFACTURER_ID = w.MANUFACTURER_ID"));
assertThat(args.getValue(), arrayWithSize(0));
}
use of com.cadenzauk.siesta.model.WidgetRow in project siesta by cadenzauk.
the class SelectProjectionTest method projectColumns.
@Test
void projectColumns() {
Database database = TestDatabase.testDatabase(new AnsiDialect());
Alias<WidgetRow> w = database.table(WidgetRow.class).as("w");
database.from(w).select(WidgetRow::name, "n1").comma(WidgetRow::description, "d1").comma(WidgetRow::manufacturerId, "m1").comma("w", WidgetRow::name, "n2").comma("w", WidgetRow::description, "d2").comma("w", WidgetRow::manufacturerId, "m2").comma(w, WidgetRow::name, "n3").comma(w, WidgetRow::description, "d3").comma(w, WidgetRow::manufacturerId, "m3").where(WidgetRow::name).isEqualTo("Bob").list(transaction);
verify(transaction).query(sql.capture(), args.capture(), rowMapper.capture());
assertThat(sql.getValue(), is("select " + "w.NAME as n1, w.DESCRIPTION as d1, w.MANUFACTURER_ID as m1, " + "w.NAME as n2, w.DESCRIPTION as d2, w.MANUFACTURER_ID as m2, " + "w.NAME as n3, w.DESCRIPTION as d3, w.MANUFACTURER_ID as m3 " + "from SIESTA.WIDGET w " + "where w.NAME = ?"));
assertThat(args.getValue(), arrayWithSize(1));
assertThat(args.getValue()[0], is("Bob"));
}
Aggregations