(_Settings_QNAME, Settings.class, null, value);
}
diff --git a/jOOQ/src/main/java/org/jooq/conf/RenderFormatting.java b/jOOQ/src/main/java/org/jooq/conf/RenderFormatting.java
index 0a884265bc..d7e61f5434 100644
--- a/jOOQ/src/main/java/org/jooq/conf/RenderFormatting.java
+++ b/jOOQ/src/main/java/org/jooq/conf/RenderFormatting.java
@@ -33,7 +33,7 @@ public class RenderFormatting
implements Serializable, Cloneable
{
- private final static long serialVersionUID = 31000L;
+ private final static long serialVersionUID = 31100L;
@XmlElement(defaultValue = "\n")
protected String newline = "\n";
@XmlElement(defaultValue = " ")
diff --git a/jOOQ/src/main/java/org/jooq/conf/RenderMapping.java b/jOOQ/src/main/java/org/jooq/conf/RenderMapping.java
index fef3664817..c17ce43c5e 100644
--- a/jOOQ/src/main/java/org/jooq/conf/RenderMapping.java
+++ b/jOOQ/src/main/java/org/jooq/conf/RenderMapping.java
@@ -37,7 +37,7 @@ public class RenderMapping
implements Serializable, Cloneable
{
- private final static long serialVersionUID = 31000L;
+ private final static long serialVersionUID = 31100L;
protected String defaultSchema;
@XmlElementWrapper(name = "schemata")
@XmlElement(name = "schema")
diff --git a/jOOQ/src/main/java/org/jooq/conf/Settings.java b/jOOQ/src/main/java/org/jooq/conf/Settings.java
index 20a65c5459..12b89e48ab 100644
--- a/jOOQ/src/main/java/org/jooq/conf/Settings.java
+++ b/jOOQ/src/main/java/org/jooq/conf/Settings.java
@@ -34,7 +34,7 @@ public class Settings
implements Serializable, Cloneable
{
- private final static long serialVersionUID = 31000L;
+ private final static long serialVersionUID = 31100L;
@XmlElement(defaultValue = "true")
protected Boolean renderCatalog = true;
@XmlElement(defaultValue = "true")
@@ -98,6 +98,12 @@ public class Settings
protected Boolean inListPadding = false;
@XmlElement(defaultValue = ";")
protected String delimiter = ";";
+ @XmlElement(defaultValue = "LOG_DEBUG")
+ @XmlSchemaType(name = "string")
+ protected ExecuteWithoutWhere executeUpdateWithoutWhere = ExecuteWithoutWhere.LOG_DEBUG;
+ @XmlElement(defaultValue = "LOG_DEBUG")
+ @XmlSchemaType(name = "string")
+ protected ExecuteWithoutWhere executeDeleteWithoutWhere = ExecuteWithoutWhere.LOG_DEBUG;
/**
* Whether any catalog name should be rendered at all.
@@ -834,6 +840,54 @@ public class Settings
this.delimiter = value;
}
+ /**
+ * [#6771] Specifies whether UPDATE statements are allowed to be executed lacking a WHERE clause. This has no effect on rendering the statements SQL string.
+ *
+ * @return
+ * possible object is
+ * {@link ExecuteWithoutWhere }
+ *
+ */
+ public ExecuteWithoutWhere getExecuteUpdateWithoutWhere() {
+ return executeUpdateWithoutWhere;
+ }
+
+ /**
+ * Sets the value of the executeUpdateWithoutWhere property.
+ *
+ * @param value
+ * allowed object is
+ * {@link ExecuteWithoutWhere }
+ *
+ */
+ public void setExecuteUpdateWithoutWhere(ExecuteWithoutWhere value) {
+ this.executeUpdateWithoutWhere = value;
+ }
+
+ /**
+ * [#6771] Specifies whether DELETE statements are allowed to be executed lacking a WHERE clause. This has no effect on rendering the statements SQL string.
+ *
+ * @return
+ * possible object is
+ * {@link ExecuteWithoutWhere }
+ *
+ */
+ public ExecuteWithoutWhere getExecuteDeleteWithoutWhere() {
+ return executeDeleteWithoutWhere;
+ }
+
+ /**
+ * Sets the value of the executeDeleteWithoutWhere property.
+ *
+ * @param value
+ * allowed object is
+ * {@link ExecuteWithoutWhere }
+ *
+ */
+ public void setExecuteDeleteWithoutWhere(ExecuteWithoutWhere value) {
+ this.executeDeleteWithoutWhere = value;
+ }
+
public Settings withRenderCatalog(Boolean value) {
setRenderCatalog(value);
return this;
@@ -979,4 +1033,14 @@ public class Settings
return this;
}
+ public Settings withExecuteUpdateWithoutWhere(ExecuteWithoutWhere value) {
+ setExecuteUpdateWithoutWhere(value);
+ return this;
+ }
+
+ public Settings withExecuteDeleteWithoutWhere(ExecuteWithoutWhere value) {
+ setExecuteDeleteWithoutWhere(value);
+ return this;
+ }
+
}
diff --git a/jOOQ/src/main/java/org/jooq/conf/SettingsTools.java b/jOOQ/src/main/java/org/jooq/conf/SettingsTools.java
index bff4a2e8c7..63d01c9bf3 100644
--- a/jOOQ/src/main/java/org/jooq/conf/SettingsTools.java
+++ b/jOOQ/src/main/java/org/jooq/conf/SettingsTools.java
@@ -178,6 +178,22 @@ public final class SettingsTools {
return settings.getRenderMapping();
}
+ /**
+ * Lazy access to {@link Settings#getExecuteUpdateWithoutWhere()}.
+ */
+ public static final ExecuteWithoutWhere getExecuteUpdateWithoutWhere(Settings settings) {
+ ExecuteWithoutWhere result = settings.getExecuteUpdateWithoutWhere();
+ return result == null ? ExecuteWithoutWhere.LOG_DEBUG : result;
+ }
+
+ /**
+ * Lazy access to {@link Settings#getExecuteDeleteWithoutWhere()}.
+ */
+ public static final ExecuteWithoutWhere getExecuteDeleteWithoutWhere(Settings settings) {
+ ExecuteWithoutWhere result = settings.getExecuteDeleteWithoutWhere();
+ return result == null ? ExecuteWithoutWhere.LOG_DEBUG : result;
+ }
+
/**
* Retrieve the configured default settings.
*
@@ -214,7 +230,7 @@ public final class SettingsTools {
* Return timeout if it is not 0, or the specified
* {@link Settings#getQueryTimeout()}.
*/
- public static int getQueryTimeout(int timeout, Settings settings) {
+ public static final int getQueryTimeout(int timeout, Settings settings) {
return timeout != 0
? timeout
: settings.getQueryTimeout() != null
@@ -226,7 +242,7 @@ public final class SettingsTools {
* Return maxRows if it is not 0, or the specified
* {@link Settings#getMaxRows()}.
*/
- public static int getMaxRows(int maxRows, Settings settings) {
+ public static final int getMaxRows(int maxRows, Settings settings) {
return maxRows != 0
? maxRows
: settings.getMaxRows() != null
@@ -238,7 +254,7 @@ public final class SettingsTools {
* Return fetchSize if it is not 0, or the specified
* {@link Settings#getFetchSize()}.
*/
- public static int getFetchSize(int fetchSize, Settings settings) {
+ public static final int getFetchSize(int fetchSize, Settings settings) {
return fetchSize != 0
? fetchSize
: settings.getFetchSize() != null
diff --git a/jOOQ/src/main/java/org/jooq/conf/package-info.java b/jOOQ/src/main/java/org/jooq/conf/package-info.java
index cc0fa74690..d36780b4da 100644
--- a/jOOQ/src/main/java/org/jooq/conf/package-info.java
+++ b/jOOQ/src/main/java/org/jooq/conf/package-info.java
@@ -5,5 +5,5 @@
-@javax.xml.bind.annotation.XmlSchema(namespace = "http://www.jooq.org/xsd/jooq-runtime-3.9.0.xsd", elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED)
+@javax.xml.bind.annotation.XmlSchema(namespace = "http://www.jooq.org/xsd/jooq-runtime-3.11.0.xsd", elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED)
package org.jooq.conf;
diff --git a/jOOQ/src/main/java/org/jooq/impl/AbstractDMLQuery.java b/jOOQ/src/main/java/org/jooq/impl/AbstractDMLQuery.java
index 93faceb883..10177a9cd4 100644
--- a/jOOQ/src/main/java/org/jooq/impl/AbstractDMLQuery.java
+++ b/jOOQ/src/main/java/org/jooq/impl/AbstractDMLQuery.java
@@ -90,8 +90,11 @@ import org.jooq.Result;
import org.jooq.SQLDialect;
import org.jooq.Table;
import org.jooq.UpdateQuery;
+import org.jooq.conf.ExecuteWithoutWhere;
import org.jooq.conf.RenderNameStyle;
+import org.jooq.exception.DataAccessException;
import org.jooq.impl.Tools.DataKey;
+import org.jooq.tools.JooqLogger;
import org.jooq.tools.jdbc.JDBCUtils;
/**
@@ -103,6 +106,7 @@ abstract class AbstractDMLQuery extends AbstractQuery {
* Generated UID
*/
private static final long serialVersionUID = -7438014075226919192L;
+ private static final JooqLogger log = JooqLogger.getLogger(AbstractQuery.class);
@@ -314,6 +318,29 @@ abstract class AbstractDMLQuery extends AbstractQuery {
abstract void accept0(Context> ctx);
+ /**
+ * [#6771] Handle the case where a statement is executed without a WHERE clause.
+ */
+ void executeWithoutWhere(String message, ExecuteWithoutWhere executeWithoutWhere) {
+ switch (executeWithoutWhere) {
+ case IGNORE:
+ break;
+ case LOG_DEBUG:
+ if (log.isDebugEnabled())
+ log.debug(message, "A statement is executed without WHERE clause");
+ break;
+ case LOG_INFO:
+ if (log.isInfoEnabled())
+ log.info(message, "A statement is executed without WHERE clause");
+ break;
+ case LOG_WARN:
+ log.warn(message, "A statement is executed without WHERE clause");
+ break;
+ case THROW:
+ throw new DataAccessException("A statement is executed without WHERE clause");
+ }
+ }
+
final void toSQLReturning(Context> ctx) {
if (!returning.isEmpty()) {
switch (ctx.family()) {
diff --git a/jOOQ/src/main/java/org/jooq/impl/AbstractQuery.java b/jOOQ/src/main/java/org/jooq/impl/AbstractQuery.java
index 0955923c1f..8ad599c301 100644
--- a/jOOQ/src/main/java/org/jooq/impl/AbstractQuery.java
+++ b/jOOQ/src/main/java/org/jooq/impl/AbstractQuery.java
@@ -457,7 +457,7 @@ abstract class AbstractQuery extends AbstractQueryPart implements Query {
* method.
*/
@Override
- public boolean isExecutable() {
+ public /* non-final */ boolean isExecutable() {
return true;
}
diff --git a/jOOQ/src/main/java/org/jooq/impl/ConditionProviderImpl.java b/jOOQ/src/main/java/org/jooq/impl/ConditionProviderImpl.java
index d24d5b287f..9a15a975ab 100644
--- a/jOOQ/src/main/java/org/jooq/impl/ConditionProviderImpl.java
+++ b/jOOQ/src/main/java/org/jooq/impl/ConditionProviderImpl.java
@@ -64,7 +64,11 @@ final class ConditionProviderImpl extends AbstractQueryPart implements Condition
}
final Condition getWhere() {
- return condition == null ? trueCondition() : condition;
+ return hasWhere() ? condition : trueCondition();
+ }
+
+ final boolean hasWhere() {
+ return condition != null;
}
// -------------------------------------------------------------------------
@@ -88,10 +92,10 @@ final class ConditionProviderImpl extends AbstractQueryPart implements Condition
@Override
public final void addConditions(Operator operator, Condition conditions) {
- if (getWhere() instanceof TrueCondition)
- condition = conditions;
- else
+ if (hasWhere())
condition = DSL.condition(operator, getWhere(), conditions);
+ else
+ condition = conditions;
}
@Override
diff --git a/jOOQ/src/main/java/org/jooq/impl/DeleteQueryImpl.java b/jOOQ/src/main/java/org/jooq/impl/DeleteQueryImpl.java
index 649cecf043..c434db744c 100644
--- a/jOOQ/src/main/java/org/jooq/impl/DeleteQueryImpl.java
+++ b/jOOQ/src/main/java/org/jooq/impl/DeleteQueryImpl.java
@@ -41,6 +41,7 @@ import static org.jooq.Clause.DELETE_RETURNING;
import static org.jooq.Clause.DELETE_WHERE;
import static org.jooq.SQLDialect.MARIADB;
import static org.jooq.SQLDialect.MYSQL;
+import static org.jooq.conf.SettingsTools.getExecuteDeleteWithoutWhere;
import static org.jooq.impl.Keywords.K_DELETE;
import static org.jooq.impl.Keywords.K_FROM;
import static org.jooq.impl.Keywords.K_WHERE;
@@ -79,6 +80,10 @@ final class DeleteQueryImpl extends AbstractDMLQuery implem
return condition.getWhere();
}
+ final boolean hasWhere() {
+ return condition.hasWhere();
+ }
+
@Override
public final void addConditions(Collection extends Condition> conditions) {
condition.addConditions(conditions);
@@ -133,11 +138,10 @@ final class DeleteQueryImpl extends AbstractDMLQuery implem
.end(DELETE_DELETE)
.start(DELETE_WHERE);
- if (!(getWhere() instanceof TrueCondition)) {
+ if (hasWhere())
ctx.formatSeparator()
.visit(K_WHERE).sql(' ')
.visit(getWhere());
- }
ctx.end(DELETE_WHERE)
.start(DELETE_RETURNING);
@@ -151,4 +155,14 @@ final class DeleteQueryImpl extends AbstractDMLQuery implem
public final Clause[] clauses(Context> ctx) {
return CLAUSES;
}
+
+ @Override
+ public final boolean isExecutable() {
+
+ // [#6771] Take action when DELETE query has no WHERE clause
+ if (!condition.hasWhere())
+ executeWithoutWhere("DELETE without WHERE", getExecuteDeleteWithoutWhere(configuration().settings()));
+
+ return super.isExecutable();
+ }
}
diff --git a/jOOQ/src/main/java/org/jooq/impl/InsertQueryImpl.java b/jOOQ/src/main/java/org/jooq/impl/InsertQueryImpl.java
index 876891c933..39ecaa84e5 100644
--- a/jOOQ/src/main/java/org/jooq/impl/InsertQueryImpl.java
+++ b/jOOQ/src/main/java/org/jooq/impl/InsertQueryImpl.java
@@ -276,7 +276,7 @@ final class InsertQueryImpl extends AbstractStoreQuery impl
.visit(updateMap)
.formatIndentLockEnd();
- if (!(condition.getWhere() instanceof TrueCondition))
+ if (condition.hasWhere())
ctx.formatSeparator()
.visit(K_WHERE)
.sql(' ')
diff --git a/jOOQ/src/main/java/org/jooq/impl/SelectQueryImpl.java b/jOOQ/src/main/java/org/jooq/impl/SelectQueryImpl.java
index e795106969..2aa7575dfc 100644
--- a/jOOQ/src/main/java/org/jooq/impl/SelectQueryImpl.java
+++ b/jOOQ/src/main/java/org/jooq/impl/SelectQueryImpl.java
@@ -1220,7 +1220,7 @@ final class SelectQueryImpl extends AbstractResultQuery imp
// ------------
context.start(SELECT_WHERE);
- if (getWhere().getWhere() instanceof TrueCondition && semiAntiJoinPredicates == null)
+ if (!getWhere().hasWhere() && semiAntiJoinPredicates == null)
;
else {
ConditionProviderImpl where = new ConditionProviderImpl();
@@ -1228,7 +1228,7 @@ final class SelectQueryImpl extends AbstractResultQuery imp
if (semiAntiJoinPredicates != null)
where.addConditions(semiAntiJoinPredicates);
- if (!(getWhere().getWhere() instanceof TrueCondition))
+ if (getWhere().hasWhere())
where.addConditions(getWhere());
context.formatSeparator()
@@ -1247,23 +1247,21 @@ final class SelectQueryImpl extends AbstractResultQuery imp
// syntax
context.start(SELECT_START_WITH);
- if (!(getConnectByStartWith().getWhere() instanceof TrueCondition)) {
+ if (getConnectByStartWith().hasWhere())
context.formatSeparator()
.visit(K_START_WITH)
.sql(' ')
.visit(getConnectByStartWith());
- }
context.end(SELECT_START_WITH);
context.start(SELECT_CONNECT_BY);
- if (!(getConnectBy().getWhere() instanceof TrueCondition)) {
+ if (getConnectBy().hasWhere()) {
context.formatSeparator()
.visit(K_CONNECT_BY);
- if (connectByNoCycle) {
+ if (connectByNoCycle)
context.sql(' ').visit(K_NOCYCLE);
- }
context.sql(' ').visit(getConnectBy());
}
@@ -1315,12 +1313,11 @@ final class SelectQueryImpl extends AbstractResultQuery imp
// -------------
context.start(SELECT_HAVING);
- if (!(getHaving().getWhere() instanceof TrueCondition)) {
+ if (getHaving().hasWhere())
context.formatSeparator()
.visit(K_HAVING)
.sql(' ')
.visit(getHaving());
- }
context.end(SELECT_HAVING);
diff --git a/jOOQ/src/main/java/org/jooq/impl/UpdateQueryImpl.java b/jOOQ/src/main/java/org/jooq/impl/UpdateQueryImpl.java
index 42daa7e110..fbe0b1e18b 100644
--- a/jOOQ/src/main/java/org/jooq/impl/UpdateQueryImpl.java
+++ b/jOOQ/src/main/java/org/jooq/impl/UpdateQueryImpl.java
@@ -46,6 +46,7 @@ import static org.jooq.Clause.UPDATE_WHERE;
// ...
import static org.jooq.SQLDialect.POSTGRES_10;
// ...
+import static org.jooq.conf.SettingsTools.getExecuteUpdateWithoutWhere;
import static org.jooq.impl.DSL.select;
import static org.jooq.impl.Keywords.K_FROM;
import static org.jooq.impl.Keywords.K_ROW;
@@ -495,6 +496,10 @@ final class UpdateQueryImpl extends AbstractStoreQuery impl
return condition.getWhere();
}
+ final boolean hasWhere() {
+ return condition.hasWhere();
+ }
+
@Override
final void accept0(Context> ctx) {
boolean declareTables = ctx.declareTables();
@@ -616,11 +621,10 @@ final class UpdateQueryImpl extends AbstractStoreQuery impl
ctx.start(UPDATE_WHERE);
- if (!(getWhere() instanceof TrueCondition)) {
+ if (hasWhere())
ctx.formatSeparator()
.visit(K_WHERE).sql(' ')
.visit(getWhere());
- }
ctx.end(UPDATE_WHERE)
.start(UPDATE_RETURNING);
@@ -637,6 +641,11 @@ final class UpdateQueryImpl extends AbstractStoreQuery impl
@Override
public final boolean isExecutable() {
+
+ // [#6771] Take action when UPDATE query has no WHERE clause
+ if (!condition.hasWhere())
+ executeWithoutWhere("UPDATE without WHERE", getExecuteUpdateWithoutWhere(configuration().settings()));
+
return updateMap.size() > 0 || multiRow != null;
}
}
diff --git a/jOOQ/src/main/resources/xjb/runtime/binding.xjb b/jOOQ/src/main/resources/xjb/runtime/binding.xjb
index a79ea9ca35..b4cbf92d10 100644
--- a/jOOQ/src/main/resources/xjb/runtime/binding.xjb
+++ b/jOOQ/src/main/resources/xjb/runtime/binding.xjb
@@ -12,16 +12,16 @@
-
+
-
+
-
+
org.jooq.conf.SettingsBase
java.lang.Cloneable
diff --git a/jOOQ/src/main/resources/xsd/jooq-runtime-3.11.0.xsd b/jOOQ/src/main/resources/xsd/jooq-runtime-3.11.0.xsd
new file mode 100644
index 0000000000..96079a347c
--- /dev/null
+++ b/jOOQ/src/main/resources/xsd/jooq-runtime-3.11.0.xsd
@@ -0,0 +1,432 @@
+
+
+
+
+
+
+
+
+
+
+Use this for single-catalog environments, or when all objects are made
+available using synonyms]]>
+
+
+
+
+Setting this to false also implicitly sets "renderCatalog" to false.
+
+Use this for single-schema environments, or when all objects are made
+available using synonyms]]>
+
+
+
+
+
+
+
+
+This is set to "QUOTED" by default for backwards-compatibility]]>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Oracle 11g (and potentially, other databases too) implements scalar subquery caching. With this flag
+set to true, users can automatically profit from this feature in all SQL statements.]]>
+
+
+
+
+
+
+
+
+Possibilities include:
+
+- question marks
+- named parameters
+- named or inlined parameters
+- inlined parameters
+
+This value is overridden by statementType == STATIC_STATEMENT, in
+case of which, this defaults to INLINED]]>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+This flag has no effect when "executeWithOptimisticLocking" is turned off.]]>
+
+
+
+
+
+
+
+
+Setting this to "true" will allow for updating primary key values through
+UpdatableRecord.store() and UpdatableRecord.update().]]>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Do note that only few databases support this feature. It is supported only in case the INSERT's or UPDATE's
+RETURNING clause is fully supported, also for non-IDENTITY columns.]]>
+
+
+
+ is active, also other values.]]>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+This schema will be omitted in rendered SQL.]]>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Either <input/> or <inputExpression/> must be provided]]>
+
+
+
+ or <inputExpression/> must be provided]]>
+
+
+
+
+When this is omitted, you can still apply table mapping.
+When <input/> is provided, <output/> is a constant value.
+When <inputExpression/> is provided, <output/> is a replacement expression
+]]>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ or <inputExpression/> must be provided.]]>
+
+
+
+ or <inputExpression/> must be provided]]>
+
+
+
+
+When <input/> is provided, <output/> is a constant value.
+When <inputExpression/> is provided, <output/> is a replacement expression.
+]]>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file