[jOOQ/jOOQ#16483] Add Settings.renderNullifEmptyStringForBindValues to

emulate Oracle behaviour on other RDBMS
This commit is contained in:
Lukas Eder 2024-03-19 16:20:33 +01:00
parent 916882d597
commit 1490028bd2
3 changed files with 83 additions and 2 deletions

View File

@ -70,6 +70,8 @@ public class Settings
@XmlElement(defaultValue = "false")
protected Boolean renderFormatted = false;
protected RenderFormatting renderFormatting;
@XmlElement(defaultValue = "false")
protected Boolean renderNullifEmptyStringForBindValues = false;
@XmlElement(defaultValue = "NEVER")
@XmlSchemaType(name = "string")
protected AutoAliasExpressions renderAutoAliasedDerivedTableExpressions = AutoAliasExpressions.NEVER;
@ -897,6 +899,34 @@ public class Settings
this.renderFormatting = value;
}
/**
* Whether to wrap String typed bind values with NULLIF(?, '') for Oracle compatibility.
* <p>
* This feature is available in the commercial distribution only.
*
* @return
* possible object is
* {@link Boolean }
*
*/
public Boolean isRenderNullifEmptyStringForBindValues() {
return renderNullifEmptyStringForBindValues;
}
/**
* Whether to wrap String typed bind values with NULLIF(?, '') for Oracle compatibility.
* <p>
* This feature is available in the commercial distribution only.
*
* @param value
* allowed object is
* {@link Boolean }
*
*/
public void setRenderNullifEmptyStringForBindValues(Boolean value) {
this.renderNullifEmptyStringForBindValues = value;
}
/**
* Whether to auto-alias expressions in derived tables.
* <p>
@ -6840,6 +6870,17 @@ public class Settings
return this;
}
/**
* Whether to wrap String typed bind values with NULLIF(?, '') for Oracle compatibility.
* <p>
* This feature is available in the commercial distribution only.
*
*/
public Settings withRenderNullifEmptyStringForBindValues(Boolean value) {
setRenderNullifEmptyStringForBindValues(value);
return this;
}
/**
* Whether to auto-alias expressions in derived tables.
* <p>
@ -9455,6 +9496,7 @@ public class Settings
builder.append("renderLocale", renderLocale);
builder.append("renderFormatted", renderFormatted);
builder.append("renderFormatting", renderFormatting);
builder.append("renderNullifEmptyStringForBindValues", renderNullifEmptyStringForBindValues);
builder.append("renderAutoAliasedDerivedTableExpressions", renderAutoAliasedDerivedTableExpressions);
builder.append("renderOptionalAssociativityParentheses", renderOptionalAssociativityParentheses);
builder.append("renderOptionalAsKeywordForTableAliases", renderOptionalAsKeywordForTableAliases);
@ -9813,6 +9855,15 @@ public class Settings
return false;
}
}
if (renderNullifEmptyStringForBindValues == null) {
if (other.renderNullifEmptyStringForBindValues!= null) {
return false;
}
} else {
if (!renderNullifEmptyStringForBindValues.equals(other.renderNullifEmptyStringForBindValues)) {
return false;
}
}
if (renderAutoAliasedDerivedTableExpressions == null) {
if (other.renderAutoAliasedDerivedTableExpressions!= null) {
return false;
@ -11733,6 +11784,7 @@ public class Settings
result = ((prime*result)+((renderLocale == null)? 0 :renderLocale.hashCode()));
result = ((prime*result)+((renderFormatted == null)? 0 :renderFormatted.hashCode()));
result = ((prime*result)+((renderFormatting == null)? 0 :renderFormatting.hashCode()));
result = ((prime*result)+((renderNullifEmptyStringForBindValues == null)? 0 :renderNullifEmptyStringForBindValues.hashCode()));
result = ((prime*result)+((renderAutoAliasedDerivedTableExpressions == null)? 0 :renderAutoAliasedDerivedTableExpressions.hashCode()));
result = ((prime*result)+((renderOptionalAssociativityParentheses == null)? 0 :renderOptionalAssociativityParentheses.hashCode()));
result = ((prime*result)+((renderOptionalAsKeywordForTableAliases == null)? 0 :renderOptionalAsKeywordForTableAliases.hashCode()));

View File

@ -37,6 +37,7 @@
*/
package org.jooq.impl;
import static java.lang.Boolean.TRUE;
import static java.util.stream.Collectors.joining;
// ...
import static org.jooq.conf.ParamType.INLINED;
@ -44,7 +45,9 @@ import static org.jooq.conf.ParamType.NAMED;
import static org.jooq.conf.ParamType.NAMED_OR_INLINED;
import static org.jooq.impl.AbstractRowAsField.acceptMultisetContent;
import static org.jooq.impl.AbstractRowAsField.forceMultisetContent;
import static org.jooq.impl.DSL.inline;
import static org.jooq.impl.DSL.sql;
import static org.jooq.impl.Names.N_NULLIF;
import static org.jooq.impl.QueryPartListView.wrap;
import static org.jooq.impl.SQLDataType.OTHER;
import static org.jooq.impl.SQLDataType.VARCHAR;
@ -215,7 +218,23 @@ final class Val<T> extends AbstractParam<T> implements UEmpty {
try {
getBinding().sql(new DefaultBindingSQLContext<>(ctx.configuration(), ctx.data(), r, value, getBindVariable(ctx)));
accept0(r);
}
catch (SQLException e) {
throw new DataAccessException("Error while generating SQL for Binding", e);
@ -232,7 +251,11 @@ final class Val<T> extends AbstractParam<T> implements UEmpty {
}
}
private void acceptDefaultEmbeddable(Context<?> ctx) {
private final void accept0(RenderContext ctx) throws SQLException {
getBinding().sql(new DefaultBindingSQLContext<>(ctx.configuration(), ctx.data(), ctx, value, getBindVariable(ctx)));
}
private final void acceptDefaultEmbeddable(Context<?> ctx) {
ctx.data(DATA_LIST_ALREADY_INDENTED, true, c -> c.visit(wrap(embeddedFields(this))));
}

View File

@ -130,6 +130,12 @@ providing a name to parameters, resulting in <code>:1</code> or <code>@1</code>
<annotation><appinfo><jxb:property><jxb:javadoc><![CDATA[All sorts of formatting flags / settings.]]></jxb:javadoc></jxb:property></appinfo></annotation>
</element>
<element name="renderNullifEmptyStringForBindValues" type="boolean" minOccurs="0" maxOccurs="1" default="false">
<annotation><appinfo><jxb:property><jxb:javadoc><![CDATA[Whether to wrap String typed bind values with NULLIF(?, '') for Oracle compatibility.
<p>
This feature is available in the commercial distribution only.]]></jxb:javadoc></jxb:property></appinfo></annotation>
</element>
<element name="renderAutoAliasedDerivedTableExpressions" type="jooq-runtime:AutoAliasExpressions" minOccurs="0" maxOccurs="1" default="NEVER">
<annotation><appinfo><jxb:property><jxb:javadoc><![CDATA[Whether to auto-alias expressions in derived tables.
<p>