diff --git a/jOOQ/src/main/java/org/jooq/conf/Settings.java b/jOOQ/src/main/java/org/jooq/conf/Settings.java
index 3b48d77603..02de18327b 100644
--- a/jOOQ/src/main/java/org/jooq/conf/Settings.java
+++ b/jOOQ/src/main/java/org/jooq/conf/Settings.java
@@ -101,6 +101,9 @@ public class Settings
protected Boolean bindOffsetTimeType = false;
@XmlElement(defaultValue = "true")
protected Boolean fetchTriggerValuesAfterSQLServerOutput = true;
+ @XmlElement(defaultValue = "WHEN_NEEDED")
+ @XmlSchemaType(name = "string")
+ protected Transformation transformInConditionSubqueryWithLimitToDerivedTable = Transformation.WHEN_NEEDED;
@XmlElement(defaultValue = "false")
protected Boolean transformAnsiJoinToTableLists = false;
@XmlElement(defaultValue = "false")
@@ -951,6 +954,30 @@ public class Settings
this.fetchTriggerValuesAfterSQLServerOutput = value;
}
+ /**
+ * Transform a subquery from an IN condition with LIMIT to an equivalent derived table.
+ *
+ * This transformation works around a known MySQL limitation "ERROR 1235 (42000): This version of MySQL doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery'"
+ *
+ * This feature is available in the commercial distribution only.
+ *
+ */
+ public Transformation getTransformInConditionSubqueryWithLimitToDerivedTable() {
+ return transformInConditionSubqueryWithLimitToDerivedTable;
+ }
+
+ /**
+ * Transform a subquery from an IN condition with LIMIT to an equivalent derived table.
+ *
+ * This transformation works around a known MySQL limitation "ERROR 1235 (42000): This version of MySQL doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery'"
+ *
+ * This feature is available in the commercial distribution only.
+ *
+ */
+ public void setTransformInConditionSubqueryWithLimitToDerivedTable(Transformation value) {
+ this.transformInConditionSubqueryWithLimitToDerivedTable = value;
+ }
+
/**
* Transform ANSI join to table lists if possible.
*
@@ -2952,6 +2979,19 @@ public class Settings
return this;
}
+ /**
+ * Transform a subquery from an IN condition with LIMIT to an equivalent derived table.
+ *
+ * This transformation works around a known MySQL limitation "ERROR 1235 (42000): This version of MySQL doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery'"
+ *
+ * This feature is available in the commercial distribution only.
+ *
+ */
+ public Settings withTransformInConditionSubqueryWithLimitToDerivedTable(Transformation value) {
+ setTransformInConditionSubqueryWithLimitToDerivedTable(value);
+ return this;
+ }
+
public Settings withTransformAnsiJoinToTableLists(Boolean value) {
setTransformAnsiJoinToTableLists(value);
return this;
@@ -3670,6 +3710,7 @@ public class Settings
builder.append("bindOffsetDateTimeType", bindOffsetDateTimeType);
builder.append("bindOffsetTimeType", bindOffsetTimeType);
builder.append("fetchTriggerValuesAfterSQLServerOutput", fetchTriggerValuesAfterSQLServerOutput);
+ builder.append("transformInConditionSubqueryWithLimitToDerivedTable", transformInConditionSubqueryWithLimitToDerivedTable);
builder.append("transformAnsiJoinToTableLists", transformAnsiJoinToTableLists);
builder.append("transformTableListsToAnsiJoin", transformTableListsToAnsiJoin);
builder.append("transformRownum", transformRownum);
@@ -4020,6 +4061,15 @@ public class Settings
return false;
}
}
+ if (transformInConditionSubqueryWithLimitToDerivedTable == null) {
+ if (other.transformInConditionSubqueryWithLimitToDerivedTable!= null) {
+ return false;
+ }
+ } else {
+ if (!transformInConditionSubqueryWithLimitToDerivedTable.equals(other.transformInConditionSubqueryWithLimitToDerivedTable)) {
+ return false;
+ }
+ }
if (transformAnsiJoinToTableLists == null) {
if (other.transformAnsiJoinToTableLists!= null) {
return false;
@@ -4828,6 +4878,7 @@ public class Settings
result = ((prime*result)+((bindOffsetDateTimeType == null)? 0 :bindOffsetDateTimeType.hashCode()));
result = ((prime*result)+((bindOffsetTimeType == null)? 0 :bindOffsetTimeType.hashCode()));
result = ((prime*result)+((fetchTriggerValuesAfterSQLServerOutput == null)? 0 :fetchTriggerValuesAfterSQLServerOutput.hashCode()));
+ result = ((prime*result)+((transformInConditionSubqueryWithLimitToDerivedTable == null)? 0 :transformInConditionSubqueryWithLimitToDerivedTable.hashCode()));
result = ((prime*result)+((transformAnsiJoinToTableLists == null)? 0 :transformAnsiJoinToTableLists.hashCode()));
result = ((prime*result)+((transformTableListsToAnsiJoin == null)? 0 :transformTableListsToAnsiJoin.hashCode()));
result = ((prime*result)+((transformRownum == null)? 0 :transformRownum.hashCode()));
diff --git a/jOOQ/src/main/java/org/jooq/conf/Transformation.java b/jOOQ/src/main/java/org/jooq/conf/Transformation.java
new file mode 100644
index 0000000000..ab68041a6c
--- /dev/null
+++ b/jOOQ/src/main/java/org/jooq/conf/Transformation.java
@@ -0,0 +1,40 @@
+
+package org.jooq.conf;
+
+import javax.xml.bind.annotation.XmlEnum;
+import javax.xml.bind.annotation.XmlType;
+
+
+/**
+ *
Java class for Transformation.
+ *
+ *
The following schema fragment specifies the expected content contained within this class.
+ *
+ *
+ */
+@XmlType(name = "Transformation")
+@XmlEnum
+public enum Transformation {
+
+ NEVER,
+ WHEN_NEEDED,
+ ALWAYS;
+
+ public String value() {
+ return name();
+ }
+
+ public static Transformation fromValue(String v) {
+ return valueOf(v);
+ }
+
+}
diff --git a/jOOQ/src/main/java/org/jooq/impl/Cache.java b/jOOQ/src/main/java/org/jooq/impl/Cache.java
new file mode 100644
index 0000000000..eb04567801
--- /dev/null
+++ b/jOOQ/src/main/java/org/jooq/impl/Cache.java
@@ -0,0 +1,132 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Other licenses:
+ * -----------------------------------------------------------------------------
+ * Commercial licenses for this work are available. These replace the above
+ * ASL 2.0 and offer limited warranties, support, maintenance, and commercial
+ * database integrations.
+ *
+ * For more information, please visit: http://www.jooq.org/licenses
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ */
+package org.jooq.impl;
+
+import static org.jooq.tools.StringUtils.defaultIfNull;
+
+import java.io.Serializable;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.function.Supplier;
+
+import org.jooq.impl.CacheType;
+import org.jooq.Configuration;
+
+/**
+ * [#2965] This is a {@link Configuration}-based cache that can cache reflection information and other things
+ */
+final class Cache {
+
+ /**
+ * Run a cached operation in the context of a {@link Configuration}.
+ *
+ * @param configuration The configuration that may cache the outcome of
+ * the cached operation.
+ * @param operation The expensive operation.
+ * @param type The cache type to be used.
+ * @param key The cache keys.
+ * @return The cached value or the outcome of the cached operation.
+ */
+ @SuppressWarnings("unchecked")
+ static final V run(Configuration configuration, Supplier operation, CacheType type, Supplier> key) {
+
+ // If no configuration is provided take the default configuration that loads the default Settings
+ if (configuration == null)
+ configuration = new DefaultConfiguration();
+
+ // Shortcut caching when the relevant Settings flag isn't set.
+ if (!type.category.predicate.test(configuration.settings()))
+ return operation.get();
+
+ Object cacheOrNull = configuration.data(type);
+ if (cacheOrNull == null) {
+ synchronized (type) {
+ cacheOrNull = configuration.data(type);
+
+ if (cacheOrNull == null)
+ configuration.data(type, cacheOrNull = defaultIfNull(
+ configuration.cacheProvider().provide(new DefaultCacheContext(configuration, type)),
+ NULL
+ ));
+ }
+ }
+
+ if (cacheOrNull == NULL)
+ return operation.get();
+
+ // The cache is guaranteed to be thread safe by the CacheProvider
+ // contract. However since we cannot use ConcurrentHashMap.computeIfAbsent()
+ // recursively, we have to revert to double checked locking nonetheless.
+ Map