use of com.cadenzauk.siesta.model.WidgetViewRow in project siesta by cadenzauk.
the class DatabaseIntegrationTest method selectIntoView.
@Test
void selectIntoView() {
Database database = testDatabase(dataSource, dialect);
long manufacturerId = newId();
ManufacturerRow aManufacturer = ManufacturerRow.newBuilder().manufacturerId(manufacturerId).name(Optional.of("Acme")).build();
WidgetRow aWidget = WidgetRow.newBuilder().widgetId(newId()).manufacturerId(manufacturerId).name("Gizmo").description(Optional.of("Acme's Patent Gizmo")).build();
database.insert(aManufacturer);
database.insert(aWidget);
Optional<WidgetViewRow> gizmo = database.from(WidgetRow.class, "w").leftJoin(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).where(WidgetRow::widgetId).isEqualTo(aWidget.widgetId()).optional();
assertThat(gizmo.map(WidgetViewRow::widgetName), is(Optional.of("Gizmo")));
assertThat(gizmo.flatMap(WidgetViewRow::manufacturerName), is(Optional.of("Acme")));
assertThat(gizmo.flatMap(WidgetViewRow::description), is(Optional.of("Acme's Patent Gizmo")));
}
use of com.cadenzauk.siesta.model.WidgetViewRow 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));
}
Aggregations