Hello,

I'm changing parts of my code to remove magic numbers. I used Java enums 
for that - which make the code nice and clean.
Some enum classes use more advanced features - like conversions methods, a 
custom toString method etc.
Now it comes to the time to map these to the database in especially to jooq.
I've wanted to use codegen for all steps - but failed - I got following 
enum class:

> public enum Visibility {
>     PUBLIC("visibilitylist.public"), UNLISTED("visibilitylist.unlisted"), 
> PRIVATE("visibilitylist.private"), SCHEDULED(
>             "visibilitylist.scheduled");
>
>     private String    i18n;
>
>     private Visibility(final String i18n) {
>         this.i18n = i18n;
>     }
>
>     @Override
>     public String toString() {
>         return TextUtil.getString(i18n);
>     }
> }
>
The data should be stored as string in the database. I've already wanted to 
use / write my own Converter implementation for this, but the documentation 
references "EnumConverter" class but I didn't get it working:
I've tried:

public VisibilityConverter extends EnumConverter<String, Visibility>  { }
>

However this forces me to create a constructor and then it's impossible to 
use this with default codegen. 
I then tried to register just the EnumConverter - which failed again.
I don't want to create any new table for the enums - they should just be 
mapped to.

Could you show me a short example how to use EnumConverter properly?

For the codegen I used described registration:

>         <customType>
>                     <name>....Visibility</name>
>                     <converter>....VisibilityConverter</converter>
>                 </customType>
>
.... 

> <forcedType>
>                     <name>....Visibility</name>
>                     <expressions>.*\.VISIBILITY</expressions>
>                 </forcedType> 
>

Regards,
Dennis 

-- 
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/groups/opt_out.


Reply via email to