use of org.jooq.XMLFormat in project jOOQ by jOOQ.
the class TestContainersTest method testMultisetFormattingAsXMLorJSON.
@Test
public void testMultisetFormattingAsXMLorJSON() {
// Get films by title, and their actors and categories as nested collections,
// and all the customers that have rented the film, and their payments
Result<?> result = println(ctx.select(FILM.TITLE, multiset(select(FILM_ACTOR.actor().FIRST_NAME, FILM_ACTOR.actor().LAST_NAME).from(FILM_ACTOR).where(FILM_ACTOR.FILM_ID.eq(FILM.FILM_ID))).as("actors"), multiset(select(FILM_CATEGORY.category().NAME).from(FILM_CATEGORY).where(FILM_CATEGORY.FILM_ID.eq(FILM.FILM_ID))).as("categories"), multiset(select(PAYMENT.rental().customer().FIRST_NAME, PAYMENT.rental().customer().LAST_NAME, multisetAgg(PAYMENT.PAYMENT_DATE, PAYMENT.AMOUNT).as("payments"), sum(PAYMENT.AMOUNT).as("total")).from(PAYMENT).where(PAYMENT.rental().inventory().FILM_ID.eq(FILM.FILM_ID)).groupBy(PAYMENT.rental().customer().CUSTOMER_ID, PAYMENT.rental().customer().FIRST_NAME, PAYMENT.rental().customer().LAST_NAME)).as("customers")).from(FILM).where(FILM.TITLE.like("A%")).orderBy(FILM.TITLE).limit(5)).fetch();
System.out.println(result.format(new TXTFormat()));
System.out.println(result.formatXML(new XMLFormat().xmlns(false).format(true).header(false).recordFormat(COLUMN_NAME_ELEMENTS)));
System.out.println(result.formatJSON(new JSONFormat().format(true).header(false).recordFormat(OBJECT)));
}
Aggregations