use of com.cadenzauk.siesta.dialect.H2Dialect in project siesta by cadenzauk.
the class DatabaseIntegrationTest method commonTableExpression.
@Test
void commonTableExpression() {
assumeFalse(dialect instanceof H2Dialect, "H2 is buggy");
Database database = testDatabase(dataSource, dialect);
Tuple2<Long, Long> inserted = insertSalespeople(database, 10);
CommonTableExpression<SalespersonRow> first5 = database.with("first5").as(database.from(SalespersonRow.class).where(SalespersonRow::salespersonId).isBetween(inserted.item1()).and(inserted.item2()).orderBy(SalespersonRow::salespersonId).fetchFirst(5));
CommonTableExpression<SalespersonRow> last2 = database.with("last2").as(database.from(first5, "f5").orderBy(SalespersonRow::salespersonId, DESC).fetchFirst(2));
List<SalespersonRow> lastTwo = database.from(last2, "l2").list();
assertThat(lastTwo, hasSize(2));
assertThat(lastTwo.get(0).salespersonId(), is(inserted.item1() + 4));
assertThat(lastTwo.get(1).salespersonId(), is(inserted.item1() + 3));
}
Aggregations