Search in sources :

Example 1 with ManufacturerId

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"));
}
Also used : Tuple2(com.cadenzauk.core.tuple.Tuple2) Tuple3(com.cadenzauk.core.tuple.Tuple3) WidgetRowWithTypeSafeId(com.cadenzauk.siesta.model.WidgetRowWithTypeSafeId) ManufacturerId(com.cadenzauk.siesta.model.ManufacturerId) ZonedDateTime(java.time.ZonedDateTime) TypedExpression.literal(com.cadenzauk.siesta.grammar.expression.TypedExpression.literal) DateFunctions.currentDate(com.cadenzauk.siesta.grammar.expression.DateFunctions.currentDate) CompositeAutoCloseable(com.cadenzauk.core.lang.CompositeAutoCloseable) Test(org.junit.jupiter.api.Test) Assert.assertThat(org.junit.Assert.assertThat) List(java.util.List) MatcherAssert(org.hamcrest.MatcherAssert) IntegrationTest(com.cadenzauk.siesta.IntegrationTest) LocalDate(java.time.LocalDate) Optional(java.util.Optional) Matchers.hasSize(org.hamcrest.Matchers.hasSize) WidgetId(com.cadenzauk.siesta.model.WidgetId) Matchers.is(org.hamcrest.Matchers.is) JdbcSqlExecutor(com.cadenzauk.siesta.jdbc.JdbcSqlExecutor) ZoneOffset(java.time.ZoneOffset) DateFunctions.currentTimestamp(com.cadenzauk.siesta.grammar.expression.DateFunctions.currentTimestamp) DbTypeId(com.cadenzauk.siesta.type.DbTypeId) Aggregates.countDistinct(com.cadenzauk.siesta.grammar.expression.Aggregates.countDistinct) Database(com.cadenzauk.siesta.Database) ManufacturerId(com.cadenzauk.siesta.model.ManufacturerId) Database(com.cadenzauk.siesta.Database) WidgetId(com.cadenzauk.siesta.model.WidgetId) WidgetRowWithTypeSafeId(com.cadenzauk.siesta.model.WidgetRowWithTypeSafeId) Test(org.junit.jupiter.api.Test) IntegrationTest(com.cadenzauk.siesta.IntegrationTest)

Aggregations

CompositeAutoCloseable (com.cadenzauk.core.lang.CompositeAutoCloseable)1 Tuple2 (com.cadenzauk.core.tuple.Tuple2)1 Tuple3 (com.cadenzauk.core.tuple.Tuple3)1 Database (com.cadenzauk.siesta.Database)1 IntegrationTest (com.cadenzauk.siesta.IntegrationTest)1 Aggregates.countDistinct (com.cadenzauk.siesta.grammar.expression.Aggregates.countDistinct)1 DateFunctions.currentDate (com.cadenzauk.siesta.grammar.expression.DateFunctions.currentDate)1 DateFunctions.currentTimestamp (com.cadenzauk.siesta.grammar.expression.DateFunctions.currentTimestamp)1 TypedExpression.literal (com.cadenzauk.siesta.grammar.expression.TypedExpression.literal)1 JdbcSqlExecutor (com.cadenzauk.siesta.jdbc.JdbcSqlExecutor)1 ManufacturerId (com.cadenzauk.siesta.model.ManufacturerId)1 WidgetId (com.cadenzauk.siesta.model.WidgetId)1 WidgetRowWithTypeSafeId (com.cadenzauk.siesta.model.WidgetRowWithTypeSafeId)1 DbTypeId (com.cadenzauk.siesta.type.DbTypeId)1 LocalDate (java.time.LocalDate)1 ZoneOffset (java.time.ZoneOffset)1 ZonedDateTime (java.time.ZonedDateTime)1 List (java.util.List)1 Optional (java.util.Optional)1 MatcherAssert (org.hamcrest.MatcherAssert)1