use of com.cadenzauk.siesta.model.WidgetRow in project siesta by cadenzauk.
the class SelectExpressionTest method isNotLikeEscape.
@Test
void isNotLikeEscape() {
Database database = testDatabase(new AnsiDialect());
String sql = database.from(WidgetRow.class).where(WidgetRow::name).isNotLike("abc+%%", "+").sql();
assertThat(sql, is("select WIDGET.WIDGET_ID as WIDGET_WIDGET_ID, " + "WIDGET.NAME as WIDGET_NAME, " + "WIDGET.MANUFACTURER_ID as WIDGET_MANUFACTURER_ID, " + "WIDGET.DESCRIPTION as WIDGET_DESCRIPTION " + "from SIESTA.WIDGET WIDGET " + "where WIDGET.NAME not like ? escape '+'"));
}
use of com.cadenzauk.siesta.model.WidgetRow in project siesta by cadenzauk.
the class SelectExpressionTest method isLike.
@Test
void isLike() {
Database database = testDatabase(new AnsiDialect());
String sql = database.from(WidgetRow.class).where(WidgetRow::name).isLike("abc%").sql();
assertThat(sql, is("select WIDGET.WIDGET_ID as WIDGET_WIDGET_ID, " + "WIDGET.NAME as WIDGET_NAME, " + "WIDGET.MANUFACTURER_ID as WIDGET_MANUFACTURER_ID, " + "WIDGET.DESCRIPTION as WIDGET_DESCRIPTION " + "from SIESTA.WIDGET WIDGET " + "where WIDGET.NAME like ?"));
}
use of com.cadenzauk.siesta.model.WidgetRow in project siesta by cadenzauk.
the class SelectGroupByTest method joinGroupBy.
@Test
void joinGroupBy() {
Database database = TestDatabase.testDatabase(new AnsiDialect());
database.from(WidgetRow.class, "w").leftJoin(ManufacturerRow.class, "m").on(ManufacturerRow::manufacturerId).isEqualTo(WidgetRow::manufacturerId).select(WidgetRow::manufacturerId, "id").comma(ManufacturerRow::name, "manufacturer").comma(max(WidgetRow::name), "name").where(WidgetRow::description).isLike("ABC%").groupBy(WidgetRow::manufacturerId).comma(ManufacturerRow::name).list(transaction);
verify(transaction).query(sql.capture(), args.capture(), rowMapper.capture());
assertThat(sql.getValue(), is("select w.MANUFACTURER_ID as id, m.NAME as manufacturer, max(w.NAME) as name " + "from SIESTA.WIDGET w " + "left join SIESTA.MANUFACTURER m on m.MANUFACTURER_ID = w.MANUFACTURER_ID " + "where w.DESCRIPTION like ? " + "group by w.MANUFACTURER_ID, m.NAME"));
assertThat(args.getValue(), arrayWithSize(1));
assertThat(args.getValue()[0], is("ABC%"));
}
use of com.cadenzauk.siesta.model.WidgetRow in project siesta by cadenzauk.
the class SelectGroupByTest method whereGroupByOrderBy.
@Test
void whereGroupByOrderBy() {
Database database = TestDatabase.testDatabase(new AnsiDialect());
database.from(WidgetRow.class, "w").select(WidgetRow::manufacturerId, "id").comma(max(WidgetRow::name), "name").where(WidgetRow::description).isLike("ABC%").groupBy(WidgetRow::manufacturerId).orderBy(WidgetRow::manufacturerId).then(max(WidgetRow::name)).list(transaction);
verify(transaction).query(sql.capture(), args.capture(), rowMapper.capture());
assertThat(sql.getValue(), is("select w.MANUFACTURER_ID as id, max(w.NAME) as name from SIESTA.WIDGET w " + "where w.DESCRIPTION like ? " + "group by w.MANUFACTURER_ID " + "order by w.MANUFACTURER_ID asc, max(w.NAME) asc"));
assertThat(args.getValue(), arrayWithSize(1));
assertThat(args.getValue()[0], is("ABC%"));
}
use of com.cadenzauk.siesta.model.WidgetRow in project siesta by cadenzauk.
the class SelectHavingTest method having.
@ParameterizedTest
@MethodSource("parametersForHaving")
void having(BiFunction<Alias<WidgetRow>, ExpectingHaving<Tuple3<Long, String, String>>, Select<Tuple3<Long, String, String>>> having, String expectedSql, Object[] expectedArgs) {
MockitoAnnotations.initMocks(this);
Database database = TestDatabase.testDatabase(new AnsiDialect());
Alias<WidgetRow> w = database.table(WidgetRow.class).as("w");
having.apply(w, database.from(w).select(WidgetRow::manufacturerId).comma(WidgetRow::description).comma(max(WidgetRow::name)).groupBy(WidgetRow::manufacturerId).comma(WidgetRow::description)).list(transaction);
verify(transaction).query(sql.capture(), args.capture(), rowMapper.capture());
assertThat(sql.getValue(), is("select w.MANUFACTURER_ID as w_MANUFACTURER_ID, w.DESCRIPTION as w_DESCRIPTION, max(w.NAME) as max_w_NAME " + "from SIESTA.WIDGET w " + "group by w.MANUFACTURER_ID, w.DESCRIPTION " + expectedSql));
assertThat(args.getValue(), is(expectedArgs));
}
Aggregations