use of com.cadenzauk.siesta.dialect.AnsiDialect in project siesta by cadenzauk.
the class CountTest method countDistinct1.
@Test
void countDistinct1() {
Database database = TestDatabase.testDatabase(new AnsiDialect());
database.from(WidgetRow.class, "w").select(countDistinct(WidgetRow::name), "n").where(WidgetRow::manufacturerId).isEqualTo(4002L).list(transaction);
verify(transaction).query(sql.capture(), args.capture(), rowMapper.capture());
assertThat(sql.getValue(), is("select count(distinct w.NAME) as n " + "from SIESTA.WIDGET w " + "where w.MANUFACTURER_ID = ?"));
assertThat(args.getValue(), arrayWithSize(1));
assertThat(args.getValue()[0], is(4002L));
}
use of com.cadenzauk.siesta.dialect.AnsiDialect in project siesta by cadenzauk.
the class DataTypeTest method get.
@ParameterizedTest
@MethodSource("parametersForGet")
<T> void get(DataType<T> sut, SqlBiConsumer<ResultSet, String> resultSetExtractor, Optional<ZoneId> dbTimeZone, T expected) throws SQLException {
resultSetExtractor.accept(rs, "someColumn");
when(db.dialect()).thenReturn(new AnsiDialect());
dbTimeZone.ifPresent(zone -> when(db.databaseTimeZone()).thenReturn(zone));
Optional<T> result = sut.get(rs, "someColumn", db);
assertThat(result, is(Optional.of(expected)));
}
use of com.cadenzauk.siesta.dialect.AnsiDialect in project siesta by cadenzauk.
the class DataTypeTest method getZonedDateTime.
@ParameterizedTest
@MethodSource("timeZones")
void getZonedDateTime(String timeZone) throws SQLException {
ZonedDateTime expected = ZonedDateTime.of(randomLocalDateTime(), ZoneId.of("UTC"));
Timestamp returnVal = Timestamp.from(expected.toInstant());
when(rs.getTimestamp(eq("someColumn"), any())).thenReturn(returnVal);
when(db.databaseTimeZone()).thenReturn(ZoneId.of(timeZone));
when(db.dialect()).thenReturn(new AnsiDialect());
Optional<ZonedDateTime> result = DataType.ZONED_DATE_TIME.get(rs, "someColumn", db);
assertThat(result, is(Optional.of(expected)));
}
use of com.cadenzauk.siesta.dialect.AnsiDialect in project siesta by cadenzauk.
the class DataTypeTest method toDatabaseZonedDateTime.
@ParameterizedTest
@MethodSource("timeZonePairs")
void toDatabaseZonedDateTime(String dbTimeZone, String jvmTimeZone) {
ZoneId dbZone = ZoneId.of(dbTimeZone);
ZoneId jvmZone = ZoneId.of(jvmTimeZone);
ZonedDateTime input = RandomValues.randomZonedDateTime(jvmZone);
try (UncheckedAutoCloseable ignored = withTimeZone(jvmTimeZone)) {
ZonedDateTime dbTime = input.withZoneSameInstant(dbZone);
Timestamp expected = Timestamp.valueOf(dbTime.toLocalDateTime());
when(db.databaseTimeZone()).thenReturn(dbZone);
when(db.dialect()).thenReturn(new AnsiDialect());
Object result = DataType.ZONED_DATE_TIME.toDatabase(db, input);
assertThat(result, is(expected));
}
}
use of com.cadenzauk.siesta.dialect.AnsiDialect in project siesta by cadenzauk.
the class EmbeddedTest method embeddedOverride.
@Test
void embeddedOverride() {
Database database = Database.newBuilder().dialect(new AnsiDialect()).build();
database.from(CustomerWithOverride.class).select(CustomerWithOverride::address).comma(column(CustomerWithOverride::address).dot(Address::line1), "l1").comma(column(CustomerWithOverride::address).dot(Address::line2), "l2").list(sqlExecutor);
Mockito.verify(sqlExecutor).query(sql.capture(), args.capture(), any());
assertThat(sql.getValue(), is("select " + "CUSTOMER.ADDRESS_LINE1 as CUSTOMER_ADDRESS_LINE1, " + "CUSTOMER.ADDR_LINE_2 as CUSTOMER_ADDR_LINE_2, " + "CUSTOMER.ADDRESS_LINE1 as l1, " + "CUSTOMER.ADDR_LINE_2 as l2 " + "from CUSTOMER CUSTOMER"));
}
Aggregations