use of com.cadenzauk.siesta.dialect.AnsiDialect in project siesta by cadenzauk.
the class CaseExpressionTest method subsequentClauses.
@ParameterizedTest
@MethodSource("parametersForSubsequentClauses")
void subsequentClauses(String expected, BiFunction<CaseExpression<String>, Alias<WidgetRow>, TypedExpression<String>> f, Object[] expectedArgs) {
Database database = testDatabase(new AnsiDialect());
Alias<WidgetRow> w = database.table(WidgetRow.class).as("w");
database.from(w).select(f.apply(Case.when(literal(1)).isEqualTo(literal(2)).then("UNLIKELY"), w), "name").list(transaction);
verify(transaction).query(sql.capture(), args.capture(), any());
assertThat(sql.getValue(), is("select case when 1 = 2 then 'UNLIKELY' " + expected + " end as name " + "from SIESTA.WIDGET w"));
assertThat(args.getValue(), is(expectedArgs));
}
use of com.cadenzauk.siesta.dialect.AnsiDialect in project siesta by cadenzauk.
the class CastExpressionTest method sql.
@ParameterizedTest
@MethodSource("parametersForSql")
<T> void sql(String type, Function<CastBuilder<String>, TypedExpression<T>> castFunction) {
when(expression.sql(scope)).thenReturn("input");
when(scope.database()).thenReturn(database);
when(scope.dialect()).thenReturn(new AnsiDialect());
CastBuilder<String> builder = new CastBuilder<>(expression);
TypedExpression<T> sut = castFunction.apply(builder);
String result = sut.sql(scope);
assertThat(result, is("cast(input as " + type + ")"));
verifyNoMoreInteractions(expression, scope, dialect, database, resultSet);
}
use of com.cadenzauk.siesta.dialect.AnsiDialect in project siesta by cadenzauk.
the class ExpressionBuilderTest method isNotInWithNoValuesShouldThrow.
@Test
void isNotInWithNoValuesShouldThrow() {
Database database = testDatabase(new AnsiDialect());
ExpressionBuilder<String, InWhereExpectingAnd<SalespersonRow>> select = database.from(SalespersonRow.class).where(SalespersonRow::firstName);
// noinspection Convert2MethodRef
calling(() -> select.isNotIn(new String[0])).shouldThrow(IllegalArgumentException.class);
}
use of com.cadenzauk.siesta.dialect.AnsiDialect in project siesta by cadenzauk.
the class ExpressionBuilderTest method isInWithNoValuesShouldThrow.
@Test
void isInWithNoValuesShouldThrow() {
Database database = testDatabase(new AnsiDialect());
ExpressionBuilder<String, InWhereExpectingAnd<SalespersonRow>> select = database.from(SalespersonRow.class).where(SalespersonRow::firstName);
// noinspection Convert2MethodRef
calling(() -> select.isIn(new String[0])).shouldThrow(IllegalArgumentException.class);
}
use of com.cadenzauk.siesta.dialect.AnsiDialect in project siesta by cadenzauk.
the class ExpectingUnionTest method union.
@Test
void union() {
Database database = testDatabase(new AnsiDialect());
database.select(TypedExpression.value(1), "one").union(database.select(TypedExpression.literal(2), "two")).unionAll(database.select(TypedExpression.value(3), "three")).orderBy(1).list(transaction);
verify(transaction).query(sql.capture(), args.capture(), rowMapper.capture());
assertThat(sql.getValue(), is("select ? as one from DUAL union select 2 as two from DUAL union all select ? as three from DUAL order by 1 asc"));
assertThat(args.getValue(), is(toArray(1, 3)));
}
Aggregations