Hello Pay,
> Let me think how to describe that use-case....
>
> my running project is presented by java web. Sometime, I need to pass param
> by ID in POST or GET Data. [...]
I understand.
> I'm used to create this kind of reverse function inside ENUM Class.
> Otherwise, for the Enum class from JOOQ, I'd create an utility class for
> looking up the ID of enum type.
I'd favour this solution over code generation for this specific case.
Right now, you can do this:
MyPriorityLevel.values()[index - 1]
But you probably want some fail-safety for wrong indexes and some null
handling. So what do you think about this implementation in
org.jooq.util.mysql.MySQLFactory:
------------------------------------------------
public static <E extends java.lang.Enum<E> & org.jooq.EnumType> E
enumType(Class<E> type, int index) {
if (index <= 0) {
return null;
}
E[] values = type.getEnumConstants();
if (index > values.length) {
return null;
}
return values[index - 1];
}
------------------------------------------------
Another option might be to consider Minuteproject for source code
generation. It has some nice enhancement for enums too:
http://minuteproject.wikispaces.com/JOOQ#toc8
This is a third-party product that has started to integrate with jOOQ
recently. You'd be a beta tester :-)
Cheers
Lukas