I'd like to make our JOOQ records more typesafe. For example, I'd like the BIGINT
fields CUSTOMER.ID
and ORDER.CUSTOMER_ID
to be of type CustomerNo
instead of just Long
.
I can force JOOQ's code generator generate the correct fields using a combination of customType
forcedType
:
public final TableField<CustomerRecord, CustomerNo> ID =
createField("ID", SQLDataType.BIGINT.asConvertedDataType(new CustomerNoConverter()), this);
public final TableField<OrderRecord, CustomerNo> CUSTOMER_ID =
createField("CUSTOMER_ID", SQLDataType.BIGINT.asConvertedDataType(new CustomerNoConverter()), this);
However, that's not enough. For every single-field primary key of type Long
, I need to create two classes, i.e. equivalents of CustomerNo
and CustomerNoConverter
. Of course, the most convenient way to do this is to use the JOOQ meta-model to loop over any such fields and generate the code for each of them.
Since the JOOQ model itself depends upon the to-be-generated classes, I will need to hook into JOOQ's code generator. However, I was unable to find a suitable callback mechanism for this task. How could I approach this problem?