> What about: > > 1. A mandatory super interface for all enumerations that jOOQ can recognise:
That would be EnumType, then: http://www.jooq.org/javadoc/latest/org/jooq/EnumType.html > public static interface NumberBasedEnum<V extends Enum<V>> { > public int intValue(); > public V getEnum(int intValue); > } I think, intValue() would have to be generic...: public interface EnumType<T> { public T getLiteral(); // The existing literal corresponds to intValue() } public V getEnum() would have to be made static and moved to some registry. It doesn't make sense in an interface, I think. > 2. Add a method in SQLDataType to expose creating such enum types: That would correspond to DataType.asEnumDataType(): http://www.jooq.org/javadoc/latest/org/jooq/DataType.html#asEnumDataType%28java.lang.Class%29 > 3. Generate a field with that type according to some user > configuration (or at least user can create its own generator): > public final org.jooq.TableField<test.generated.tables.records.SomeEnum, > TestEnum> SOMEENUM = createField("SomeEnum", > SQLDataType.createNumberBasedEnumType(TestEnum.class), this); You're a magician! That would then correspond to that aforementioned undocumented feature! Check out <enumTypes/> and <forcedTypes/> tags in jOOQ 2.0.4's code generation configuration: http://www.jooq.org/xsd/jooq-codegen-2.0.4.xsd > Hope this helps, Well... :-) Seeing that you have very similar ideas is promising, as I am probably on the right track with this existing undocumented feature. These are the missing things: - The "base type" for jOOQ's EnumType is lost, i.e. the synthetic EnumType has no reference to its original DataType or to the generic type <T>. This means, only VARCHAR enum types work right now (and some others in lenient, "forgiving" databases) - EnumType only knows its "literal". There is currently now way to add another "synthetic index" as you and Pay propose. Cheers Lukas PS: For further reference, this was the original discussion that lead to these features: https://groups.google.com/forum/#!topic/jooq-user/AC4ZbtBIQ6A/discussion
