Yes I see. I will check out the RecordListener later then.

Btw, based on the generated classes, I wanted to see if I could generate
the DDL again from it ;-)

I came up with this:

        // Table creation statement.

        String create = ctx
                .createTable(COUNTRY)
                .columns(COUNTRY.fields())
                .constraint(primaryKey(COUNTRY.getPrimaryKey().getFields()))
                .constraints(
                        COUNTRY.getUniqueKeys().stream()
                                .map(it -> unique(it.getFields()))
                                .collect(Collectors.toList())
                )
                .constraints(
                        COUNTRY.getReferences().stream()
                                .map(it ->
foreignKey(it.getFields()).references(it.getInverseKey().getTable(),
it.getKeyFields()))
                                .collect(Collectors.toList())
                )
                .getSQL(ParamType.INLINED);

        println(create);

        COUNTRY.getIndexes().forEach((index) -> {
            String stmt = ctx
                    .createIndex(index.getName())
                    .on(index.getTable(), index.getFields())
                    .getSQL(ParamType.INLINED);

            println(stmt);
        });

As far as I could see there is no one-liner that dumps the whole table
creation including columns, constraints and indexes, right?

So above -- and especially the  getInverseKey().getTable(), in the fk -- is
a good approach, or am I missing something?


Cheers,
Marcel












On Mon, Mar 18, 2024 at 4:03 PM Lukas Eder <[email protected]> wrote:

> Hi Marcel,
>
> On Mon, Mar 18, 2024 at 3:38 PM Marcel Overdijk <[email protected]>
> wrote:
>
>> Hi Lukas, and thanks for your reply. This helps a lot.
>>
>> I used jOOQ In the past with code generation and I understand the
>> benefits especially in terms of type information and type safety.
>>
>
> Sure, I knew you were aware of it, I just point this out at every
> occasion, given there are other readers.
>
>
>> In terms of type safety, would it be possible to fail (exception) when
>> there is no default mapping available?
>>
>
> You can implement a RecordListener that fails if a record isn't entirely
> populated.  The RecordListener.loadEnd() event could help here. I don't
> think this would be a good out of the box behaviour. There's no reason to
> assume that everyone always uses 1:1 POJO to Record mappings.
>
>
>> And would there be a way to implement a RecordUnmapper where one only
>> needs to map fields that do not match automatically?
>>
>
> You can implement one that delegates to the DefaultRecordUnmapper, and
> then does some extra work on the resulting Record.
>
>
>> Or would it be better to use another tool - like MapStruct - to map from
>> Continent POJO to ContinentRecord?
>>
>
> Well, not sure what "better" means in this context. I can't recommend
> other tools because I don't know them. You'll exchange one set of problems
> for another, as I'd expect :)
>
> I hope this helps,
> Lukas
>
> --
> 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
> [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/jooq-user/CAB4ELO7Kr1duM_cyv8yRTaKC-E8-gnfw10bgiWncYjz7UjTQTQ%40mail.gmail.com
> <https://groups.google.com/d/msgid/jooq-user/CAB4ELO7Kr1duM_cyv8yRTaKC-E8-gnfw10bgiWncYjz7UjTQTQ%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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jooq-user/CAGXs_qQn2M2Si5xvYVkdm4dvEFRBzr2_m4rBYYi3mqGE0yzdVw%40mail.gmail.com.

Reply via email to