Search in sources :

Example 6 with AnsiDialect

use of com.cadenzauk.siesta.dialect.AnsiDialect in project siesta by cadenzauk.

the class FromTest method validateInvalidThrowsWhenWrongAlias.

@Test
void validateInvalidThrowsWhenWrongAlias() {
    Database database = testDatabase(new AnsiDialect());
    calling(() -> database.from(ManufacturerRow.class, "m1").join(ManufacturerRow.class, "m2").on("m1", ManufacturerRow::name).isEqualTo("Fred").sql()).shouldThrow(InvalidJoinException.class).withMessage(is("Joined table 'SIESTA.MANUFACTURER m2' is not referenced in the ON clause."));
}
Also used : AnsiDialect(com.cadenzauk.siesta.dialect.AnsiDialect) ManufacturerRow(com.cadenzauk.siesta.model.ManufacturerRow) TestDatabase.testDatabase(com.cadenzauk.siesta.model.TestDatabase.testDatabase) InvalidJoinException(com.cadenzauk.siesta.grammar.InvalidJoinException) Test(org.junit.jupiter.api.Test)

Example 7 with AnsiDialect

use of com.cadenzauk.siesta.dialect.AnsiDialect in project siesta by cadenzauk.

the class FromTest method invalidJoinCanBeSuppressed.

@Test
void invalidJoinCanBeSuppressed() {
    Database database = testDatabase(new AnsiDialect());
    String sql = database.from(ManufacturerRow.class, "m1").join(ManufacturerRow.class, "m2").validate(false).on("m1", ManufacturerRow::name).isEqualTo("Fred").sql();
    assertThat(sql, startsWith("select m1.MANUFACTURER_ID as m1_MANUFACTURER_ID"));
}
Also used : AnsiDialect(com.cadenzauk.siesta.dialect.AnsiDialect) ManufacturerRow(com.cadenzauk.siesta.model.ManufacturerRow) TestDatabase.testDatabase(com.cadenzauk.siesta.model.TestDatabase.testDatabase) Test(org.junit.jupiter.api.Test)

Example 8 with AnsiDialect

use of com.cadenzauk.siesta.dialect.AnsiDialect in project siesta by cadenzauk.

the class OlapFunctionTest method addPartitionByAndParitionBy.

@ParameterizedTest(name = "{index}: {1}")
@MethodSource("parametersForRowNumber")
void addPartitionByAndParitionBy(BiFunction<InOlapExpectingPartitionBy<Integer>, Alias<SalespersonRow>, TypedExpression<Integer>> f, String expected, Object[] expectedArgs) {
    Database database = testDatabase(new AnsiDialect());
    Alias<SalespersonRow> s = database.table(SalespersonRow.class).as("s");
    database.from(s).select(f.apply(Olap.rowNumber(), s)).list(transaction);
    verify(transaction).query(sql.capture(), args.capture(), any());
    assertThat(sql.getValue(), is("select row_number() over (" + expected + ") as row_number_1 " + "from SIESTA.SALESPERSON s"));
    assertThat(args.getValue(), is(expectedArgs));
}
Also used : AnsiDialect(com.cadenzauk.siesta.dialect.AnsiDialect) TestDatabase.testDatabase(com.cadenzauk.siesta.model.TestDatabase.testDatabase) Database(com.cadenzauk.siesta.Database) SalespersonRow(com.cadenzauk.siesta.model.SalespersonRow) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 9 with AnsiDialect

use of com.cadenzauk.siesta.dialect.AnsiDialect in project siesta by cadenzauk.

the class OlapTest method olapFunction.

