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.

Reply via email to