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(nameSet))
.fetchMap(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(nameSet))))
.fetchMap(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(nameSet)))
.fetchMap(PERSON.NAME, r -> r.into(PERSON)));
Is any more proper than the other?
I had gotten side tracked thinking I needed to use a RecordMapper but
could never set that up properly.
On 03/28/2017 10:15 AM, Lukas Eder wrote:
Hmm, I thought there was a fetchMap(Field, Table) method but there
isn't. In that case, you could do:
DSL.using(configuration)
.select(...)
.from(...)
.fetchMap(MY_TABLE.KEY_FIELD, r -> r.into(PERSON));
This will be using the Record.into(Table) method:
https://www.jooq.org/javadoc/latest/org/jooq/Record.html#into-org.jooq.Table-
Hope this helps,
Lukas
2017-03-28 15:28 GMT+02:00 Rob Sargent <robjsarg...@gmail.com
<mailto:robjsarg...@gmail.com>>:
Map<String,PersonRecord> is a different matter I think.
On Mar 27, 2017, at 9:25 PM, Samir Faci <sa...@esamir.com
<mailto:sa...@esamir.com>> wrote:
fetchMap:
Map<Long, String> userMapping =
complexQuery.fetchMap(schema.table.fieldname,
schema.table.fieldname2);
I've used the exact same pattern for fetchMap irrelevant of the
complexity of the SQL and it works fine for me. I do find
repeating the
field names a bit repetitive but it does work.
If you're on Java 8, you have access to the .fetch().stream()
pattern and you can simply use the standard Java 8 pattern to
conver it to a map if you'd like.
Actually, I take it back.. if you're on Jooq 3.1 I don't think
you have that feature. I can't remember what version I started
with but I don't think I was ever on 3.1 might be a legacy issue?
--
Samir Faci
On Mon, Mar 27, 2017 at 4:41 PM, Rob Sargent
<robjsarg...@gmail.com <mailto:robjsarg...@gmail.com>> wrote:
Are there any actual examples of RecordMapper working with
fetchMap() on results of joins?
I can map a direct select to a string (name field), but not
for a join. I've wondered through the code for
DefaultRecordMapper, Record and RecordType but still haven't
managed to get a usable mapper the will fetchMap() my
select/join results to a string (the name field of the record)
On Monday, July 22, 2013 at 3:41:44 AM UTC-6, Lukas Eder wrote:
Hi Ryan,
Unlike most JPA-based ORMs, jOOQ cleanly separates
querying from mapping. There is no implicit knowledge
about relations between your document and annotation
tables, unless you explicitly join the two tables in your
SQL statement. Once the result is fetched, you have lots
of means of mapping the flat result set onto your custom
domain model (i.e. your existing POJOs). jOOQ supports a
default mapping algorithm that is described here:
http://www.jooq.org/javadoc/latest/org/jooq/impl/DefaultRecordMapper.html
<http://www.jooq.org/javadoc/latest/org/jooq/impl/DefaultRecordMapper.html>
Since jOOQ 3.1, you can globally override the
DefaultRecordMapper and inject your own mapping
strategies, using tools like
- http://modelmapper.org <http://modelmapper.org/>
- https://code.google.com/p/orika
<https://code.google.com/p/orika/>
- Your own implementation of jOOQ's RecordMapper
Some documentation:
http://www.jooq.org/doc/3.1/manual/sql-execution/fetching/recordmapper
<http://www.jooq.org/doc/3.1/manual/sql-execution/fetching/recordmapper/>
http://www.jooq.org/doc/3.1/manual/sql-execution/fetching/pojos
<http://www.jooq.org/doc/3.1/manual/sql-execution/fetching/pojos/>
http://www.jooq.org/doc/3.1/manual/sql-execution/fetching/pojos-with-recordmapper-provider
<http://www.jooq.org/doc/3.1/manual/sql-execution/fetching/pojos-with-recordmapper-provider/>
Hope this helps
Lukas
2013/7/19 Ryan Cornia <ryanc...@gmail.com>
I have an application with existing POJO's (and many
hand coded SQL statements) I would like to try JOOQ on.
I can't find any examples of how to do this? Do I
need to configure JOOQ programmatically so it knows,
for instance, I have a Document table and Annotation
table, and how they are related? Where would I find
an example of that?
Or is code generation needed to get full feature type
checking queries? Right now the data is mostly read
only, so I am looking for the most maintainable way
to do queries.
Thanks,
Ryan
--
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+...@googlegroups.com.
For more options, visit
https://groups.google.com/groups/opt_out
<https://groups.google.com/groups/opt_out>.
--
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
<https://groups.google.com/d/optout>.
--
Thank you
Samir Faci
https://keybase.io/csgeek
--
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
<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
<mailto:jooq-user+unsubscr...@googlegroups.com>.
For more options, visit https://groups.google.com/d/optout
<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
<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.