Search in sources :

Example 1 with BookToBookStoreRecord

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);
    }
}
Also used : Tuple2(org.jooq.lambda.tuple.Tuple2) ResultSet(java.sql.ResultSet) Tools(org.jooq.academy.tools.Tools) BookToBookStoreRecord(org.jooq.example.db.h2.tables.records.BookToBookStoreRecord) Test(org.junit.Test)

Aggregations

ResultSet (java.sql.ResultSet)1 Tools (org.jooq.academy.tools.Tools)1 BookToBookStoreRecord (org.jooq.example.db.h2.tables.records.BookToBookStoreRecord)1 Tuple2 (org.jooq.lambda.tuple.Tuple2)1 Test (org.junit.Test)1