use of com.cadenzauk.siesta.dialect.AnsiDialect in project siesta by cadenzauk.
the class CoalesceFunctionTest method coalesceTest.
@ParameterizedTest
@MethodSource("parametersForCoalesce")
void coalesceTest(String name, Function<Alias<WidgetRow>, CoalesceFunction<String>> f, String expected) {
Database database = testDatabase(new AnsiDialect());
Alias<WidgetRow> w = database.table(WidgetRow.class).as("w");
String sql = database.from(w).select(f.apply(w), "name").where(WidgetRow::manufacturerId).isEqualTo(2L).sql();
assertThat(sql, is("select " + expected + " as name " + "from SIESTA.WIDGET w " + "where w.MANUFACTURER_ID = ?"));
}
use of com.cadenzauk.siesta.dialect.AnsiDialect in project siesta by cadenzauk.
the class ExpressionBuilderTest method testExpression.
@ParameterizedTest
@MethodSource("argsForTestExpression")
void testExpression(BiFunction<ExpressionBuilder<String, InWhereExpectingAnd<String>>, Alias<SalespersonRow>, InWhereExpectingAnd<String>> method, String expectedSql, Object[] expectedArgs) {
MockitoAnnotations.initMocks(this);
Database database = testDatabase(new AnsiDialect());
Alias<SalespersonRow> alias = database.table(SalespersonRow.class).as("s");
ExpressionBuilder<String, InWhereExpectingAnd<String>> select = database.from(alias).select(SalespersonRow::firstName, "name").where(SalespersonRow::firstName);
method.apply(select, alias).list(transaction);
verify(transaction).query(sql.capture(), args.capture(), any());
assertThat(sql.getValue(), is("select s.FIRST_NAME as name from SIESTA.SALESPERSON s where s.FIRST_NAME " + expectedSql));
assertThat(args.getValue(), is(expectedArgs));
}
use of com.cadenzauk.siesta.dialect.AnsiDialect in project siesta by cadenzauk.
the class FunctionTest method functionTest.
@ParameterizedTest
@MethodSource("parametersForFunctionTest")
void functionTest(Function<Alias<TestRow>, TypedExpression<?>> sutSupplier, String expectedSql, Object[] expectedArgs) {
MockitoAnnotations.initMocks(this);
Database database = testDatabase(new AnsiDialect());
Alias<TestRow> alias = database.table(TestRow.class).as("s");
database.from(alias).select(sutSupplier.apply(alias), "foo").list(transaction);
verify(transaction).query(sql.capture(), args.capture(), rowMapper.capture());
assertThat(sql.getValue(), is("select " + expectedSql + " as foo from SIESTA.TEST_TABLE s"));
assertThat(args.getValue(), is(expectedArgs));
}
use of com.cadenzauk.siesta.dialect.AnsiDialect in project siesta by cadenzauk.
the class SelectExpressionTest method between.
@Test
void between() {
Database database = testDatabase(new AnsiDialect());
Alias<ManufacturerRow> m = database.table(ManufacturerRow.class).as("m");
String sql = database.from(m).where(ManufacturerRow::name).isBetween("Fred").and("Barney").or(ManufacturerRow::checked).isNull().and(ManufacturerRow::manufacturerId).isGreaterThan(3L).sql();
assertThat(sql, is("select m.MANUFACTURER_ID as m_MANUFACTURER_ID, m.NAME as m_NAME, m.CHECKED as m_CHECKED " + "from SIESTA.MANUFACTURER m " + "where m.NAME between ? and ? " + "or m.CHECKED is null and m.MANUFACTURER_ID > ?"));
}
use of com.cadenzauk.siesta.dialect.AnsiDialect in project siesta by cadenzauk.
the class SelectExpressionTest method coalesceFunc.
@Test
void coalesceFunc() {
Database database = testDatabase(new AnsiDialect());
Alias<WidgetRow> w = database.table(WidgetRow.class).as("w");
String sql = database.from(w).select(coalesce(WidgetRow::name).orElse(WidgetRow::description).orElse("Bob"), "name").where(WidgetRow::manufacturerId).isEqualTo(2L).sql();
assertThat(sql, is("select coalesce(w.NAME, w.DESCRIPTION, ?) as name " + "from SIESTA.WIDGET w " + "where w.MANUFACTURER_ID = ?"));
}
Aggregations