use of com.cadenzauk.siesta.dialect.AnsiDialect 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.dialect.AnsiDialect in project siesta by cadenzauk.
the class SelectGroupByTest method whereGroupBy.
@Test
void whereGroupBy() {
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).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"));
assertThat(args.getValue(), arrayWithSize(1));
assertThat(args.getValue()[0], is("ABC%"));
}
use of com.cadenzauk.siesta.dialect.AnsiDialect 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.dialect.AnsiDialect 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));
}
use of com.cadenzauk.siesta.dialect.AnsiDialect 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