[#7966] Add Setting to turn off fetching generated keys from UpdatableRecord

This commit is contained in:
lukaseder 2018-10-25 15:58:19 +02:00
parent 6dc8b4bd52
commit f98c2f855d
4 changed files with 84 additions and 2 deletions

View File

@ -3979,11 +3979,39 @@ author.store(); // The behaviour of this store call is governed by the updatable
</html></content>
</section>
<section id="settings-return-identity-on-store">
<title>Return Identity Value On Store</title>
<content><html>
<p>
When using the <reference id="crud-with-updatablerecords" title="updatable records feature"/>, jOOQ by default fetches the generated <reference id="identity-values" title="identity value"/>.
</p>
<p>
In some situations, it is desirable for this feature to be turned off using the following flag:
</p>
<p>
<strong>Programmatic configuration</strong>
</p>
</html><java><![CDATA[Settings settings = new Settings()
.withReturnIdentityOnUpdatableRecord(false); // Defaults to true]]></java><html>
<p>
<strong>XML configuration</strong>
</p>
</html><xml><![CDATA[<settings xmlns="http://www.jooq.org/xsd/jooq-runtime-{runtime-xsd-version}.xsd">
<returnIdentityOnUpdatableRecord>false</returnIdentityOnUpdatableRecord>
</settings>]]></xml><html>
</html></content>
</section>
<section id="settings-return-all-on-store">
<title>Return All Columns On Store</title>
<content><html>
<p>
When using the <reference id="crud-with-updatablerecords" title="updatable records feature"/>, jOOQ always fetches the generated <reference id="identity-values" title="identity value"/>, if such a value is available.
When using the <reference id="crud-with-updatablerecords" title="updatable records feature"/>, jOOQ always fetches the generated <reference id="identity-values" title="identity value"/>, if such a value is available and if <reference id="settings-return-identity-on-store" title="the return identity on store"/> feature is enabled (it is, by default).
</p>
<p>

View File

@ -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.
* <p>
@ -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("</fetchServerOutputSize>");
}
if (returnIdentityOnUpdatableRecord!= null) {
sb.append("<returnIdentityOnUpdatableRecord>");
sb.append(returnIdentityOnUpdatableRecord);
sb.append("</returnIdentityOnUpdatableRecord>");
}
if (returnAllOnUpdatableRecord!= null) {
sb.append("<returnAllOnUpdatableRecord>");
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()));

View File

@ -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<R extends TableRecord<R>> extends AbstractRecord im
Collection<Field<?>> 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()))

View File

@ -149,6 +149,10 @@ UpdatableRecord.store() and UpdatableRecord.update().]]></jxb:javadoc></jxb:prop
<annotation><appinfo><jxb:property><jxb:javadoc><![CDATA[Whether server output should be fetched after each query execution.]]></jxb:javadoc></jxb:property></appinfo></annotation>
</element>
<element name="returnIdentityOnUpdatableRecord" type="boolean" minOccurs="0" maxOccurs="1" default="true">
<annotation><appinfo><jxb:property><jxb:javadoc><![CDATA[Whether calls to store(), insert() and update() should return the identity column.]]></jxb:javadoc></jxb:property></appinfo></annotation>
</element>
<element name="returnAllOnUpdatableRecord" type="boolean" minOccurs="0" maxOccurs="1" default="false">
<annotation><appinfo><jxb:property><jxb:javadoc><![CDATA[Whether calls to store(), insert() and update() should return all columns, not just identity columns.
<p>