[jOOQ/jOOQ#16425] [jOOQ/jOOQ#16090] Static registry warning improvements

This includes:

- [jOOQ/jOOQ#8517] Row[N].eq(Row[N]) should apply data type bindings if necessary
- [jOOQ/jOOQ#16090] Unnecessary static type registry warning when inlining custom converted enum value
- [jOOQ/jOOQ#16425] Static type registry deprecation warning shouldn't appear when using the INSERT valuesOfRows() clause with converted data types
This commit is contained in:
Lukas Eder 2024-03-11 11:32:00 +01:00
parent 1338a28c75
commit 88d3dc3cb1
3 changed files with 37 additions and 8 deletions

View File

@ -45,6 +45,7 @@ import static org.jooq.impl.Names.N_ROW;
import static org.jooq.impl.QueryPartListView.wrap;
import static org.jooq.impl.Tools.extractVal;
import static org.jooq.impl.Tools.isVal;
import static org.jooq.impl.Tools.isVal1;
import static org.jooq.impl.Tools.nullSafe;
import java.util.Collection;
@ -224,7 +225,8 @@ implements
findConversionCandidates: {
for (int i = 0; i < size; i++)
if (isVal(fields.field(i)) && !isVal(row.field(i)))
if (isVal1(fields.field(i), v -> v.inferredDataType)
&& !isVal1(row.field(i), v -> v.inferredDataType))
break findConversionCandidates;
return this;
@ -233,10 +235,12 @@ implements
Field<?>[] result = new Field[size];
for (int i = 0; i < size; i++) {
Field<?> f = fields.field(i);
Val<?> v;
Val<?> val;
if ((v = extractVal(f)) != null)
result[i] = v.convertTo(row.field(i).getDataType());
if (isVal1(fields.field(i), v -> v.inferredDataType)
&& !isVal1(row.field(i), v -> v.inferredDataType)
&& (val = extractVal(f)) != null)
result[i] = val.convertTo(row.field(i).getDataType());
else
result[i] = f;
}

View File

@ -843,14 +843,34 @@ public class DefaultDataType<T> extends AbstractDataTypeX<T> {
private static final class DiscouragedStaticTypeRegistryUsage extends RuntimeException {}
public static final <T> DataType<T> getDataType(SQLDialect dialect, Class<T> type, DataType<T> fallbackDataType) {
return check(getDataType0(dialect, type, fallbackDataType));
return getDataType0(dialect, type, fallbackDataType);
}
private static final <T> DataType<T> check(DataType<T> result) {
static final <T> DataType<T> check(DataType<T> result) {
// [#5713] [#15286] TODO: Move this to a dynamic type registry and make warning configurable
if (result instanceof ConvertedDataType || result instanceof LegacyConvertedDataType)
getDataType.warn("Static type registry", "The deprecated static type registry was being accessed for a non-built-in data type: " + result + ". It is strongly recommended not looking up DataType<T> references from Class<T> references by relying on the internal static type registry. See https://github.com/jOOQ/jOOQ/issues/15286 for details.", new DiscouragedStaticTypeRegistryUsage());
if (result instanceof LegacyConvertedDataType) {
DiscouragedStaticTypeRegistryUsage e = new DiscouragedStaticTypeRegistryUsage();
getDataType.warn("Static type registry", """
The deprecated static type registry was being accessed for a non-built-in data type: {result}.
It is strongly recommended not looking up DataType<T> references from Class<T> references by
relying on the internal static type registry. For example, avoid calling DSL.val(Object) or
DSL.val(Object, Class), and call DSL.val(Object, DataType), providing an explicit DataType
reference to jOOQ if your DataType uses a Converter or a Binding. If you think jOOQ should
be able to infer your user type in your particular query, please report a bug here:
https://jooq.org/bug
See https://github.com/jOOQ/jOOQ/issues/15286 for more details.
""".replace("{result}", "" + result), e);
// [#16090] [#16425]
// An undocumented flag to throw the logged exception to help with faster fixing of this problem
// Users should not rely on this flag as it may be removed without announcement when it isn't needed anymore.
if ("true".equals(System.getProperty("org.jooq.throw-on-discouraged-static-type-registry-access")))
throw e;
}
if (result instanceof ArrayDataType<?> a)
check(a.elementType);

View File

@ -177,6 +177,11 @@ final class Val<T> extends AbstractParam<T> implements UEmpty {
@Override
public void accept(Context<?> ctx) {
// [#16090] [#16425] Inferred user types shouldn't rely on static type registry
if (inferredDataType)
DefaultDataType.check(getDataType());
if (getDataType().isEmbeddable()) {
// TODO [#12021] [#12706] ROW must consistently follow MULTISET emulation