use of com.cadenzauk.siesta.model.ManufacturerRow in project siesta by cadenzauk.
the class FromTest method validateInvalidThrowsWhenWrongAlias.
@Test
void validateInvalidThrowsWhenWrongAlias() {
Database database = testDatabase(new AnsiDialect());
calling(() -> database.from(ManufacturerRow.class, "m1").join(ManufacturerRow.class, "m2").on("m1", ManufacturerRow::name).isEqualTo("Fred").sql()).shouldThrow(InvalidJoinException.class).withMessage(is("Joined table 'SIESTA.MANUFACTURER m2' is not referenced in the ON clause."));
}
use of com.cadenzauk.siesta.model.ManufacturerRow in project siesta by cadenzauk.
the class FromTest method invalidJoinCanBeSuppressed.
@Test
void invalidJoinCanBeSuppressed() {
Database database = testDatabase(new AnsiDialect());
String sql = database.from(ManufacturerRow.class, "m1").join(ManufacturerRow.class, "m2").validate(false).on("m1", ManufacturerRow::name).isEqualTo("Fred").sql();
assertThat(sql, startsWith("select m1.MANUFACTURER_ID as m1_MANUFACTURER_ID"));
}
use of com.cadenzauk.siesta.model.ManufacturerRow in project siesta by cadenzauk.
the class DatabaseIntegrationTest method delete.
@Test
void delete() {
Database database = testDatabase(dataSource, dialect);
long manufacturer1 = newId();
long manufacturer2 = newId();
ManufacturerRow manufacturerRow1 = ManufacturerRow.newBuilder().manufacturerId(manufacturer1).name(Optional.of("tbc 1")).build();
ManufacturerRow manufacturerRow2 = ManufacturerRow.newBuilder().manufacturerId(manufacturer2).name(Optional.of("tbc 2")).build();
database.insert(manufacturerRow1, manufacturerRow2);
assertThat(database.from(ManufacturerRow.class).select(count()).where(ManufacturerRow::name).isLike("tbc %").single(), is(2));
int rowsDeleted = database.delete(ManufacturerRow.class).where(ManufacturerRow::name).isEqualTo("tbc 1").execute();
assertThat(database.from(ManufacturerRow.class).select(count()).where(ManufacturerRow::name).isLike("tbc %").single(), is(1));
assertThat(rowsDeleted, is(1));
}
use of com.cadenzauk.siesta.model.ManufacturerRow in project siesta by cadenzauk.
the class DatabaseIntegrationTest method leftJoinOfMissingIsNull.
@Test
void leftJoinOfMissingIsNull() {
Database database = testDatabase(dataSource, dialect);
long manufacturer1 = newId();
long manufacturer2 = newId();
ManufacturerRow twoParts = ManufacturerRow.newBuilder().manufacturerId(manufacturer1).name(Optional.of("Has a Part")).build();
ManufacturerRow noParts = ManufacturerRow.newBuilder().manufacturerId(manufacturer2).name(Optional.of("Has No Parts")).build();
WidgetRow aWidget1 = WidgetRow.newBuilder().widgetId(newId()).manufacturerId(manufacturer1).name("Name 1").build();
database.insert(noParts, twoParts);
database.insert(aWidget1);
List<Tuple2<ManufacturerRow, WidgetRow>> result = database.from(ManufacturerRow.class, "m").leftJoin(WidgetRow.class, "w").on(WidgetRow::manufacturerId).isEqualTo(ManufacturerRow::manufacturerId).where(ManufacturerRow::manufacturerId).isIn(manufacturer1, manufacturer2).orderBy(ManufacturerRow::manufacturerId).list();
assertThat(result, hasSize(2));
assertThat(result.get(0).item1().name(), is(Optional.of("Has a Part")));
assertThat(result.get(0).item2().name(), is("Name 1"));
assertThat(result.get(1).item1().name(), is(Optional.of("Has No Parts")));
assertThat(result.get(1).item2(), nullValue());
}
use of com.cadenzauk.siesta.model.ManufacturerRow in project siesta by cadenzauk.
the class DatabaseIntegrationTest method selectRow.
@Test
void selectRow() {
Database database = testDatabase(dataSource, dialect);
long manufacturerId = newId();
ManufacturerRow aManufacturer = ManufacturerRow.newBuilder().manufacturerId(manufacturerId).name(Optional.of("Acclaimed Widgets")).build();
WidgetRow aWidget1 = WidgetRow.newBuilder().widgetId(newId()).manufacturerId(manufacturerId).name("Acclaimed 1").build();
WidgetRow aWidget2 = WidgetRow.newBuilder().widgetId(newId()).manufacturerId(manufacturerId).name("Acclaimed 2").build();
database.insert(aManufacturer);
database.insert(aWidget1, aWidget2);
List<WidgetRow> acclaimedWidgets1 = database.from(ManufacturerRow.class, "m").join(WidgetRow.class, "w").on(WidgetRow::manufacturerId).isEqualTo(ManufacturerRow::manufacturerId).select(WidgetRow.class).where(ManufacturerRow::name).isEqualTo("Acclaimed Widgets").orderBy(WidgetRow::name, DESC).list();
List<Tuple2<String, WidgetRow>> acclaimedWidgets2 = database.from(ManufacturerRow.class, "m").join(WidgetRow.class, "w").on(WidgetRow::manufacturerId).isEqualTo(ManufacturerRow::manufacturerId).select(WidgetRow::name, "name").comma(WidgetRow.class).where(ManufacturerRow::name).isEqualTo("Acclaimed Widgets").orderBy(WidgetRow::name, Order.ASC).list();
assertThat(acclaimedWidgets1, hasSize(2));
assertThat(acclaimedWidgets1.get(0).name(), is("Acclaimed 2"));
assertThat(acclaimedWidgets1.get(1).name(), is("Acclaimed 1"));
assertThat(acclaimedWidgets2, hasSize(2));
assertThat(acclaimedWidgets2.get(0).item1(), is("Acclaimed 1"));
assertThat(acclaimedWidgets2.get(1).item1(), is("Acclaimed 2"));
assertThat(acclaimedWidgets2.get(0).item2().name(), is("Acclaimed 1"));
assertThat(acclaimedWidgets2.get(1).item2().name(), is("Acclaimed 2"));
}
Aggregations