I am working with a database that handles null values very poorly. Instead of using nullable strings, I want to use a fixed, very rare value (essentially a UUID) as a placeholder for null.
My goal is to use Optional instead of String for fields in Java, and whenever I bind an Optional.empty() to an INSERT INTO statement, I want jOOQ to automatically convert this to my UUID that I use as a flag for an empty optional. When the optional has a value, I want jOOQ to use the provided value as usual.
I tried setting up a converter, but it only seems to work during SELECT operations and not during the insertion phase. I suspect I might be missing something.
Here is what I have so far:
package com.res.jooq.neo4j;
public class Neo4jOptionalUtils {
public static final String EMPTY_STRING = "empty-string-optional-ac4ea8cd-9128-4ee3-bb2c-48a1c239ffd2";
private Neo4jOptionalUtils() {
// private constructor to hide the implicit public one
}
public static String optional(String value) {
return value == null ? EMPTY_STRING : value;
}
public static String fromOptional(String optional) {
return EMPTY_STRING.equals(optional) ? null : optional;
}
}
I am using this utility class to convert null values to my fixed UUID and vice versa.
How can I configure jOOQ to apply this conversion automatically during INSERT operations?
Is there a way to ensure that both SELECT and INSERT operations respect this conversion logic without manually converting each value?