From f98c2f855dec5a81de2bace3c1b01a06204c6d38 Mon Sep 17 00:00:00 2001 From: lukaseder Date: Thu, 25 Oct 2018 15:58:19 +0200 Subject: [PATCH] [#7966] Add Setting to turn off fetching generated keys from UpdatableRecord --- .../resources/org/jooq/web/manual-3.12.xml | 30 +++++++++++- .../src/main/java/org/jooq/conf/Settings.java | 46 +++++++++++++++++++ .../java/org/jooq/impl/TableRecordImpl.java | 6 ++- .../resources/xsd/jooq-runtime-3.12.0.xsd | 4 ++ 4 files changed, 84 insertions(+), 2 deletions(-) diff --git a/jOOQ-manual/src/main/resources/org/jooq/web/manual-3.12.xml b/jOOQ-manual/src/main/resources/org/jooq/web/manual-3.12.xml index 3a96ac2d95..996db8bc7c 100644 --- a/jOOQ-manual/src/main/resources/org/jooq/web/manual-3.12.xml +++ b/jOOQ-manual/src/main/resources/org/jooq/web/manual-3.12.xml @@ -3979,11 +3979,39 @@ author.store(); // The behaviour of this store call is governed by the updatable +
+ Return Identity Value On Store + +

+ When using the , jOOQ by default fetches the generated . +

+ +

+ In some situations, it is desirable for this feature to be turned off using the following flag: +

+ +

+ Programmatic configuration +

+ + + +

+ XML configuration +

+ + + false +]]> +
+
+
Return All Columns On Store

- When using the , jOOQ always fetches the generated , if such a value is available. + When using the , jOOQ always fetches the generated , if such a value is available and if feature is enabled (it is, by default).

diff --git a/jOOQ/src/main/java/org/jooq/conf/Settings.java b/jOOQ/src/main/java/org/jooq/conf/Settings.java index 52ab0c0d9e..92805cb7c5 100644 --- a/jOOQ/src/main/java/org/jooq/conf/Settings.java +++ b/jOOQ/src/main/java/org/jooq/conf/Settings.java @@ -91,6 +91,8 @@ public class Settings protected Boolean fetchWarnings = true; @XmlElement(defaultValue = "0") protected Integer fetchServerOutputSize = 0; + @XmlElement(defaultValue = "true") + protected Boolean returnIdentityOnUpdatableRecord = true; @XmlElement(defaultValue = "false") protected Boolean returnAllOnUpdatableRecord = false; @XmlElement(defaultValue = "true") @@ -751,6 +753,30 @@ public class Settings this.fetchServerOutputSize = value; } + /** + * Whether calls to store(), insert() and update() should return the identity column. + * + * @return + * possible object is + * {@link Boolean } + * + */ + public Boolean isReturnIdentityOnUpdatableRecord() { + return returnIdentityOnUpdatableRecord; + } + + /** + * Sets the value of the returnIdentityOnUpdatableRecord property. + * + * @param value + * allowed object is + * {@link Boolean } + * + */ + public void setReturnIdentityOnUpdatableRecord(Boolean value) { + this.returnIdentityOnUpdatableRecord = value; + } + /** * Whether calls to store(), insert() and update() should return all columns, not just identity columns. *

@@ -1312,6 +1338,11 @@ public class Settings return this; } + public Settings withReturnIdentityOnUpdatableRecord(Boolean value) { + setReturnIdentityOnUpdatableRecord(value); + return this; + } + public Settings withReturnAllOnUpdatableRecord(Boolean value) { setReturnAllOnUpdatableRecord(value); return this; @@ -1525,6 +1556,11 @@ public class Settings sb.append(fetchServerOutputSize); sb.append(""); } + if (returnIdentityOnUpdatableRecord!= null) { + sb.append(""); + sb.append(returnIdentityOnUpdatableRecord); + sb.append(""); + } if (returnAllOnUpdatableRecord!= null) { sb.append(""); sb.append(returnAllOnUpdatableRecord); @@ -1846,6 +1882,15 @@ public class Settings return false; } } + if (returnIdentityOnUpdatableRecord == null) { + if (other.returnIdentityOnUpdatableRecord!= null) { + return false; + } + } else { + if (!returnIdentityOnUpdatableRecord.equals(other.returnIdentityOnUpdatableRecord)) { + return false; + } + } if (returnAllOnUpdatableRecord == null) { if (other.returnAllOnUpdatableRecord!= null) { return false; @@ -2039,6 +2084,7 @@ public class Settings result = ((prime*result)+((throwExceptions == null)? 0 :throwExceptions.hashCode())); result = ((prime*result)+((fetchWarnings == null)? 0 :fetchWarnings.hashCode())); result = ((prime*result)+((fetchServerOutputSize == null)? 0 :fetchServerOutputSize.hashCode())); + result = ((prime*result)+((returnIdentityOnUpdatableRecord == null)? 0 :returnIdentityOnUpdatableRecord.hashCode())); result = ((prime*result)+((returnAllOnUpdatableRecord == null)? 0 :returnAllOnUpdatableRecord.hashCode())); result = ((prime*result)+((returnRecordToPojo == null)? 0 :returnRecordToPojo.hashCode())); result = ((prime*result)+((mapJPAAnnotations == null)? 0 :mapJPAAnnotations.hashCode())); diff --git a/jOOQ/src/main/java/org/jooq/impl/TableRecordImpl.java b/jOOQ/src/main/java/org/jooq/impl/TableRecordImpl.java index 8b286c3341..af7931c989 100644 --- a/jOOQ/src/main/java/org/jooq/impl/TableRecordImpl.java +++ b/jOOQ/src/main/java/org/jooq/impl/TableRecordImpl.java @@ -37,6 +37,7 @@ */ package org.jooq.impl; +import static java.lang.Boolean.FALSE; import static java.lang.Boolean.TRUE; // ... import static org.jooq.SQLDialect.DERBY; @@ -243,7 +244,10 @@ public class TableRecordImpl> extends AbstractRecord im Collection> key = null; if (configuration() != null) - if (!TRUE.equals(configuration().data(DATA_OMIT_RETURNING_CLAUSE))) + + // [#7966] Allow users to turning off the returning clause entirely + if (!FALSE.equals(configuration().settings().isReturnIdentityOnUpdatableRecord()) + && !TRUE.equals(configuration().data(DATA_OMIT_RETURNING_CLAUSE))) // [#1859] Return also non-key columns if (TRUE.equals(configuration().settings().isReturnAllOnUpdatableRecord())) diff --git a/jOOQ/src/main/resources/xsd/jooq-runtime-3.12.0.xsd b/jOOQ/src/main/resources/xsd/jooq-runtime-3.12.0.xsd index be17fcc38b..6bab48cf9e 100644 --- a/jOOQ/src/main/resources/xsd/jooq-runtime-3.12.0.xsd +++ b/jOOQ/src/main/resources/xsd/jooq-runtime-3.12.0.xsd @@ -149,6 +149,10 @@ UpdatableRecord.store() and UpdatableRecord.update().]]> + + + +