use of com.cadenzauk.siesta.model.ManufacturerId in project siesta by cadenzauk.
the class SiestaExample method typeSafeIdExample.
@Test
void typeSafeIdExample() {
Database database = Database.newBuilder().defaultSqlExecutor(JdbcSqlExecutor.of(dataSource)).table(Widget.class, t -> t.column(Widget::description, "WIDGET_DESC")).adapter(WidgetId.class, DbTypeId.BIGINT, WidgetId::id, WidgetId::new).adapter(ManufacturerId.class, DbTypeId.BIGINT, ManufacturerId::id, ManufacturerId::new).build();
WidgetId widgetId = new WidgetId(newId());
ManufacturerId manufacturerId = new ManufacturerId(newId());
WidgetRowWithTypeSafeId widget = WidgetRowWithTypeSafeId.newBuilder().widgetId(widgetId).manufacturerId(manufacturerId).name("Safety Gadget").build();
database.insert(widget);
WidgetRowWithTypeSafeId result = database.from(WidgetRowWithTypeSafeId.class).where(WidgetRowWithTypeSafeId::widgetId).isEqualTo(widgetId).or(WidgetRowWithTypeSafeId::manufacturerId).isEqualTo(literal(manufacturerId)).single();
MatcherAssert.assertThat(result.name(), is("Safety Gadget"));
}
Aggregations