Thank you for the guidance and confirmation. The first option was from
my sql instinct, but I wanted to see where jOOQ might take me. (The
parenthesis mess is nicely managed for me by emacs :) )
On 03/29/2017 03:30 AM, Lukas Eder wrote:
Comment inline...
2017-03-28 20:36 GMT+02:00 Rob Sargent <robjsarg...@gmail.com
<mailto:robjsarg...@gmail.com>>:
Thank you again, all of these work:
Map<String, PersonRecord> fullMap = new HashMap<>();
fullMap.putAll(ctx.select(PERSON.fields())
.from(PERSON.join(ALIAS)
.on(PERSON.ID.equal(ALIAS.PERSON_ID)))
.where(ALIAS.AKA.in
<http://ALIAS.AKA.in>(nameSet))
.fetchMap(PERSON.NAME <http://PERSON.NAME>,
r -> r.into(PERSON)));
fullMap.putAll(ctx.select(PERSON.fields())
.from(PERSON.join(ALIAS)
.on(PERSON.ID.equal(ALIAS.PERSON_ID)
.and(ALIAS.AKA.in <http://ALIAS.AKA.in>(nameSet))))
.fetchMap(PERSON.NAME <http://PERSON.NAME>,
r -> r.into(PERSON)));
fullMap.putAll(ctx.select(PERSON.fields())
.from(PERSON.join(ALIAS)
.on(PERSON.ID.equal(ALIAS.PERSON_ID))
.and(ALIAS.AKA.in
<http://ALIAS.AKA.in>(nameSet)))
.fetchMap(PERSON.NAME <http://PERSON.NAME>,
r -> r.into(PERSON)));
Is any more proper than the other?
The first one is what I'd choose here, because the WHERE predicate is
semantically sligthly different from the ON predicate. Your ALIAS.AKA
predicate is not stricly part of the JOIN specification, so I wouldn't
put it there.
For inner join, this is mostly just a stylistic debate (at least in
most databases). For outer join, 1 would be a very different query
from 2/3 (which is another reason why stylistically, you should put
the predicates at the semantically right place).
2 and 3 are exactly the same thing. 2 is creating a Condition inside
of ON, whereas 3 is using TableOnConditionStep convenience API (which
internally does the same thing as 2 but leads to a bit less confusing
parentheses).
Note, you could also write this, and it would still be the same as 2
and 3, just using convenience API:
fullMap.putAll(ctx.select(PERSON.fields())
.from(PERSON)
.join(ALIAS)
.on(PERSON.ID.equal(ALIAS.PERSON_ID))
.and(ALIAS.AKA.in <http://alias.aka.in/>(nameSet))
.fetchMap(PERSON.NAME <http://person.name/>, r -> r.into(PERSON)));
I had gotten side tracked thinking I needed to use a RecordMapper
but could never set that up properly.
Well, your lambda *is* a RecordMapper :) Just much more convenient
syntax than an anonymous or "normal" class.
Hope this helps,
Lukas
--
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 jooq-user+unsubscr...@googlegroups.com
<mailto:jooq-user+unsubscr...@googlegroups.com>.
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 jooq-user+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.