Trying to build a Country object with JDBIs ResultSetMapper API, however I have one issue which I am not sure how to solve.
For a resultset like the following which joins the Regions (states/ territories) table to country (1 - 0..n)
@Override
public Country map(final int index, final ResultSet resultRow, final StatementContext ctx) throws SQLException {
final String countryIso3Code = resultRow.getString("iso3Code");
return Country.builder().name(resultRow.getString("name"))
.iso2Code(resultRow.getString("iso2Code"))
.iso3Code(resultRow.getString("iso3Code"))
.regions(....?)
.build();
}
How can I get the ResultSetMapper to initialise one Country object with the appropriate list of related Regions in JDBI
e.g.
United States - (USA) - (US) - (PR, RI, WA)
Currently the list of Countries returned is like the followng
United Kingdom - GBR - GB - <>
United States - USA - US - PR
United States - USA - US - RI
United States - USA - US - WA
Puerto Rico - PRI - PR - <>
Canada - CAN - CA - AB
Canada - CAN - CA - BC