diff --git a/jOOQ/src/main/java/org/jooq/conf/Settings.java b/jOOQ/src/main/java/org/jooq/conf/Settings.java index 9c634d9b3d..0eef7284ed 100644 --- a/jOOQ/src/main/java/org/jooq/conf/Settings.java +++ b/jOOQ/src/main/java/org/jooq/conf/Settings.java @@ -527,6 +527,9 @@ public class Settings protected WriteIfReadonly readonlyUpdate = WriteIfReadonly.IGNORE; @XmlElement(defaultValue = "true") protected Boolean applyWorkaroundFor7962 = true; + @XmlElement(defaultValue = "LOG_WARN") + @XmlSchemaType(name = "string") + protected Warning warnOnStaticTypeRegistryAccess = Warning.LOG_WARN; @XmlElementWrapper(name = "interpreterSearchPath") @XmlElement(name = "schema") protected List interpreterSearchPath; @@ -5952,6 +5955,22 @@ public class Settings this.applyWorkaroundFor7962 = value; } + /** + * [#15286] The warning level when the deprecated static type registry was accessed by legacy code. + * + */ + public Warning getWarnOnStaticTypeRegistryAccess() { + return warnOnStaticTypeRegistryAccess; + } + + /** + * [#15286] The warning level when the deprecated static type registry was accessed by legacy code. + * + */ + public void setWarnOnStaticTypeRegistryAccess(Warning value) { + this.warnOnStaticTypeRegistryAccess = value; + } + public List getInterpreterSearchPath() { if (interpreterSearchPath == null) { interpreterSearchPath = new ArrayList(); @@ -7519,6 +7538,15 @@ public class Settings return this; } + /** + * [#15286] The warning level when the deprecated static type registry was accessed by legacy code. + * + */ + public Settings withWarnOnStaticTypeRegistryAccess(Warning value) { + setWarnOnStaticTypeRegistryAccess(value); + return this; + } + public Settings withInterpreterSearchPath(InterpreterSearchSchema... values) { if (values!= null) { for (InterpreterSearchSchema value: values) { @@ -7802,6 +7830,7 @@ public class Settings builder.append("readonlyInsert", readonlyInsert); builder.append("readonlyUpdate", readonlyUpdate); builder.append("applyWorkaroundFor7962", applyWorkaroundFor7962); + builder.append("warnOnStaticTypeRegistryAccess", warnOnStaticTypeRegistryAccess); builder.append("interpreterSearchPath", "schema", interpreterSearchPath); builder.append("migrationSchemata", "schema", migrationSchemata); builder.append("parseSearchPath", "schema", parseSearchPath); @@ -9788,6 +9817,15 @@ public class Settings return false; } } + if (warnOnStaticTypeRegistryAccess == null) { + if (other.warnOnStaticTypeRegistryAccess!= null) { + return false; + } + } else { + if (!warnOnStaticTypeRegistryAccess.equals(other.warnOnStaticTypeRegistryAccess)) { + return false; + } + } if (interpreterSearchPath == null) { if (other.interpreterSearchPath!= null) { return false; @@ -10040,6 +10078,7 @@ public class Settings result = ((prime*result)+((readonlyInsert == null)? 0 :readonlyInsert.hashCode())); result = ((prime*result)+((readonlyUpdate == null)? 0 :readonlyUpdate.hashCode())); result = ((prime*result)+((applyWorkaroundFor7962 == null)? 0 :applyWorkaroundFor7962 .hashCode())); + result = ((prime*result)+((warnOnStaticTypeRegistryAccess == null)? 0 :warnOnStaticTypeRegistryAccess.hashCode())); result = ((prime*result)+((interpreterSearchPath == null)? 0 :interpreterSearchPath.hashCode())); result = ((prime*result)+((migrationSchemata == null)? 0 :migrationSchemata.hashCode())); result = ((prime*result)+((parseSearchPath == null)? 0 :parseSearchPath.hashCode())); diff --git a/jOOQ/src/main/java/org/jooq/conf/Warning.java b/jOOQ/src/main/java/org/jooq/conf/Warning.java new file mode 100644 index 0000000000..55bffde2a7 --- /dev/null +++ b/jOOQ/src/main/java/org/jooq/conf/Warning.java @@ -0,0 +1,43 @@ + +package org.jooq.conf; + +import jakarta.xml.bind.annotation.XmlEnum; +import jakarta.xml.bind.annotation.XmlType; + + +/** + *

Java class for Warning. + * + *

The following schema fragment specifies the expected content contained within this class. + *

+ * <simpleType name="Warning">
+ *   <restriction base="{http://www.w3.org/2001/XMLSchema}string">
+ *     <enumeration value="IGNORE"/>
+ *     <enumeration value="LOG_DEBUG"/>
+ *     <enumeration value="LOG_INFO"/>
+ *     <enumeration value="LOG_WARN"/>
+ *     <enumeration value="THROW"/>
+ *   </restriction>
+ * </simpleType>
+ * 
+ * + */ +@XmlType(name = "Warning") +@XmlEnum +public enum Warning { + + IGNORE, + LOG_DEBUG, + LOG_INFO, + LOG_WARN, + THROW; + + public String value() { + return name(); + } + + public static Warning fromValue(String v) { + return valueOf(v); + } + +} diff --git a/jOOQ/src/main/java/org/jooq/impl/DefaultDataType.java b/jOOQ/src/main/java/org/jooq/impl/DefaultDataType.java index 553015e064..29bea197e2 100644 --- a/jOOQ/src/main/java/org/jooq/impl/DefaultDataType.java +++ b/jOOQ/src/main/java/org/jooq/impl/DefaultDataType.java @@ -118,6 +118,7 @@ import org.jooq.exception.SQLDialectNotSupportedException; import org.jooq.impl.DefaultBinding.InternalBinding; import org.jooq.impl.QOM.GenerationLocation; import org.jooq.impl.QOM.GenerationOption; +import org.jooq.tools.JooqLogger; import org.jooq.types.UByte; import org.jooq.types.UInteger; import org.jooq.types.ULong; @@ -793,7 +794,26 @@ public class DefaultDataType extends AbstractDataTypeX { return getDataType(dialect, type, null); } + private static final JooqLogger getDataType = JooqLogger.getLogger(DefaultDataType.class, "getDataType", 5); + private static final class DiscouragedStaticTypeRegistryUsage extends RuntimeException {} + public static final DataType getDataType(SQLDialect dialect, Class type, DataType fallbackDataType) { + return check(getDataType0(dialect, type, fallbackDataType)); + } + + private static final DataType check(DataType 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 references from Class references by relying on the internal static type registry. See https://github.com/jOOQ/jOOQ/issues/15286 for details.", new DiscouragedStaticTypeRegistryUsage()); + + if (result instanceof ArrayDataType a) + check(a.elementType); + + return result; + } + + private static final DataType getDataType0(SQLDialect dialect, Class type, DataType fallbackDataType) { // Treat primitive types the same way as their respective wrapper types type = wrapper(type); diff --git a/jOOQ/src/main/resources/org/jooq/xsd/jooq-runtime-3.19.0.xsd b/jOOQ/src/main/resources/org/jooq/xsd/jooq-runtime-3.19.0.xsd index e9df5b7fe6..9690fa9c80 100644 --- a/jOOQ/src/main/resources/org/jooq/xsd/jooq-runtime-3.19.0.xsd +++ b/jOOQ/src/main/resources/org/jooq/xsd/jooq-runtime-3.19.0.xsd @@ -1605,6 +1605,10 @@ inside of queries (including procedural statements) are still not supported.]]>< + + + + @@ -2082,6 +2086,26 @@ Either <input/> or <inputExpression/> must be provided]]> + + + + + + + + + + + + + + + + + + + +