use of com.cadenzauk.siesta.model.PartRow in project siesta by cadenzauk.
the class EmbeddedTest method embeddedInWhereClause.
@Test
void embeddedInWhereClause() {
Database database = testDatabaseBuilder().defaultSchema("SIESTA").table(PartRow.class, t -> t.embedded(MoneyAmount.class, PartRow::purchasePrice, pp -> pp.columnName("PURCH_PRICE").column(MoneyAmount::amount, "PURCHASE_PRICE_AMT")).embedded(MoneyAmount.class, PartRow::retailPrice, rp -> rp.column(MoneyAmount::amount, "RETAIL_PRICE_AMT"))).build();
database.from(PartRow.class).select(Aggregates.countDistinct(column(PartRow::purchasePrice).dot(MoneyAmount::amount))).where(PartRow::purchasePrice).dot(MoneyAmount::currency).isEqualTo("USD").or(PartRow::retailPrice).dot(MoneyAmount::currency).isEqualTo("NZD").optional(sqlExecutor);
Mockito.verify(sqlExecutor).query(sql.capture(), args.capture(), any());
assertThat(sql.getValue(), is("select count(distinct PART.PURCHASE_PRICE_AMT) as count_PART_PURCHASE_PRICE_AMT " + "from SIESTA.PART PART where PART.PURCH_PRICE_CCY = ? or PART.RETAIL_PRICE_CCY = ?"));
assertThat(args.getValue(), is(toArray("USD", "NZD")));
}
use of com.cadenzauk.siesta.model.PartRow in project siesta by cadenzauk.
the class DatabaseIntegrationTestH2 method embeddedThatIsAllNullsComesBackEmpty.
@Test
void embeddedThatIsAllNullsComesBackEmpty() {
Database database = testDatabase(dataSource);
long partId = newId();
database.insert(PartRow.newBuilder().partId(partId).description("ABC").widgetId(3L).purchasePrice(null).retailPrice(Optional.empty()).build());
Tuple5<PartRow, MoneyAmount, MoneyAmount, String, String> result = database.from(PartRow.class).select(PartRow.class).comma(PartRow::purchasePrice, "pp").comma(PartRow::retailPrice, "rp").comma(column(PartRow::purchasePrice).dot(MoneyAmount::currency), "pc").comma(column(PartRow::retailPrice).dot(MoneyAmount::currency), "rc").where(PartRow::partId).isEqualTo(partId).single();
assertThat(result.item1().purchasePrice(), nullValue());
assertThat(result.item1().retailPrice(), is(Optional.empty()));
assertThat(result.item2(), nullValue());
assertThat(result.item3(), nullValue());
assertThat(result.item4(), nullValue());
assertThat(result.item5(), nullValue());
}
use of com.cadenzauk.siesta.model.PartRow in project siesta by cadenzauk.
the class DatabaseIntegrationTestH2 method embeddedInsertedAndReadBack.
@Test
void embeddedInsertedAndReadBack() {
Database database = testDatabase(dataSource);
long partId = newId();
MoneyAmount purchasePrice = new MoneyAmount(RandomValues.randomBigDecimal(10, 2), "USD");
MoneyAmount retailPrice = new MoneyAmount(RandomValues.randomBigDecimal(10, 2), "NZD");
database.insert(PartRow.newBuilder().partId(partId).description("ABC").widgetId(3L).purchasePrice(purchasePrice).retailPrice(Optional.of(retailPrice)).build());
Tuple5<PartRow, MoneyAmount, MoneyAmount, String, String> result = database.from(PartRow.class).select(PartRow.class).comma(PartRow::purchasePrice, "pp").comma(PartRow::retailPrice, "rp").comma(column(PartRow::purchasePrice).dot(MoneyAmount::currency), "pc").comma(column(PartRow::retailPrice).dot(MoneyAmount::currency), "rc").where(PartRow::partId).isEqualTo(partId).single();
assertThat(result.item1().purchasePrice(), is(purchasePrice));
assertThat(result.item1().retailPrice(), is(Optional.of(retailPrice)));
assertThat(result.item2(), is(purchasePrice));
assertThat(result.item3(), is(retailPrice));
assertThat(result.item4(), is("USD"));
assertThat(result.item5(), is("NZD"));
}
use of com.cadenzauk.siesta.model.PartRow in project siesta by cadenzauk.
the class EmbeddedTest method embeddedInProjection.
@Test
void embeddedInProjection() {
Database database = testDatabase(new AnsiDialect());
database.from(PartRow.class).select(PartRow::purchasePrice, "pp").comma(PartRow::retailPrice, "rp").comma(column(PartRow::purchasePrice).dot(MoneyAmount::currency), "pc").comma(column(PartRow::retailPrice).dot(MoneyAmount::currency), "rc").where(PartRow::partId).isEqualTo(4L).optional(sqlExecutor);
Mockito.verify(sqlExecutor).query(sql.capture(), args.capture(), any());
assertThat(sql.getValue(), is("select PART.PURCHASE_PRICE_AMOUNT as pp_PURCHASE_PRICE_AMOUNT, " + "PART.PURCHASE_PRICE_CCY as pp_PURCHASE_PRICE_CCY, " + "PART.RETAIL_PRICE_AMOUNT as rp_RETAIL_PRICE_AMOUNT, " + "PART.RETAIL_PRICE_CCY as rp_RETAIL_PRICE_CCY, " + "PART.PURCHASE_PRICE_CCY as pc, " + "PART.RETAIL_PRICE_CCY as rc " + "from SIESTA.PART PART " + "where PART.PART_ID = ?"));
assertThat(args.getValue(), is(toArray(4L)));
}
Aggregations