> jOOQ's type system isn't ready for such
> mapping yet, hence I'm not officially supporting these undocumented
> features.

What about:

1. A mandatory super interface for all enumerations that jOOQ can recognise:
public static interface NumberBasedEnum<V extends Enum<V>> {
    public int intValue();
    public V getEnum(int intValue);
}

2. Add a method in SQLDataType to expose creating such enum types:
public static <X extends NumberBasedEnum<?>> SQLDataType<X>
createNumberBasedEnumType(Class<X> enumClass) {
    return new SQLDataType<>(enumClass, enumClass.toString());
}

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);

Where TestEnum is an enum like I explained in my previous e-mail:

public enum TestEnum implements SQLDataType.NumberBasedEnum<TestEnum> {
    // Constructors can specify non-clashing IDs
    A,
    B,
    ;
    @Override
   public int intValue() {
        // Whatever logic to return intValue
        return ordinal();
    }
    @Override
    public TestEnum getEnum(int intValue) {
        // Whatever logic to find the enum, could be based on registry
        return values()[intValue];
    }
}

If the SQLDataType mapped Java type is a NumberBasedEnum, use that
info in jOOQ code to "intValue()" or "getEnum(intValue)".

Hope this helps,
-Christopher

Reply via email to