We have a fairly common forwards-compatibility scenario that makes using 
enums problematic: loading unknown enum values results in an exception 
during loading.

These "unknown" enum values are just values written by "future" versions of 
our application.

In cases where it really matters, we use feature flagging to ensure such 
values don't get written until old versions of the application are 
shutdown. 

However, there are many cases where we'd really just like the unknown value 
to be loaded as "unknown", and not cause loading to fail.

Of course, we can always handle "enums" by just treating them as strings, 
but that approach loses out on type safety in Java/Scala and schema 
validation in the database.

A couple of alternate approaches I've been wondering about:

1. Load/store enums as Either<Integer, EnumType> or Either<String, 
EnumType> (depending on the underlying database enum type). This approach 
allows the client to inspect the unknown value if need be, round-trip it, 
or pass it along if it doesn't really need to know about the enum values.

2. Map unknown enum values to a customizable UNKNOWN enum value. This could 
be built into jOOQ generated enum types, and configurable for 
user-generated enum types. This approach wouldn't allow for client 
inspection of the unknown value, or passing it along, or round tripping - 
store operations would have to fail when trying to store such an unknown 
value.

Looking for some feedback on those approaches, and whether they can be 
implemented in jOOQ 3.10 through customization, and whether some variation 
of the above might make sense to be built into jOOQ?

Thanks!

-- 
This e-mail message is intended for the named recipient(s) above, and may 
contain information that is privileged, confidential and/or exempt from 
disclosure under applicable law. If you have received this message in 
error, or are not the named recipient(s), please do not read the content. 
Instead, immediately notify the sender and delete this e-mail message. Any 
unauthorized use, disclosure or distribution is strictly prohibited. 
Quantify Labs Inc and the sender assume no responsibility for any errors, 
omissions, or readers' misinterpretations and/ or understanding of the 
content or transmission of this email.

-- 
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/d/optout.

Reply via email to