@ParameterizedTest(name = "{index}: {1}")
@MethodSource("parametersForOlapTest")
void olapFunction(Function<Alias<SalespersonRow>, InOlapExpectingPartitionBy<?>> f, String expectedSql) {
    Database database = testDatabase(new AnsiDialect());
    Alias<SalespersonRow> s = database.table(SalespersonRow.class).as("s");
    Scope scope = new Scope(database, s);
    InOlapExpectingPartitionBy<?> result = f.apply(s);
    assertThat(result.sql(scope), is(expectedSql));
    assertThat(result.precedence(), is(Precedence.UNARY));
}
Also used : AnsiDialect(com.cadenzauk.siesta.dialect.AnsiDialect) Scope(com.cadenzauk.siesta.Scope) TestDatabase.testDatabase(com.cadenzauk.siesta.model.TestDatabase.testDatabase) Database(com.cadenzauk.siesta.Database) SalespersonRow(com.cadenzauk.siesta.model.SalespersonRow) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 10 with AnsiDialect

use of com.cadenzauk.siesta.dialect.AnsiDialect in project siesta by cadenzauk.

the class ExpectingJoinTest method testJoin.

@ParameterizedTest
@MethodSource("argsForJoin")
void testJoin(BiFunction<ExpectingJoin1<SalespersonRow>, Alias<SalespersonRow>[], ExpectingSelect<?>> method, String expectedSql) {
    MockitoAnnotations.initMocks(this);
    Database database = testDatabase(new AnsiDialect());
    @SuppressWarnings("unchecked") Alias<SalespersonRow>[] alias = toArray(database.table(SalespersonRow.class).as("s1"), database.table(SalespersonRow.class).as("s2"), database.table(SalespersonRow.class).as("s3"), database.table(SalespersonRow.class).as("s4"), database.table(SalespersonRow.class).as("s5"), database.table(SalespersonRow.class).as("s6"), database.table(SalespersonRow.class).as("s7"), database.table(SalespersonRow.class).as("s8"), database.table(SalespersonRow.class).as("s9"));
    method.apply(database.from(alias[0]), alias).select(alias[0], SalespersonRow::firstName, "name").list(transaction);
    verify(transaction).query(sql.capture(), args.capture(), rowMapper.capture());
    assertThat(sql.getValue(), is("select s1.FIRST_NAME as name from SIESTA.SALESPERSON s1 " + expectedSql));
    assertThat(args.getValue(), arrayWithSize(0));
}
Also used : AnsiDialect(com.cadenzauk.siesta.dialect.AnsiDialect) Alias(com.cadenzauk.siesta.Alias) TestDatabase.testDatabase(com.cadenzauk.siesta.model.TestDatabase.testDatabase) Database(com.cadenzauk.siesta.Database) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Aggregations

AnsiDialect (com.cadenzauk.siesta.dialect.AnsiDialect)56 TestDatabase.testDatabase (com.cadenzauk.siesta.model.TestDatabase.testDatabase)36 Test (org.junit.jupiter.api.Test)32 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)26 MethodSource (org.junit.jupiter.params.provider.MethodSource)24 WidgetRow (com.cadenzauk.siesta.model.WidgetRow)23 Database (com.cadenzauk.siesta.Database)16 MockitoTest (com.cadenzauk.core.MockitoTest)14 SalespersonRow (com.cadenzauk.siesta.model.SalespersonRow)10 TestDatabase (com.cadenzauk.siesta.model.TestDatabase)10 ManufacturerRow (com.cadenzauk.siesta.model.ManufacturerRow)8 UncheckedAutoCloseable (com.cadenzauk.core.lang.UncheckedAutoCloseable)5 InWhereExpectingAnd (com.cadenzauk.siesta.grammar.select.InWhereExpectingAnd)4 Scope (com.cadenzauk.siesta.Scope)3 Timestamp (java.sql.Timestamp)3 RandomValues.randomLocalDate (com.cadenzauk.core.RandomValues.randomLocalDate)2 RandomValues.randomLocalDateTime (com.cadenzauk.core.RandomValues.randomLocalDateTime)2 InvalidJoinException (com.cadenzauk.siesta.grammar.InvalidJoinException)2 LocalDate (java.time.LocalDate)2 LocalDateTime (java.time.LocalDateTime)2