Hello,
2015-01-22 5:01 GMT+01:00 Bill O'Neil <[email protected]>:
> 1. Is it possible to reuse auto generated RecordMappers from the dao
> objects? I have been trying to find a way to do something like.
>
> List<User> users = using(configuration())
> .selectFrom(Tables.USER)
> .from(Tables.USER)
> .join(Tables.ROLES)
> .onKey()
> .where(Tables.ROLES.ROLE.eq("admin"))
> .fetch()
> .map(mapper());
>
> This doesn't quite work is there a way to do it? Essentially a simple
> join and only return a pojo from one of the tables.
>
The DAO.mapper() method is public. Why doesn't calling it work for you?
Do note, it doesn't do anything magic, out-of-the-box. It simply calls
through to the DefaultRecordMapper, caching the instance in the DAO
instance.
The one thing that is obviously not correct is your repeating the "FROM
USER" clause twice. You should write
using(configuration())
.select()
.from(Tables.USER)
.join(Tables.ROLES)
.onKey()
2. Is there a way to return multiple mapped pojos from a query. Possibly
> Combining JOOQ and JOOL or something.
>
> List<Tuple2<User, Role>> users = using(configuration())
> .selectFrom(Tables.USER)
> .from(Tables.USER)
> .join(Tables.ROLES)
> .onKey()
> .fetch()
> .map(user.mapper(), role.mapper());
>
> I have been using slick in scala which allows you to tuple a bunch of case
> classes into a single result. I was curious if you can do something
> similar in JOOQ easily.
>
That sounds very interesting indeed! We haven't thought about this yet.
Do note, though, that this only works if your USER and ROLES tables do not
share the same column names, though. In case they don't, you can do
something like that:
List<Tuple2<User, Role>> users = using(configuration())
.select()
.from(Tables.USER)
.join(Tables.ROLES)
.onKey()
.fetch()
.map(r -> tuple(user.mapper().map(r), role.mapper().map(r)));
We'll keep this use-case in mind when implementing jOOQ 3.6, where we'll
tackle support for nested records both on a SQL and on a mapping level.
--
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.