Пример #1
0
  @Test
  public void one_to_many_join() {
    Record joined =
        RecordJoins.join(authors)
            .on(id)
            .to(authorId)
            .oneToMany(books, authored)
            .filter(authorName.is("Alan Goodyear"))
            .findFirst()
            .get();

    assertThat(authored.extract(joined), hasItems(cromulenceOfTruths, amorousEncounters));
  }
Пример #2
0
  @Test
  public void three_way_join() {
    List<Record> joined =
        RecordJoins.join(RecordJoins.join(books).on(authorId).to(id).manyToOne(authors))
            .on(publisherId)
            .to(id)
            .manyToOne(publishers)
            .map(r -> r.select(publisherName, authorName, bookName))
            .filter(authorName.is("Alan Goodyear"))
            .collect(Collectors.toList());

    assertThat(
        joined,
        CoreMatchers.hasItems(
            $$(
                bookName.of("Amorous Encounters"),
                authorName.of("Alan Goodyear"),
                publisherName.of("Bills And Moon")),
            $$(
                bookName.of("The Cromulence Of Truths"),
                authorName.of("Alan Goodyear"),
                publisherName.of("Servo"))));
  }