use of com.cadenzauk.siesta.Database 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.Database 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.Database in project siesta by cadenzauk.
the class TypedExpressionTest method columnAncCast.
@ParameterizedTest(name = "{1}")
@MethodSource({ "parametersForColumn", "parametersForCast" })
void columnAncCast(Function<Alias<TestTable>, ExpressionBuilder<Integer, BooleanExpression>> method, String expectedSql, Object[] expectedArgs) {
Database database = Database.newBuilder().build();
Alias<TestTable> alias = database.table(TestTable.class).as("t");
Scope scope = new Scope(database, alias);
ExpressionBuilder<Integer, BooleanExpression> result = method.apply(alias);
assertThat(result.sql(scope), is(expectedSql));
assertThat(result.args(scope).toArray(), is(expectedArgs));
}
use of com.cadenzauk.siesta.Database in project siesta by cadenzauk.
the class TypedExpressionTest method arithmeticOperators.
@ParameterizedTest(name = "{1}")
@MethodSource("parametersForArithmeticOperators")
void arithmeticOperators(BiFunction<TypedExpression<Integer>, Alias<TestTable>, TypedExpression<Integer>> method, String expectedSql, Object[] expectedArgs) {
Database database = Database.newBuilder().build();
Alias<TestTable> alias = database.table(TestTable.class).as("t");
Scope scope = new Scope(database, alias);
when(sut.precedence()).thenReturn(Precedence.COLUMN);
when(sut.sql(scope)).thenReturn("lhs");
when(sut.args(scope)).thenReturn(Stream.of(1, 2));
TypedExpression<Integer> result = method.apply(sut, alias);
assertThat(result.sql(scope), is("lhs" + expectedSql));
assertThat(result.args(scope).toArray(), is(ArrayUtils.addAll(toArray(1, 2), expectedArgs)));
}
use of com.cadenzauk.siesta.Database 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