use of org.jooq.example.db.h2.tables.records.BookToBookStoreRecord in project SimpleFlatMapper by arnaudroger.
the class Example_One_To_Many method authorsAndBooksAndBookStore.
@Test
public void authorsAndBooksAndBookStore() throws SQLException {
// All we need to execute a query is provide it with a connection and then
// call fetch() on it.
Tools.title("Selecting authorsAndBooksAndBookStore");
JdbcMapper<Tuple2<AuthorRecord, List<Tuple2<BookRecord, List<BookToBookStoreRecord>>>>> mapper = JdbcMapperFactory.newInstance().addKeys("ID", "BOOK_STORE_NAME").newMapper(new TypeReference<Tuple2<AuthorRecord, List<Tuple2<BookRecord, List<BookToBookStoreRecord>>>>>() {
});
try (ResultSet rs = DSL.using(connection()).select(AUTHOR.ID, AUTHOR.FIRST_NAME, AUTHOR.LAST_NAME, AUTHOR.DATE_OF_BIRTH, BOOK.ID, BOOK.TITLE, BOOK_TO_BOOK_STORE.BOOK_STORE_NAME, BOOK_TO_BOOK_STORE.STOCK).from(AUTHOR).leftJoin(BOOK).on(BOOK.AUTHOR_ID.eq(AUTHOR.ID)).leftJoin(BOOK_TO_BOOK_STORE).on(BOOK_TO_BOOK_STORE.BOOK_ID.eq(BOOK.ID)).orderBy(AUTHOR.ID).fetchResultSet()) {
mapper.stream(rs).forEach(Tools::print);
}
}
Aggregations