use of com.cadenzauk.siesta.Database in project siesta by cadenzauk.
the class UpdateTest method update.
@Test
void update() {
Database database = Database.newBuilder().defaultSchema("SIESTA").table(WidgetRow.class, t -> t.builder(WidgetRow.Builder::build)).build();
database.update(WidgetRow.class, "w").set(WidgetRow::name).to("Fred").set(WidgetRow::description).to(Optional.of("Bob")).where(WidgetRow::widgetId).isEqualTo(1L).and(column(WidgetRow::description).isBetween("A").and("w", WidgetRow::name).or(column(WidgetRow::description).isNull())).execute(transaction);
verify(transaction).update(sql.capture(), args.capture());
assertThat(sql.getValue(), is("update SIESTA.WIDGET w " + "set NAME = ?, " + "DESCRIPTION = ? " + "where w.WIDGET_ID = ? " + "and (" + "w.DESCRIPTION between ? and w.NAME " + "or w.DESCRIPTION is null" + ")"));
assertThat(args.getValue(), is(toArray("Fred", "Bob", 1L, "A")));
}
use of com.cadenzauk.siesta.Database 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));
}
use of com.cadenzauk.siesta.Database 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));
}
use of com.cadenzauk.siesta.Database 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));
}
use of com.cadenzauk.siesta.Database in project siesta by cadenzauk.
the class ExpectingSelectTest method testSelect.
@ParameterizedTest
@MethodSource("argsForSelect")
void testSelect(BiFunction<ExpectingSelect<SalespersonRow>, Alias<SalespersonRow>, Select<?>> method, String expectedSql) {
MockitoAnnotations.initMocks(this);
Database database = testDatabase(new AnsiDialect());
Alias<SalespersonRow> alias = database.table(SalespersonRow.class).as("s");
method.apply(database.from(alias), alias).list(transaction);
verify(transaction).query(sql.capture(), args.capture(), rowMapper.capture());
assertThat(sql.getValue(), is("select " + expectedSql + " from SIESTA.SALESPERSON s"));
assertThat(args.getValue(), arrayWithSize(0));
}
Aggregations