use of com.cadenzauk.siesta.Database in project siesta by cadenzauk.
the class SiestaExample method currentDateTest.
@Test
void currentDateTest() {
Database database = Database.newBuilder().defaultSchema("TEST").defaultSqlExecutor(JdbcSqlExecutor.of(dataSource)).build();
Tuple2<LocalDate, ZonedDateTime> today = database.select(currentDate()).comma(currentTimestamp()).single();
System.out.println(today);
}
use of com.cadenzauk.siesta.Database in project siesta by cadenzauk.
the class DeleteTest method update.
@Test
void update() {
Database database = Database.newBuilder().defaultSchema("SIESTA").build();
database.delete(WidgetRow.class).where(WidgetRow::widgetId).isEqualTo(2L).and(column(WidgetRow::description).isBetween("C").and(WidgetRow::name).or(column(WidgetRow::description).isNull())).execute(transaction);
verify(transaction).update(sql.capture(), args.capture());
assertThat(sql.getValue(), is("delete from SIESTA.WIDGET " + "where SIESTA.WIDGET.WIDGET_ID = ? " + "and (" + "SIESTA.WIDGET.DESCRIPTION between ? and SIESTA.WIDGET.NAME " + "or SIESTA.WIDGET.DESCRIPTION is null" + ")"));
assertThat(args.getValue(), is(toArray(2L, "C")));
}
use of com.cadenzauk.siesta.Database in project siesta by cadenzauk.
the class ExpectingWhereTest method where.
@ParameterizedTest
@MethodSource("parametersForWhere")
void where(BiFunction<Alias<WidgetRow>, ExpectingWhere, ExecutableStatementClause> whereClause, String expectedSql, Object[] expectedArgs) {
MockitoAnnotations.initMocks(this);
Database database = Database.newBuilder().defaultSchema("SIESTA").build();
Alias<WidgetRow> w = database.table(WidgetRow.class).as("w");
whereClause.apply(w, database.delete(w)).execute(transaction);
verify(transaction).update(sql.capture(), args.capture());
assertThat(sql.getValue(), is("delete from SIESTA.WIDGET w where " + expectedSql));
assertThat(args.getValue(), is(expectedArgs));
}
use of com.cadenzauk.siesta.Database in project siesta by cadenzauk.
the class BetweenBuilderTest method and.
@ParameterizedTest
@MethodSource("argsForAnd")
void and(BiFunction<BetweenBuilder<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");
BetweenBuilder<String, InWhereExpectingAnd<String>> between = database.from(alias).select(SalespersonRow::firstName, "name").where(SalespersonRow::firstName).isBetween(SalespersonRow::middleNames);
method.apply(between, alias).list(transaction);
verify(transaction).query(sql.capture(), args.capture(), rowMapper.capture());
assertThat(sql.getValue(), is("select s.FIRST_NAME as name from SIESTA.SALESPERSON s where s.FIRST_NAME between s.MIDDLE_NAMES and " + expectedSql));
assertThat(args.getValue(), is(expectedArgs));
}
use of com.cadenzauk.siesta.Database 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));
}
Aggregations