Skip to content

Commit

Permalink
[#9931] Add a new DSL.systemName type
Browse files Browse the repository at this point in the history
This also fixes: [#12752] DDLDatabase defaultNameCase property shouldn't affect built in functions in view definitions
  • Loading branch information
lukaseder committed Dec 17, 2021
1 parent a48c240 commit 6281e94
Show file tree
Hide file tree
Showing 12 changed files with 521 additions and 450 deletions.
Expand Up @@ -126,11 +126,14 @@ protected void export() throws Exception {
ctx.configuration().set(new DefaultVisitListener() {
@Override
public void visitStart(VisitContext vc) {
if (vc.queryPart() instanceof Name) {
Name[] parts = ((Name) vc.queryPart()).parts();
if (vc.queryPart() instanceof Name) { Name n = (Name) vc.queryPart();
Name[] parts = n.parts();
boolean changed = false;

for (int i = 0; i < parts.length; i++) {

// [#9931] [#12752] This explicitly excludes the new Quoted.SYSTEM
// flag for DSL.systemName() names
if (parts[i].quoted() == Quoted.UNQUOTED) {
parts[i] = DSL.quotedName(
"UPPER".equals(defaultNameCase)
Expand Down
5 changes: 5 additions & 0 deletions jOOQ/src/main/java/org/jooq/Name.java
Expand Up @@ -121,6 +121,11 @@ enum Quoted {
*/
UNQUOTED,

/**
* The name is a system name, and thus it is never quoted.
*/
SYSTEM,

/**
* The name is not quoted explicitly.
* <p>
Expand Down
3 changes: 2 additions & 1 deletion jOOQ/src/main/java/org/jooq/impl/Concat.java
Expand Up @@ -39,6 +39,7 @@

import static org.jooq.impl.DSL.function;
import static org.jooq.impl.DSL.inline;
import static org.jooq.impl.DSL.systemName;
import static org.jooq.impl.ExpressionOperator.ADD;
import static org.jooq.impl.ExpressionOperator.CONCAT;
import static org.jooq.impl.Names.N_CONCAT;
Expand Down Expand Up @@ -89,7 +90,7 @@ public final void accept(Context<?> ctx) {

case MARIADB:
case MYSQL:
ctx.visit(function("concat", SQLDataType.VARCHAR, cast));
ctx.visit(function(systemName("concat"), SQLDataType.VARCHAR, cast));
return;


Expand Down
55 changes: 55 additions & 0 deletions jOOQ/src/main/java/org/jooq/impl/DSL.java
Expand Up @@ -414,6 +414,7 @@
import org.jooq.XMLQueryPassingStep;
import org.jooq.XMLTablePassingStep;
import org.jooq.conf.NestedCollectionEmulation;
import org.jooq.conf.RenderQuotedNames;
import org.jooq.conf.Settings;
import org.jooq.exception.SQLDialectNotSupportedException;
import org.jooq.impl.QOM.DocumentOrContent;
Expand Down Expand Up @@ -11760,6 +11761,60 @@ public static Name unquotedName(Collection<String> qualifiedName) {
return unquotedName(qualifiedName.toArray(Tools.EMPTY_STRING));
}

/**
* Create a new SQL identifier using an unqualified, quoted name.
* <p>
* This works like {@link #name(String...)}, except that generated
* identifiers will be guaranteed to be unquoted, even when the relevant
* {@link Settings#getRenderQuotedNames()} flag is set to
* {@link RenderQuotedNames#ALWAYS}.
*
* @param unqualifiedName The SQL identifier's unqualified name
* @return A {@link QueryPart} that will render the SQL identifier
*/
@NotNull
@Support
public static Name systemName(String unqualifiedName) {
return new UnqualifiedName(unqualifiedName, Quoted.SYSTEM);
}

/**
* Create a new SQL identifier using a qualified, quoted name.
* <p>
* This works like {@link #name(String...)}, except that generated
* identifiers will be guaranteed to be unquoted, even when the relevant
* {@link Settings#getRenderQuotedNames()} flag is set to
* {@link RenderQuotedNames#ALWAYS}.
*
* @param qualifiedName The SQL identifier's qualified name parts
* @return A {@link QueryPart} that will render the SQL identifier
*/
@NotNull
@Support
public static Name systemName(String... qualifiedName) {
if (qualifiedName == null || qualifiedName.length != 1)
return new QualifiedName(qualifiedName, Quoted.SYSTEM);
else
return new UnqualifiedName(qualifiedName[0], Quoted.SYSTEM);
}

/**
* Create a new SQL identifier using a qualified, system name.
* <p>
* This works like {@link #name(Collection)}, except that generated
* identifiers will be guaranteed to be unquoted, even when the relevant
* {@link Settings#getRenderQuotedNames()} flag is set to
* {@link RenderQuotedNames#ALWAYS}.
*
* @param qualifiedName The SQL identifier's qualified name parts
* @return A {@link QueryPart} that will render the SQL identifier
*/
@NotNull
@Support
public static Name systemName(Collection<String> qualifiedName) {
return systemName(qualifiedName.toArray(Tools.EMPTY_STRING));
}

// -------------------------------------------------------------------------
// XXX QueryPart composition
// -------------------------------------------------------------------------
Expand Down
6 changes: 3 additions & 3 deletions jOOQ/src/main/java/org/jooq/impl/DefaultDataType.java
Expand Up @@ -50,7 +50,7 @@
import static org.jooq.SQLDialect.SQLITE;
import static org.jooq.SQLDialect.YUGABYTE;
import static org.jooq.impl.CommentImpl.NO_COMMENT;
import static org.jooq.impl.DSL.unquotedName;
import static org.jooq.impl.DSL.systemName;
import static org.jooq.impl.DefaultBinding.binding;
import static org.jooq.impl.SQLDataType.BIGINT;
import static org.jooq.impl.SQLDataType.BINARY;
Expand Down Expand Up @@ -304,11 +304,11 @@ public DefaultDataType(SQLDialect dialect, DataType<T> sqlDataType, String typeN
}

public DefaultDataType(SQLDialect dialect, Class<T> type, String typeName) {
this(dialect, null, type, unquotedName(typeName), typeName, null, null, null, null, Nullability.DEFAULT, null);
this(dialect, null, type, systemName(typeName), typeName, null, null, null, null, Nullability.DEFAULT, null);
}

public DefaultDataType(SQLDialect dialect, Class<T> type, String typeName, String castTypeName) {
this(dialect, null, type, unquotedName(typeName), typeName, castTypeName, null, null, null, Nullability.DEFAULT, null);
this(dialect, null, type, systemName(typeName), typeName, castTypeName, null, null, null, Nullability.DEFAULT, null);
}

DefaultDataType(SQLDialect dialect, Class<T> type, Name qualifiedTypeName) {
Expand Down
3 changes: 2 additions & 1 deletion jOOQ/src/main/java/org/jooq/impl/Extract.java
Expand Up @@ -43,6 +43,7 @@
import static org.jooq.impl.DSL.isoDayOfWeek;
import static org.jooq.impl.DSL.keyword;
import static org.jooq.impl.DSL.one;
import static org.jooq.impl.DSL.systemName;
import static org.jooq.impl.Internal.iadd;
import static org.jooq.impl.Internal.idiv;
import static org.jooq.impl.Internal.imul;
Expand Down Expand Up @@ -127,7 +128,7 @@ public final void accept(Context<?> ctx) {
ctx.visit(function(N_STRFTIME, VARCHAR, inline("%s"), field).cast(INTEGER));
return;
case ISO_DAY_OF_WEEK:
ctx.visit(dowSun0ToISO(function("strftime", INTEGER, inline("%w"), field).cast(INTEGER)));
ctx.visit(dowSun0ToISO(function(systemName("strftime"), INTEGER, inline("%w"), field).cast(INTEGER)));
return;
case DAY_OF_WEEK:
ctx.visit(function(N_STRFTIME, VARCHAR, inline("%w"), field).cast(INTEGER).plus(one()));
Expand Down

0 comments on commit 6281e94

Please sign in to comment.