Hi Dominik,

I can't comment on ModelMapper. I don't think it's necessary to use third
party mapping tools with jOOQ, at least not since jOOQ 3.15, when jOOQ
added support for nested collections, nested records, and ad-hoc
conversion. Using those features, do you still have any open questions?
Here's a quick overview:
https://blog.jooq.org/jooq-3-15s-new-multiset-operator-will-change-how-you-think-about-sql/

Best Regards,
Lukas

On Fri, Apr 7, 2023 at 9:41 PM 'tod...@googlemail.com' via jOOQ User Group <
jooq-user@googlegroups.com> wrote:

> Hi Lukas,
>
> thanks for your response.
> I already use your approach but with pojos and call it ...
>
> // composition of jooq pojos
> public class VerwaltungseinheitFullDto extends Verwaltungseinheit {
>    private Objekt objekt;
>    private Wirtschaftseinheit wirtschaftseinheit;
>    private Quartier quartier;
>    private Stadtteil stadtteil;
> }
>
> The problem is here how to efficiently map the database result set into
> that composition class without manually handle every field/attribute ?
> Sometimes I use org.modelmapper for that
> ModelMapper modelMapper = new ModelMapper();
> modelMapper.getConfiguration().addValueReader(new RecordValueReader());
>
> modelMapper.getConfiguration().setSourceNameTokenizer(NameTokenizers.UNDERSCORE);
>
> I put the value of the composition dto attribute name plus the underscore
> as prefix for every field
> var objektFields =
> Arrays.asList(VERWALTUNGSEINHEIT.objekt().fields()).stream().map(field ->
> field.as("objekt_" + field.getName())).toList();
>
> and let the modelmapper do his job
> var result = modelMapper.map(dbResult, VerwaltungseinheitFullDto.class);
>
> But its quite slow and often I prefer the updateable records in order to
> store() the record directly back ....
>
> So I didn't found a way to map such DTO like yours. RecordMapper,
> RecordHandler or something like this seems not appropriate at least in this
> way:
>
> .fetch(new RecordHandler<KalkulationPositionRecord, CompositionDto>() {
> @Override
> public CompositionDto map(KalkulationPositionRecord position) {
> CompositionDto result = new CompositionDto();
> result.setDbRecord(position);
> return result;
> }
> });
>
> But I'm quite sure, you have a way to map that without handle every field
> manually... :-)
>
> kind regards
> Dominik
>
> On Thursday, 6 April 2023 at 10:08:03 UTC+2 lukas...@gmail.com wrote:
>
> Thanks for your message.
>
> A Record's row type isn't defined by the attributes it contains. Imagine
> if that were the case, would we have to map to jOOQ's internal
> org.jooq.impl.AbstractRecord.changed or other properties, for example? No,
> an org.jooq.Record extends org.jooq.Fields, and thus defines exactly what
> fields are contained in it. As such, you cannot extend generated records
> and add more fields to them.
>
> The idea looks hackish anyway. Why extend something that is well defined,
> rather than use composition? Why not write:
>
> public class MyDto {
>     // Or, whatever:
>     MyTableRecord theRecord;
>     int additionalAttribute1;
> }
>
> Doesn't that look much cleaner?
>
> --
> 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.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/jooq-user/91dc608d-b584-417f-b33d-958b7d8a8ed2n%40googlegroups.com
> <https://groups.google.com/d/msgid/jooq-user/91dc608d-b584-417f-b33d-958b7d8a8ed2n%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jooq-user/CAB4ELO5pvodyOXB0TgGOyn1J7DG%3DCRscQbpBB7%2B4EF0On6HM_w%40mail.gmail.com.

Reply via email to