Thanks Lukas,

I created https://github.com/jOOQ/jOOQ/issues/16470 for this.

> We can do a topological sort.

That sounds hopeful!  Not sure how to do it, so if there is anything you
share that would be great.


I'm also posting here some example using Mapstruct, for if somebody else
comes to this thread via Google.

So imagine the table has a "code" column but in the POJO it is "alpha2Code".
Then we can use Mapstruct to create a mapper like:

import org.jooq.RecordUnmapper;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.ReportingPolicy;
import org.mapstruct.factory.Mappers;

@Mapper(unmappedTargetPolicy = ReportingPolicy.ERROR)
public interface ContinentMapper extends RecordUnmapper<Continent,
ContinentRecord> {

    ContinentMapper INSTANCE = Mappers.getMapper(ContinentMapper.class);

    @Override
    @Mapping(target = "code", source = "alpha2Code")
    ContinentRecord unmap(Continent source);
}

Above Mapstruct mapper will do the trick:

Continent continent = new Continent();
continent.setId("europe");
continent.setAlpha2Code("eu");
continent.setName("Europe");
continent.setDemonym("European");

// Map POJO to jOOQ generated record.
ContinentRecord continentRecord = ContinentMapper.INSTANCE.unmap(continent);


The nice thing with the (unmappedTargetPolicy = ReportingPolicy.ERROR is
that the compilation will fail if there target properties that are not
found in the source.
This provides full type safety :-)


Cheers,
Marcel




On Tue, Mar 19, 2024 at 7:57 AM Lukas Eder <lukas.e...@gmail.com> wrote:

>
>
> On Mon, Mar 18, 2024 at 10:26 PM Marcel Overdijk <marceloverd...@gmail.com>
> wrote:
>
>> Related to generating the schema ddl I found there is the dsl.ddl(schema)
>> method of jooq.
>
>
> Great that you've found it! :)
>
>
>> I noticed it generates the ddl in the order:
>> create table country ...
>> create index ...
>> alter table country add constraint CONSTRAINT_2E foreign key
>> (continent_id) references continent (id)
>>
>> which causes:
>>
>> > SQL [alter table country add constraint CONSTRAINT_2E foreign key
>> (continent_id) references continent (id)]; [SQLITE_ERROR] SQL error or
>> missing database (near "constraint": syntax error)
>>
>
> Can you please create an issue:
> https://github.com/jOOQ/jOOQ/issues/new/choose
>
>
>> PS: I understand that for creating the constraints inline in the create
>> table statement, the order of the tables is important.
>> And I also see that when using the DDLDatabase in the codegen there is no
>> order maintained in the generated schema class.
>> So not sure if this can work at all.
>>
>
> We can do a topological sort.
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "jOOQ User Group" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/jooq-user/At5WzUp-1Po/unsubscribe.
> To unsubscribe from this group and all its topics, 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/CAB4ELO7KcYd-2%2Br0DLvM--kzAvS1Vg9r8Y34Gm2LOx216dMJkA%40mail.gmail.com
> <https://groups.google.com/d/msgid/jooq-user/CAB4ELO7KcYd-2%2Br0DLvM--kzAvS1Vg9r8Y34Gm2LOx216dMJkA%40mail.gmail.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/CAGXs_qSHotfuuhC-nAdFwPsQB9m8cFS6vvCdTRYfxUHWkKPC6A%40mail.gmail.com.

Reply via email to