Hello Christian,
Yes, this should be possible. I suspect your marker interface should be
generic with the primary key type:
public interface PKHolder<PKType> {
PKType getPrimaryKey();
}
Now, use a generator strategy to add the interface to the "implements"
section of each relevant POJO:
http://www.jooq.org/doc/latest/manual/code-generation/codegen-generatorstrategy
There is also the possibility to add a configurative generator strategy,
but that won't be sufficient in your use-case as you probably need to
introspect the primary key type:
http://www.jooq.org/doc/latest/manual/code-generation/codegen-matcherstrategy
Now the last step is to actually implement the marker interface and the
getPrimaryKey() method. This can be done by generating a custom code
section:
http://www.jooq.org/doc/latest/manual/code-generation/codegen-custom-code
I think with the above pointers, it should be possible to achieve what you
want to do. Please, let me know if you encounter any issues or if some
detail is unclear.
Hope this helps,
Lukas
2016-06-17 19:40 GMT+01:00 Christian Meyer <[email protected]>:
> Hi,
>
> I'm trying hard to find a way to have a common getter method in generated
> POJOs, e.g. getPrimaryKey().
> The problem so far is that some tables may have a composite PK, some just
> have something like ID.
> My plan is to have a marker interface containing getPrimaryKey(). Each
> POJO implements that interface.
>
> Is there a way to archive that?
>
> Thanks,
> Christian
>
> --
> 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].
> 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 [email protected].
For more options, visit https://groups.google.com/d/optout.