Search in sources :

Example 1 with H2Dialect

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));
}
Also used : H2Dialect(com.cadenzauk.siesta.dialect.H2Dialect) TestDatabase.testDatabase(com.cadenzauk.siesta.model.TestDatabase.testDatabase) SalespersonRow(com.cadenzauk.siesta.model.SalespersonRow) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

H2Dialect (com.cadenzauk.siesta.dialect.H2Dialect)1 SalespersonRow (com.cadenzauk.siesta.model.SalespersonRow)1 TestDatabase.testDatabase (com.cadenzauk.siesta.model.TestDatabase.testDatabase)1 Test (org.junit.jupiter.api.Test)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1