On Tue, May 5, 2015 at 12:38 PM, Lukas Eder <[email protected]> wrote:
> 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...
So this would return
Map<Record, Result<R>>
I guess that you would use the static column metadata to extract the
fields from the Record key and Result<R> list respectively?
In the meantime, I've hacked together this agricultural solution,
which does the job, but is not very elegant:
public List<Group> groupsForOrganization(final Long organization) {
return db.execute(ctx ->
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().
stream().
collect(Collectors.groupingBy(x ->
Pair.of(x.getValue(GROUP_MEMBERS.GROUP_ID),
x.getValue(GROUPS.NAME)))).
entrySet().
stream().
map(x -> {
Pair<Long,String> key = x.getKey();
List<Record3<Long, String, Long>> records = x.getValue();
List<Long> members = records.stream().map(y ->
y.getValue(GROUP_MEMBERS.USER_ID)).collect(Collectors.toList());
return Group.create(key.getLeft(), key.getRight(), members);
}).
collect(Collectors.toList())
);
}
This hack uses the Apache tuple definition - on reflection I guess I
could have used some other tuple implementation - does JOOQ lambda
have some kind of tuple thingy?
--
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.