On Tue, May 5, 2015 at 2:04 PM, Lukas Eder <[email protected]> wrote:
>   return db.execute(ctx ->
>     seq(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)).
>         orderBy(GROUP_MEMBERS.GROUP_ID, GROUPS.NAME, GROUP_MEMBERS.USER_ID).
>         fetch()).
>         groupBy(x -> Tuple.tuple(x.getValue(GROUP_MEMBERS.GROUP_ID),
>                                  x.getValue(GROUPS.NAME))),
>                 Collectors.mapping(
>
>                     x -> x.getValue(GROUP_MEMBERS.USER_ID),
>
>                     Collectors.toList()
>
>                 ))
>     );
>
> I've just noticed that the Collectors.mapping() bit might probably be
> simplified as well. The JDK's approach is too verbose.
>
> Let me know if this works for you,


This was the best I could come up with:

public List<Group> groupsForOrganization(final Long organization) {
  return db.execute(ctx ->
    seq(
      seq(
        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)).
            orderBy(GROUP_MEMBERS.GROUP_ID, GROUPS.NAME, GROUP_MEMBERS.USER_ID).
            fetch()
      ).groupBy(
        x -> Tuple.tuple(x.getValue(GROUP_MEMBERS.GROUP_ID),
x.getValue(GROUPS.NAME)),
        Collectors.mapping(
            x -> x.getValue(GROUP_MEMBERS.USER_ID),
            Collectors.toList()
      ))
    ).map(x -> Group.create(x.v1.v1, x.v1.v2, x.v2)
    ).toList()
  );
}

-- 
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.

Reply via email to