[#8107] Add Name.Quoted Name.quoted()
This commit is contained in:
parent
55347e83c4
commit
8aacd73c76
@ -59,6 +59,7 @@ import static org.jooq.SQLDialect.POSTGRES;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Function;
|
||||
|
||||
import org.jooq.conf.RenderQuotedNames;
|
||||
import org.jooq.conf.Settings;
|
||||
|
||||
/**
|
||||
@ -73,6 +74,42 @@ import org.jooq.conf.Settings;
|
||||
*/
|
||||
public interface Name extends QueryPart {
|
||||
|
||||
/**
|
||||
* A flag indicating whether the name is quoted or not.
|
||||
* <p>
|
||||
* Quoting of names can be overridden by
|
||||
* {@link Settings#getRenderQuotedNames()}.
|
||||
*
|
||||
* @author Lukas Eder
|
||||
*/
|
||||
enum Quoted {
|
||||
|
||||
/**
|
||||
* The name is explicitly quoted.
|
||||
*/
|
||||
QUOTED,
|
||||
|
||||
/**
|
||||
* The name is explicitly not quoted.
|
||||
*/
|
||||
UNQUOTED,
|
||||
|
||||
/**
|
||||
* The name is not quoted explicitly.
|
||||
* <p>
|
||||
* The behaviour of this name's quoting is governed by
|
||||
* {@link RenderQuotedNames#EXPLICIT_DEFAULT_QUOTED} and
|
||||
* {@link RenderQuotedNames#EXPLICIT_DEFAULT_UNQUOTED}.
|
||||
*/
|
||||
DEFAULT,
|
||||
|
||||
/**
|
||||
* The {@link Name#qualified()} name has mixed values for individual
|
||||
* {@link Name#quoted()} flags.
|
||||
*/
|
||||
MIXED
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the first segment of the qualified name (usually a {@link Catalog} or {@link Schema} name).
|
||||
*/
|
||||
@ -100,6 +137,11 @@ public interface Name extends QueryPart {
|
||||
*/
|
||||
Name unqualifiedName();
|
||||
|
||||
/**
|
||||
* Whether this is a quoted name.
|
||||
*/
|
||||
Quoted quoted();
|
||||
|
||||
/**
|
||||
* This name, quoted.
|
||||
*/
|
||||
|
||||
@ -245,6 +245,7 @@ import org.jooq.MergeKeyStep9;
|
||||
import org.jooq.MergeKeyStepN;
|
||||
import org.jooq.MergeUsingStep;
|
||||
import org.jooq.Name;
|
||||
import org.jooq.Name.Quoted;
|
||||
import org.jooq.Operator;
|
||||
import org.jooq.OrderField;
|
||||
import org.jooq.OrderedAggregateFunction;
|
||||
@ -9032,7 +9033,7 @@ public class DSL {
|
||||
* @return A {@link QueryPart} that will render the SQL identifier
|
||||
*/
|
||||
public static Name quotedName(String unqualifiedName) {
|
||||
return new UnqualifiedName(unqualifiedName, true);
|
||||
return new UnqualifiedName(unqualifiedName, Quoted.QUOTED);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -9046,7 +9047,7 @@ public class DSL {
|
||||
* @return A {@link QueryPart} that will render the SQL identifier
|
||||
*/
|
||||
public static Name quotedName(String... qualifiedName) {
|
||||
return new QualifiedName(qualifiedName, true);
|
||||
return new QualifiedName(qualifiedName, Quoted.QUOTED);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -9074,7 +9075,7 @@ public class DSL {
|
||||
* @return A {@link QueryPart} that will render the SQL identifier
|
||||
*/
|
||||
public static Name unquotedName(String unqualifiedName) {
|
||||
return new UnqualifiedName(unqualifiedName, false);
|
||||
return new UnqualifiedName(unqualifiedName, Quoted.UNQUOTED);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -9089,9 +9090,9 @@ public class DSL {
|
||||
*/
|
||||
public static Name unquotedName(String... qualifiedName) {
|
||||
if (qualifiedName == null || qualifiedName.length != 1)
|
||||
return new QualifiedName(qualifiedName, false);
|
||||
return new QualifiedName(qualifiedName, Quoted.UNQUOTED);
|
||||
else
|
||||
return new UnqualifiedName(qualifiedName[0], false);
|
||||
return new UnqualifiedName(qualifiedName[0], Quoted.UNQUOTED);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -37,6 +37,9 @@
|
||||
*/
|
||||
package org.jooq.impl;
|
||||
|
||||
import static org.jooq.Name.Quoted.DEFAULT;
|
||||
import static org.jooq.Name.Quoted.MIXED;
|
||||
|
||||
import org.jooq.Context;
|
||||
import org.jooq.Name;
|
||||
import org.jooq.tools.StringUtils;
|
||||
@ -56,10 +59,10 @@ final class QualifiedName extends AbstractName {
|
||||
private final UnqualifiedName[] qualifiedName;
|
||||
|
||||
QualifiedName(String[] qualifiedName) {
|
||||
this(qualifiedName, null);
|
||||
this(qualifiedName, DEFAULT);
|
||||
}
|
||||
|
||||
QualifiedName(String[] qualifiedName, Boolean quoted) {
|
||||
QualifiedName(String[] qualifiedName, Quoted quoted) {
|
||||
this(names(qualifiedName, quoted));
|
||||
}
|
||||
|
||||
@ -71,7 +74,7 @@ final class QualifiedName extends AbstractName {
|
||||
this.qualifiedName = qualifiedName;
|
||||
}
|
||||
|
||||
private static final UnqualifiedName[] names(String[] qualifiedName, Boolean quoted) {
|
||||
private static final UnqualifiedName[] names(String[] qualifiedName, Quoted quoted) {
|
||||
String[] nonEmpty = nonEmpty(qualifiedName);
|
||||
UnqualifiedName[] result = new UnqualifiedName[nonEmpty.length];
|
||||
|
||||
@ -200,6 +203,19 @@ final class QualifiedName extends AbstractName {
|
||||
return qualifiedName[qualifiedName.length - 1];
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Quoted quoted() {
|
||||
Quoted result = null;
|
||||
|
||||
for (UnqualifiedName name : qualifiedName)
|
||||
if (result == null)
|
||||
result = name.quoted();
|
||||
else if (result != name.quoted())
|
||||
return MIXED;
|
||||
|
||||
return result == null ? DEFAULT : result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Name quotedName() {
|
||||
Name[] result = new Name[qualifiedName.length];
|
||||
|
||||
@ -37,6 +37,10 @@
|
||||
*/
|
||||
package org.jooq.impl;
|
||||
|
||||
import static org.jooq.Name.Quoted.DEFAULT;
|
||||
import static org.jooq.Name.Quoted.QUOTED;
|
||||
import static org.jooq.Name.Quoted.UNQUOTED;
|
||||
|
||||
import org.jooq.Context;
|
||||
import org.jooq.Name;
|
||||
import org.jooq.conf.RenderQuotedNames;
|
||||
@ -55,13 +59,13 @@ final class UnqualifiedName extends AbstractName {
|
||||
private static final long serialVersionUID = 8562325639223483938L;
|
||||
|
||||
private final String name;
|
||||
private final Boolean quoted;
|
||||
private final Quoted quoted;
|
||||
|
||||
UnqualifiedName(String name) {
|
||||
this(name, null);
|
||||
this(name, DEFAULT);
|
||||
}
|
||||
|
||||
UnqualifiedName(String name, Boolean quoted) {
|
||||
UnqualifiedName(String name, Quoted quoted) {
|
||||
this.name = name;
|
||||
this.quoted = quoted;
|
||||
}
|
||||
@ -73,8 +77,8 @@ final class UnqualifiedName extends AbstractName {
|
||||
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;
|
||||
|| q == RenderQuotedNames.EXPLICIT_DEFAULT_QUOTED && (quoted == DEFAULT || quoted == QUOTED)
|
||||
|| q == RenderQuotedNames.EXPLICIT_DEFAULT_UNQUOTED && quoted == QUOTED;
|
||||
|
||||
ctx.quote(current);
|
||||
ctx.literal(name);
|
||||
@ -106,14 +110,19 @@ final class UnqualifiedName extends AbstractName {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Quoted quoted() {
|
||||
return quoted;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Name quotedName() {
|
||||
return new UnqualifiedName(name, true);
|
||||
return new UnqualifiedName(name, QUOTED);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Name unquotedName() {
|
||||
return new UnqualifiedName(name, false);
|
||||
return new UnqualifiedName(name, UNQUOTED);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Loading…
Reference in New Issue
Block a user