[#8103] Add RenderQuotedNames.EXPLICIT_DEFAULT_QUOTED and EXPLICIT_DEFAULT_UNQUOTED

This commit is contained in:
lukaseder 2018-12-11 11:08:05 +01:00
parent 5e780aad31
commit 55347e83c4
6 changed files with 25 additions and 13 deletions

View File

@ -21,6 +21,8 @@ import javax.xml.bind.annotation.XmlType;
* <simpleType name="RenderQuotedNames">
* <restriction base="{http://www.w3.org/2001/XMLSchema}string">
* <enumeration value="ALWAYS"/>
* <enumeration value="EXPLICIT_DEFAULT_QUOTED"/>
* <enumeration value="EXPLICIT_DEFAULT_UNQUOTED"/>
* <enumeration value="NEVER"/>
* </restriction>
* </simpleType>
@ -32,6 +34,8 @@ import javax.xml.bind.annotation.XmlType;
public enum RenderQuotedNames {
ALWAYS,
EXPLICIT_DEFAULT_QUOTED,
EXPLICIT_DEFAULT_UNQUOTED,
NEVER;
public String value() {

View File

@ -43,9 +43,9 @@ public class Settings
@XmlElement(defaultValue = "true")
protected Boolean renderSchema = true;
protected RenderMapping renderMapping;
@XmlElement(defaultValue = "ALWAYS")
@XmlElement(defaultValue = "EXPLICIT_DEFAULT_QUOTED")
@XmlSchemaType(name = "string")
protected RenderQuotedNames renderQuotedNames = RenderQuotedNames.ALWAYS;
protected RenderQuotedNames renderQuotedNames = RenderQuotedNames.EXPLICIT_DEFAULT_QUOTED;
@XmlElement(defaultValue = "AS_IS")
@XmlSchemaType(name = "string")
protected RenderNameCase renderNameCase = RenderNameCase.AS_IS;

View File

@ -236,11 +236,11 @@ public final class SettingsTools {
public static final RenderQuotedNames getRenderQuotedNames(Settings settings) {
RenderQuotedNames result = settings.getRenderQuotedNames();
if (result == null || result == RenderQuotedNames.ALWAYS) {
if (result == null || result == RenderQuotedNames.EXPLICIT_DEFAULT_QUOTED) {
RenderNameStyle style = settings.getRenderNameStyle();
if (style == null || style == RenderNameStyle.QUOTED)
result = RenderQuotedNames.ALWAYS;
result = RenderQuotedNames.EXPLICIT_DEFAULT_QUOTED;
else
result = RenderQuotedNames.NEVER;
}

View File

@ -80,7 +80,6 @@ import org.jooq.VisitListener;
import org.jooq.VisitListenerProvider;
import org.jooq.conf.ParamCastMode;
import org.jooq.conf.ParamType;
import org.jooq.conf.RenderQuotedNames;
import org.jooq.conf.Settings;
import org.jooq.conf.SettingsTools;
import org.jooq.conf.StatementType;
@ -179,7 +178,6 @@ abstract class AbstractContext<C extends Context<C>> extends AbstractScope imple
: m == ParamCastMode.NEVER
? CastMode.NEVER
: CastMode.DEFAULT;
this.quote = SettingsTools.getRenderQuotedNames(settings()) == RenderQuotedNames.ALWAYS;
this.scopeStack = new ScopeStack();
}

View File

@ -39,6 +39,8 @@ package org.jooq.impl;
import org.jooq.Context;
import org.jooq.Name;
import org.jooq.conf.RenderQuotedNames;
import org.jooq.conf.SettingsTools;
/**
* The default implementation for an unqualified SQL identifier.
@ -66,15 +68,17 @@ final class UnqualifiedName extends AbstractName {
@Override
public final void accept(Context<?> ctx) {
RenderQuotedNames q = SettingsTools.getRenderQuotedNames(ctx.settings());
boolean previous = ctx.quote();
boolean current =
q == RenderQuotedNames.ALWAYS
|| q == RenderQuotedNames.EXPLICIT_DEFAULT_QUOTED && (quoted == null || quoted)
|| q == RenderQuotedNames.EXPLICIT_DEFAULT_UNQUOTED && quoted != null && quoted;
if (quoted != null)
ctx.quote(quoted);
ctx.quote(current);
ctx.literal(name);
if (quoted != null)
ctx.quote(previous);
ctx.quote(previous);
}
@Override

View File

@ -33,7 +33,7 @@ available using synonyms]]></jxb:javadoc></jxb:property></appinfo></annotation>
generated SQL.]]></jxb:javadoc></jxb:property></appinfo></annotation>
</element>
<element name="renderQuotedNames" type="jooq-runtime:RenderQuotedNames" minOccurs="0" maxOccurs="1" default="ALWAYS">
<element name="renderQuotedNames" type="jooq-runtime:RenderQuotedNames" minOccurs="0" maxOccurs="1" default="EXPLICIT_DEFAULT_QUOTED">
<annotation><appinfo><jxb:property><jxb:javadoc><![CDATA[Whether rendered schema, table, column names, etc should be quoted.
<p>
This only affects names created through {@link org.jooq.impl.DSL#name(String)} methods (including those that are implicitly created through this method), not {@link org.jooq.impl.DSL#quotedName(String)} or {@link org.jooq.impl.DSL#unquotedName(String)}, whose behaviour cannot be overridden.
@ -441,6 +441,12 @@ Either &lt;input/> or &lt;inputExpression/> must be provided]]></jxb:javadoc></j
SQL Server: [INFORMATION_SCHEMA].[TABLES] -->
<enumeration value="ALWAYS"/>
<!-- Render object names quoted if they are constructed using DSL.quotedName() or DSL.name() -->
<enumeration value="EXPLICIT_DEFAULT_QUOTED"/>
<!-- Render object names quoted if they are constructed using DSL.quotedName() -->
<enumeration value="EXPLICIT_DEFAULT_UNQUOTED"/>
<!-- Never quote names -->
<enumeration value="NEVER"/>
</restriction>