You're looking for this, I suspect? http://www.jooq.org/javadoc/latest/org/jooq/ResultQuery.html#fetchGroups-org.jooq.Field:A-
Of course, with Java 8 Streams you'll get access to even more powerful transformations... 2015-05-05 13:34 GMT+02:00 Ben Hood <[email protected]>: > Hi Lukas, > > I'm looking for a terse way to create a map grouping from a result set. > > Here's my example: > > ctx.select(GROUP_MEMBERS.GROUP_ID, GROUPS.NAME, GROUP_MEMBERS.USER_ID). > from(GROUP_MEMBERS). > join(GROUPS).on(GROUP_MEMBERS.GROUP_ID.eq(GROUPS.ID)). > where(GROUP_MEMBERS.REGISTRANT.eq(organization)). > fetchGroups(GROUP_MEMBERS.GROUP_ID, GROUP_MEMBERS.USER_ID); > > The _ID fields are BIGINT and the NAME is a VARCHAR. > > This produces > > Map<Long,List<Long>> > > which is half the rent. In addition, I'd like it to automagically produce a > > Map<Record2<Long,String>, List<Long>> > > whereby > > GROUP_MEMBERS.GROUP_ID, GROUPS.NAME > > are keys in the map, and > > GROUP_MEMBERS.USER_ID > > are elements of a List<Long> value in the map. This would avoid having > to iterate through the result (set) twice to group members. > > Is there a (hidden) trick to doing this in the JOOQ API alone, or > would I need to find something in the stream API? > > Cheers, > > Ben > > -- > You received this message because you are subscribed to the Google Groups > "jOOQ User Group" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "jOOQ User Group" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
