diff --git a/jOOQ-examples/jOOQ-academy/src/test/java/org/jooq/academy/section4/Example_4_2_Settings.java b/jOOQ-examples/jOOQ-academy/src/test/java/org/jooq/academy/section4/Example_4_2_Settings.java index 5237812df6..828ffa8a60 100644 --- a/jOOQ-examples/jOOQ-academy/src/test/java/org/jooq/academy/section4/Example_4_2_Settings.java +++ b/jOOQ-examples/jOOQ-academy/src/test/java/org/jooq/academy/section4/Example_4_2_Settings.java @@ -46,9 +46,10 @@ import org.jooq.Select; import org.jooq.academy.tools.Tools; import org.jooq.conf.MappedSchema; import org.jooq.conf.MappedTable; -import org.jooq.conf.RenderKeywordStyle; +import org.jooq.conf.RenderKeywordCase; import org.jooq.conf.RenderMapping; -import org.jooq.conf.RenderNameStyle; +import org.jooq.conf.RenderNameCase; +import org.jooq.conf.RenderQuotedNames; import org.jooq.conf.Settings; import org.jooq.impl.DSL; @@ -71,15 +72,20 @@ public class Example_4_2_Settings { out.println(using(H2, new Settings().withRenderSchema(false)).render(select)); out.println(using(H2, new Settings().withRenderSchema(true)).render(select)); - Tools.title("A couple of settings at work - Name style"); - out.println(using(H2, new Settings().withRenderNameStyle(RenderNameStyle.AS_IS)).render(select)); - out.println(using(H2, new Settings().withRenderNameStyle(RenderNameStyle.UPPER)).render(select)); - out.println(using(H2, new Settings().withRenderNameStyle(RenderNameStyle.LOWER)).render(select)); - out.println(using(H2, new Settings().withRenderNameStyle(RenderNameStyle.QUOTED)).render(select)); + Tools.title("A couple of settings at work - Name case"); + out.println(using(H2, new Settings().withRenderNameCase(RenderNameCase.AS_IS)).render(select)); + out.println(using(H2, new Settings().withRenderNameCase(RenderNameCase.UPPER)).render(select)); + out.println(using(H2, new Settings().withRenderNameCase(RenderNameCase.LOWER)).render(select)); + out.println(using(H2, new Settings().withRenderNameCase(RenderNameCase.PASCAL)).render(select)); - Tools.title("A couple of settings at work - Keyword style"); - out.println(using(H2, new Settings().withRenderKeywordStyle(RenderKeywordStyle.UPPER)).render(select)); - out.println(using(H2, new Settings().withRenderKeywordStyle(RenderKeywordStyle.LOWER)).render(select)); + Tools.title("A couple of settings at work - Name quoting"); + out.println(using(H2, new Settings().withRenderQuotedNames(RenderQuotedNames.ALWAYS)).render(select)); + out.println(using(H2, new Settings().withRenderQuotedNames(RenderQuotedNames.WHEN_NEEDED)).render(select)); + out.println(using(H2, new Settings().withRenderQuotedNames(RenderQuotedNames.NEVER)).render(select)); + + Tools.title("A couple of settings at work - Keyword case"); + out.println(using(H2, new Settings().withRenderKeywordCase(RenderKeywordCase.UPPER)).render(select)); + out.println(using(H2, new Settings().withRenderKeywordCase(RenderKeywordCase.LOWER)).render(select)); Tools.title("A couple of settings at work - Mapping"); out.println(using(H2, new Settings() diff --git a/jOOQ-examples/jOOQ-academy/src/test/java/org/jooq/academy/section4/Example_4_3_Settings.java b/jOOQ-examples/jOOQ-academy/src/test/java/org/jooq/academy/section4/Example_4_3_Settings.java index 7303fbb40b..10020359dd 100644 --- a/jOOQ-examples/jOOQ-academy/src/test/java/org/jooq/academy/section4/Example_4_3_Settings.java +++ b/jOOQ-examples/jOOQ-academy/src/test/java/org/jooq/academy/section4/Example_4_3_Settings.java @@ -46,9 +46,10 @@ import org.jooq.Select; import org.jooq.academy.tools.Tools; import org.jooq.conf.MappedSchema; import org.jooq.conf.MappedTable; -import org.jooq.conf.RenderKeywordStyle; +import org.jooq.conf.RenderKeywordCase; import org.jooq.conf.RenderMapping; -import org.jooq.conf.RenderNameStyle; +import org.jooq.conf.RenderNameCase; +import org.jooq.conf.RenderQuotedNames; import org.jooq.conf.Settings; import org.jooq.impl.DSL; @@ -71,15 +72,20 @@ public class Example_4_3_Settings { out.println(using(H2, new Settings().withRenderSchema(false)).render(select)); out.println(using(H2, new Settings().withRenderSchema(true)).render(select)); - Tools.title("A couple of settings at work - Name style"); - out.println(using(H2, new Settings().withRenderNameStyle(RenderNameStyle.AS_IS)).render(select)); - out.println(using(H2, new Settings().withRenderNameStyle(RenderNameStyle.UPPER)).render(select)); - out.println(using(H2, new Settings().withRenderNameStyle(RenderNameStyle.LOWER)).render(select)); - out.println(using(H2, new Settings().withRenderNameStyle(RenderNameStyle.QUOTED)).render(select)); + Tools.title("A couple of settings at work - Name case"); + out.println(using(H2, new Settings().withRenderNameCase(RenderNameCase.AS_IS)).render(select)); + out.println(using(H2, new Settings().withRenderNameCase(RenderNameCase.UPPER)).render(select)); + out.println(using(H2, new Settings().withRenderNameCase(RenderNameCase.LOWER)).render(select)); + out.println(using(H2, new Settings().withRenderNameCase(RenderNameCase.PASCAL)).render(select)); - Tools.title("A couple of settings at work - Keyword style"); - out.println(using(H2, new Settings().withRenderKeywordStyle(RenderKeywordStyle.UPPER)).render(select)); - out.println(using(H2, new Settings().withRenderKeywordStyle(RenderKeywordStyle.LOWER)).render(select)); + Tools.title("A couple of settings at work - Name quoting"); + out.println(using(H2, new Settings().withRenderQuotedNames(RenderQuotedNames.ALWAYS)).render(select)); + out.println(using(H2, new Settings().withRenderQuotedNames(RenderQuotedNames.WHEN_NEEDED)).render(select)); + out.println(using(H2, new Settings().withRenderQuotedNames(RenderQuotedNames.NEVER)).render(select)); + + Tools.title("A couple of settings at work - Keyword case"); + out.println(using(H2, new Settings().withRenderKeywordCase(RenderKeywordCase.UPPER)).render(select)); + out.println(using(H2, new Settings().withRenderKeywordCase(RenderKeywordCase.LOWER)).render(select)); Tools.title("A couple of settings at work - Mapping"); out.println(using(H2, new Settings() diff --git a/jOOQ/src/main/java/org/jooq/Context.java b/jOOQ/src/main/java/org/jooq/Context.java index 7f5138ca34..0b6e95f0b7 100644 --- a/jOOQ/src/main/java/org/jooq/Context.java +++ b/jOOQ/src/main/java/org/jooq/Context.java @@ -41,7 +41,7 @@ import java.sql.PreparedStatement; import org.jooq.RenderContext.CastMode; import org.jooq.conf.ParamType; -import org.jooq.conf.RenderKeywordStyle; +import org.jooq.conf.RenderKeywordCase; import org.jooq.conf.Settings; import org.jooq.exception.DataAccessException; import org.jooq.impl.DSL; @@ -253,7 +253,7 @@ public interface Context> extends Scope { /** * Append a SQL keyword to the context's contained {@link StringBuilder}. *

- * Use this to have your SQL keyword rendered in {@link RenderKeywordStyle}. + * Use this to have your SQL keyword rendered in {@link RenderKeywordCase}. * * @deprecated - 3.10.0 - [#4990] - Use {@link DSL#keyword(String)} instead. */ diff --git a/jOOQ/src/main/java/org/jooq/DSLContext.java b/jOOQ/src/main/java/org/jooq/DSLContext.java index 232cb690ad..0a2429de90 100644 --- a/jOOQ/src/main/java/org/jooq/DSLContext.java +++ b/jOOQ/src/main/java/org/jooq/DSLContext.java @@ -835,7 +835,7 @@ public interface DSLContext extends Scope , AutoCloseable { * // The following query * query("select {0}, {1} from {2}", val(1), inline("test"), name("DUAL")); * - * // Will render this SQL on an Oracle database with RenderNameStyle.QUOTED: + * // Will render this SQL by default, using SQLDialect.ORACLE: * select ?, 'test' from "DUAL" * *

@@ -952,7 +952,7 @@ public interface DSLContext extends Scope , AutoCloseable { * // The following query * fetch("select {0}, {1} from {2}", val(1), inline("test"), name("DUAL")); * - * // Will execute this SQL on an Oracle database with RenderNameStyle.QUOTED: + * // Will execute this SQL by default, using SQLDialect.ORACLE: * select ?, 'test' from "DUAL" * *

@@ -1093,7 +1093,7 @@ public interface DSLContext extends Scope , AutoCloseable { * // The following query * fetchLazy("select {0}, {1} from {2}", val(1), inline("test"), name("DUAL")); * - * // Will execute this SQL on an Oracle database with RenderNameStyle.QUOTED: + * // Will execute this SQL by default, using SQLDialect.ORACLE: * select ?, 'test' from "DUAL" * *

@@ -1227,7 +1227,7 @@ public interface DSLContext extends Scope , AutoCloseable { * // The following query * fetchLazy("select {0}, {1} from {2}", val(1), inline("test"), name("DUAL")); * - * // Will execute this SQL on an Oracle database with RenderNameStyle.QUOTED: + * // Will execute this SQL by default, using SQLDialect.ORACLE: * select ?, 'test' from "DUAL" * *

@@ -1347,7 +1347,7 @@ public interface DSLContext extends Scope , AutoCloseable { * // The following query * fetchLazy("select {0}, {1} from {2}", val(1), inline("test"), name("DUAL")); * - * // Will execute this SQL on an Oracle database with RenderNameStyle.QUOTED: + * // Will execute this SQL by default, using SQLDialect.ORACLE: * select ?, 'test' from "DUAL" * *

@@ -1493,7 +1493,7 @@ public interface DSLContext extends Scope , AutoCloseable { * // The following query * fetchLazy("select {0}, {1} from {2}", val(1), inline("test"), name("DUAL")); * - * // Will execute this SQL on an Oracle database with RenderNameStyle.QUOTED: + * // Will execute this SQL by default, using SQLDialect.ORACLE: * select ?, 'test' from "DUAL" * *

@@ -1604,7 +1604,7 @@ public interface DSLContext extends Scope , AutoCloseable { * // The following query * fetchMany("select {0}, {1} from {2}", val(1), inline("test"), name("DUAL")); * - * // Will execute this SQL on an Oracle database with RenderNameStyle.QUOTED: + * // Will execute this SQL by default, using SQLDialect.ORACLE: * select ?, 'test' from "DUAL" * *

@@ -1723,7 +1723,7 @@ public interface DSLContext extends Scope , AutoCloseable { * // The following query * fetchOne("select {0}, {1} from {2}", val(1), inline("test"), name("DUAL")); * - * // Will execute this SQL on an Oracle database with RenderNameStyle.QUOTED: + * // Will execute this SQL by default, using SQLDialect.ORACLE: * select ?, 'test' from "DUAL" * *

@@ -1846,7 +1846,7 @@ public interface DSLContext extends Scope , AutoCloseable { * // The following query * fetchOne("select {0}, {1} from {2}", val(1), inline("test"), name("DUAL")); * - * // Will execute this SQL on an Oracle database with RenderNameStyle.QUOTED: + * // Will execute this SQL by default, using SQLDialect.ORACLE: * select ?, 'test' from "DUAL" * *

@@ -1968,7 +1968,7 @@ public interface DSLContext extends Scope , AutoCloseable { * // The following query * fetchOne("select {0}, {1} from {2}", val(1), inline("test"), name("DUAL")); * - * // Will execute this SQL on an Oracle database with RenderNameStyle.QUOTED: + * // Will execute this SQL by default, using SQLDialect.ORACLE: * select ?, 'test' from "DUAL" * *

@@ -2095,7 +2095,7 @@ public interface DSLContext extends Scope , AutoCloseable { * // The following query * fetchOne("select {0}, {1} from {2}", val(1), inline("test"), name("DUAL")); * - * // Will execute this SQL on an Oracle database with RenderNameStyle.QUOTED: + * // Will execute this SQL by default, using SQLDialect.ORACLE: * select ?, 'test' from "DUAL" * *

@@ -2224,7 +2224,7 @@ public interface DSLContext extends Scope , AutoCloseable { * // The following query * fetchOne("select {0}, {1} from {2}", val(1), inline("test"), name("DUAL")); * - * // Will execute this SQL on an Oracle database with RenderNameStyle.QUOTED: + * // Will execute this SQL by default, using SQLDialect.ORACLE: * select ?, 'test' from "DUAL" * *

@@ -2350,7 +2350,7 @@ public interface DSLContext extends Scope , AutoCloseable { * // The following query * fetchOne("select {0}, {1} from {2}", val(1), inline("test"), name("DUAL")); * - * // Will execute this SQL on an Oracle database with RenderNameStyle.QUOTED: + * // Will execute this SQL by default, using SQLDialect.ORACLE: * select ?, 'test' from "DUAL" * *

@@ -2441,7 +2441,7 @@ public interface DSLContext extends Scope , AutoCloseable { * // The following query * execute("select {0}, {1} from {2}", val(1), inline("test"), name("DUAL")); * - * // Will execute this SQL on an Oracle database with RenderNameStyle.QUOTED: + * // Will execute this SQL by default, using SQLDialect.ORACLE: * select ?, 'test' from "DUAL" * *

@@ -2615,7 +2615,7 @@ public interface DSLContext extends Scope , AutoCloseable { * // The following query * resultQuery("select {0}, {1} from {2}", val(1), inline("test"), name("DUAL")); * - * // Will render this SQL on an Oracle database with RenderNameStyle.QUOTED: + * // Will render this SQL by default, using SQLDialect.ORACLE: * select ?, 'test' from "DUAL" * *

diff --git a/jOOQ/src/main/java/org/jooq/Field.java b/jOOQ/src/main/java/org/jooq/Field.java index a92e326d39..e65ebb9159 100644 --- a/jOOQ/src/main/java/org/jooq/Field.java +++ b/jOOQ/src/main/java/org/jooq/Field.java @@ -159,8 +159,8 @@ extends * Create an alias for this field. *

* Note that the case-sensitivity of the returned field depends on - * {@link Settings#getRenderNameStyle()}. By default, field aliases are - * quoted, and thus case-sensitive! + * {@link Settings#getRenderQuotedNames()}. By default, field aliases are + * quoted, and thus case-sensitive in many SQL dialects! * * @param alias The alias name * @return The field alias @@ -172,9 +172,9 @@ extends * Create an alias for this field. *

* Note that the case-sensitivity of the returned field depends on - * {@link Settings#getRenderNameStyle()} and the {@link Name}. By default, - * field aliases are quoted, and thus case-sensitive - use - * {@link DSL#unquotedName(String...)} for case-insensitive aliases. + * {@link Settings#getRenderQuotedNames()} and the {@link Name}. By default, + * field aliases are quoted, and thus case-sensitive in many SQL dialects - + * use {@link DSL#unquotedName(String...)} for case-insensitive aliases. *

* If the argument {@link Name#getName()} is qualified, then the * {@link Name#last()} part will be used. @@ -187,10 +187,6 @@ extends /** * Create an alias for this field based on another field's name. - *

- * Note that the case-sensitivity of the returned field depends on - * {@link Settings#getRenderNameStyle()}. By default, field aliases are - * quoted, and thus case-sensitive! * * @param otherField The other field whose name this field is aliased with. * @return The field alias. @@ -203,8 +199,8 @@ extends * Create an alias for this field. *

* Note that the case-sensitivity of the returned field depends on - * {@link Settings#getRenderNameStyle()}. By default, field aliases are - * quoted, and thus case-sensitive! + * {@link Settings#getRenderQuotedNames()}. By default, field aliases are + * quoted, and thus case-sensitive in many SQL dialects! *

* This works like {@link #as(String)}, except that field aliases are * provided by a function. This is useful, for instance, to prefix all diff --git a/jOOQ/src/main/java/org/jooq/FieldLike.java b/jOOQ/src/main/java/org/jooq/FieldLike.java index f3bf03b71c..5a47aa6bbb 100644 --- a/jOOQ/src/main/java/org/jooq/FieldLike.java +++ b/jOOQ/src/main/java/org/jooq/FieldLike.java @@ -65,8 +65,8 @@ public interface FieldLike { * SELECT y.*, (SELECT a FROM x) [alias] FROM y *

* Note that the case-sensitivity of the returned field depends on - * {@link Settings#getRenderNameStyle()}. By default, field aliases are - * quoted, and thus case-sensitive! + * {@link Settings#getRenderQuotedNames()}. By default, field aliases are + * quoted, and thus case-sensitive in many SQL dialects! * * @return This result provider as a Field<?> object */ @@ -80,8 +80,8 @@ public interface FieldLike { * SELECT y.*, (SELECT a FROM x) [alias] FROM y *

* Note that the case-sensitivity of the returned field depends on - * {@link Settings#getRenderNameStyle()}. By default, field aliases are - * quoted, and thus case-sensitive! + * {@link Settings#getRenderQuotedNames()}. By default, field aliases are + * quoted, and thus case-sensitive in many SQL dialects! *

* This works like {@link #asField(String)}, except that field aliases are * provided by a function. This is useful, for instance, to prefix all diff --git a/jOOQ/src/main/java/org/jooq/Keyword.java b/jOOQ/src/main/java/org/jooq/Keyword.java index 503be4954c..16c4e133dd 100644 --- a/jOOQ/src/main/java/org/jooq/Keyword.java +++ b/jOOQ/src/main/java/org/jooq/Keyword.java @@ -44,7 +44,7 @@ import org.jooq.conf.Settings; *

* A Keyword is a {@link QueryPart} that renders a SQL keyword * according to the settings specified in - * {@link Settings#getRenderKeywordStyle()}. + * {@link Settings#getRenderKeywordCase()}. * * @author Lukas Eder */ diff --git a/jOOQ/src/main/java/org/jooq/Name.java b/jOOQ/src/main/java/org/jooq/Name.java index 89c8bdc389..fe3b051b52 100644 --- a/jOOQ/src/main/java/org/jooq/Name.java +++ b/jOOQ/src/main/java/org/jooq/Name.java @@ -65,7 +65,9 @@ import org.jooq.conf.Settings; * A SQL identifier QueryPart. *

* A Name is a {@link QueryPart} that renders a SQL identifier - * according to the settings specified in {@link Settings#getRenderNameStyle()}. + * according to the settings specified in + * {@link Settings#getRenderQuotedNames()} and + * {@link Settings#getRenderNameCase()}. * * @author Lukas Eder */ diff --git a/jOOQ/src/main/java/org/jooq/ParserCLI.java b/jOOQ/src/main/java/org/jooq/ParserCLI.java index 35cff6bef0..7961062d75 100644 --- a/jOOQ/src/main/java/org/jooq/ParserCLI.java +++ b/jOOQ/src/main/java/org/jooq/ParserCLI.java @@ -37,8 +37,8 @@ */ package org.jooq; -import org.jooq.conf.RenderKeywordStyle; -import org.jooq.conf.RenderNameStyle; +import org.jooq.conf.RenderKeywordCase; +import org.jooq.conf.RenderNameCase; import org.jooq.conf.Settings; import org.jooq.impl.DSL; import org.jooq.impl.ParserException; @@ -72,9 +72,9 @@ public final class ParserCLI { if (a.formatted) settings.setRenderFormatted(true); if (a.keywords != null) - settings.setRenderKeywordStyle(a.keywords); + settings.setRenderKeywordCase(a.keywords); if (a.name != null) - settings.setRenderNameStyle(a.name); + settings.setRenderNameCase(a.name); DSLContext ctx = DSL.using(a.toDialect, settings); try { @@ -106,29 +106,29 @@ public final class ParserCLI { } else if ("-k".equals(args[i]) || "--keyword".equals(args[i])) { try { - result.keywords = RenderKeywordStyle.valueOf(args[++i]); + result.keywords = RenderKeywordCase.valueOf(args[++i]); continue argsLoop; } catch (IllegalArgumentException e) { - invalid(args[i], RenderKeywordStyle.class); + invalid(args[i], RenderKeywordCase.class); throw e; } catch (ArrayIndexOutOfBoundsException e) { - System.err.println("Flag -k / --keyword requires argument"); + System.err.println("Flag -k / --keyword requires argument"); throw e; } } else if ("-i".equals(args[i]) || "--identifier".equals(args[i])) { try { - result.keywords = RenderKeywordStyle.valueOf(args[++i]); + result.keywords = RenderKeywordCase.valueOf(args[++i]); continue argsLoop; } catch (IllegalArgumentException e) { - invalid(args[i], RenderKeywordStyle.class); + invalid(args[i], RenderKeywordCase.class); throw e; } catch (ArrayIndexOutOfBoundsException e) { - System.err.println("Flag -i / --identifier requires argument"); + System.err.println("Flag -i / --identifier requires argument"); throw e; } } @@ -179,19 +179,19 @@ public final class ParserCLI { private static final void help() { System.out.println("Usage:"); - System.out.println(" -f / --formatted Format output SQL"); - System.out.println(" -h / --help Display this help"); - System.out.println(" -k / --keyword Specify the output keyword style (org.jooq.conf.RenderKeywordStyle)"); - System.out.println(" -i / --identifier Specify the output identifier style (org.jooq.conf.RenderNameStyle)"); - System.out.println(" -t / --to-dialect Specify the output dialect (org.jooq.SQLDialect)"); - System.out.println(" -s / --sql Specify the input SQL string"); + System.out.println(" -f / --formatted Format output SQL"); + System.out.println(" -h / --help Display this help"); + System.out.println(" -k / --keyword Specify the output keyword case (org.jooq.conf.RenderKeywordCase)"); + System.out.println(" -i / --identifier Specify the output identifier case (org.jooq.conf.RenderNameCase)"); + System.out.println(" -t / --to-dialect Specify the output dialect (org.jooq.SQLDialect)"); + System.out.println(" -s / --sql Specify the input SQL string"); } public static final class Args { - String sql; - RenderKeywordStyle keywords; - RenderNameStyle name; - SQLDialect toDialect; - boolean formatted; + String sql; + RenderKeywordCase keywords; + RenderNameCase name; + SQLDialect toDialect; + boolean formatted; } } diff --git a/jOOQ/src/main/java/org/jooq/RenderContext.java b/jOOQ/src/main/java/org/jooq/RenderContext.java index 74534df2e2..3cdd9ad567 100644 --- a/jOOQ/src/main/java/org/jooq/RenderContext.java +++ b/jOOQ/src/main/java/org/jooq/RenderContext.java @@ -38,7 +38,7 @@ package org.jooq; import org.jooq.conf.ParamType; -import org.jooq.conf.RenderKeywordStyle; +import org.jooq.conf.RenderKeywordCase; import org.jooq.conf.Settings; /** @@ -82,7 +82,7 @@ public interface RenderContext extends Context { /** * Append a SQL keyword to the context's contained {@link StringBuilder}. *

- * Use this to have your SQL keyword rendered in {@link RenderKeywordStyle}. + * Use this to have your SQL keyword rendered in {@link RenderKeywordCase}. */ @Override RenderContext keyword(String keyword); diff --git a/jOOQ/src/main/java/org/jooq/Table.java b/jOOQ/src/main/java/org/jooq/Table.java index be8355ec8f..8f7ebaf49b 100644 --- a/jOOQ/src/main/java/org/jooq/Table.java +++ b/jOOQ/src/main/java/org/jooq/Table.java @@ -326,8 +326,8 @@ public interface Table extends TableLike, Named { * Create an alias for this table. *

* Note that the case-sensitivity of the returned table depends on - * {@link Settings#getRenderNameStyle()}. By default, table aliases are - * quoted, and thus case-sensitive! + * {@link Settings#getRenderQuotedNames()}. By default, table aliases are + * quoted, and thus case-sensitive in many SQL dialects! * * @param alias The alias name * @return The table alias @@ -339,8 +339,8 @@ public interface Table extends TableLike, Named { * Create an alias for this table and its fields. *

* Note that the case-sensitivity of the returned table and columns depends - * on {@link Settings#getRenderNameStyle()}. By default, table aliases are - * quoted, and thus case-sensitive! + * on {@link Settings#getRenderQuotedNames()}. By default, table aliases are + * quoted, and thus case-sensitive in many SQL dialects! *

*

Derived column lists for table references
*

@@ -431,9 +431,9 @@ public interface Table extends TableLike, Named { * Create an alias for this table. *

* Note that the case-sensitivity of the returned table depends on - * {@link Settings#getRenderNameStyle()} and the {@link Name}. By default, - * table aliases are quoted, and thus case-sensitive - use - * {@link DSL#unquotedName(String...)} for case-insensitive aliases. + * {@link Settings#getRenderQuotedNames()} and the {@link Name}. By default, + * table aliases are quoted, and thus case-sensitive in many SQL dialects - + * use {@link DSL#unquotedName(String...)} for case-insensitive aliases. *

* If the argument {@link Name#getName()} is qualified, then the * {@link Name#last()} part will be used. @@ -448,9 +448,9 @@ public interface Table extends TableLike, Named { * Create an alias for this table and its fields. *

* Note that the case-sensitivity of the returned table depends on - * {@link Settings#getRenderNameStyle()} and the {@link Name}. By default, - * table aliases are quoted, and thus case-sensitive - use - * {@link DSL#unquotedName(String...)} for case-insensitive aliases. + * {@link Settings#getRenderQuotedNames()} and the {@link Name}. By default, + * table aliases are quoted, and thus case-sensitive in many SQL dialects - + * use {@link DSL#unquotedName(String...)} for case-insensitive aliases. *

* If the argument {@link Name#getName()} is qualified, then the * {@link Name#last()} part will be used. @@ -542,10 +542,6 @@ public interface Table extends TableLike, Named { /** * Create an alias for this table based on another table's name. - *

- * Note that the case-sensitivity of the returned table depends on - * {@link Settings#getRenderNameStyle()}. By default, table aliases are - * quoted, and thus case-sensitive! * * @param otherTable The other table whose name this table is aliased with. * @return The table alias. @@ -555,10 +551,6 @@ public interface Table extends TableLike, Named { /** * Create an alias for this table based on another table's name. - *

- * Note that the case-sensitivity of the returned table depends on - * {@link Settings#getRenderNameStyle()}. By default, table aliases are - * quoted, and thus case-sensitive! * * @param otherTable The other table whose name this table is aliased with. * @param otherFields The other fields whose field name this table's fields diff --git a/jOOQ/src/main/java/org/jooq/conf/RenderKeywordCase.java b/jOOQ/src/main/java/org/jooq/conf/RenderKeywordCase.java new file mode 100644 index 0000000000..85f4f9d992 --- /dev/null +++ b/jOOQ/src/main/java/org/jooq/conf/RenderKeywordCase.java @@ -0,0 +1,49 @@ + + + + + + + + +package org.jooq.conf; + +import javax.xml.bind.annotation.XmlEnum; +import javax.xml.bind.annotation.XmlType; + + +/** + *

Java class for RenderKeywordCase. + * + *

The following schema fragment specifies the expected content contained within this class. + *

+ *

+ * <simpleType name="RenderKeywordCase">
+ *   <restriction base="{http://www.w3.org/2001/XMLSchema}string">
+ *     <enumeration value="AS_IS"/>
+ *     <enumeration value="LOWER"/>
+ *     <enumeration value="UPPER"/>
+ *     <enumeration value="PASCAL"/>
+ *   </restriction>
+ * </simpleType>
+ * 
+ * + */ +@XmlType(name = "RenderKeywordCase") +@XmlEnum +public enum RenderKeywordCase { + + AS_IS, + LOWER, + UPPER, + PASCAL; + + public String value() { + return name(); + } + + public static RenderKeywordCase fromValue(String v) { + return valueOf(v); + } + +} diff --git a/jOOQ/src/main/java/org/jooq/conf/RenderNameCase.java b/jOOQ/src/main/java/org/jooq/conf/RenderNameCase.java new file mode 100644 index 0000000000..f4a3947b2d --- /dev/null +++ b/jOOQ/src/main/java/org/jooq/conf/RenderNameCase.java @@ -0,0 +1,47 @@ + + + + + + + + +package org.jooq.conf; + +import javax.xml.bind.annotation.XmlEnum; +import javax.xml.bind.annotation.XmlType; + + +/** + *

Java class for RenderNameCase. + * + *

The following schema fragment specifies the expected content contained within this class. + *

+ *

+ * <simpleType name="RenderNameCase">
+ *   <restriction base="{http://www.w3.org/2001/XMLSchema}string">
+ *     <enumeration value="AS_IS"/>
+ *     <enumeration value="LOWER"/>
+ *     <enumeration value="UPPER"/>
+ *   </restriction>
+ * </simpleType>
+ * 
+ * + */ +@XmlType(name = "RenderNameCase") +@XmlEnum +public enum RenderNameCase { + + AS_IS, + LOWER, + UPPER; + + public String value() { + return name(); + } + + public static RenderNameCase fromValue(String v) { + return valueOf(v); + } + +} diff --git a/jOOQ/src/main/java/org/jooq/conf/RenderQuotedNames.java b/jOOQ/src/main/java/org/jooq/conf/RenderQuotedNames.java new file mode 100644 index 0000000000..ebaa23702d --- /dev/null +++ b/jOOQ/src/main/java/org/jooq/conf/RenderQuotedNames.java @@ -0,0 +1,45 @@ + + + + + + + + +package org.jooq.conf; + +import javax.xml.bind.annotation.XmlEnum; +import javax.xml.bind.annotation.XmlType; + + +/** + *

Java class for RenderQuotedNames. + * + *

The following schema fragment specifies the expected content contained within this class. + *

+ *

+ * <simpleType name="RenderQuotedNames">
+ *   <restriction base="{http://www.w3.org/2001/XMLSchema}string">
+ *     <enumeration value="ALWAYS"/>
+ *     <enumeration value="NEVER"/>
+ *   </restriction>
+ * </simpleType>
+ * 
+ * + */ +@XmlType(name = "RenderQuotedNames") +@XmlEnum +public enum RenderQuotedNames { + + ALWAYS, + NEVER; + + public String value() { + return name(); + } + + public static RenderQuotedNames fromValue(String v) { + return valueOf(v); + } + +} diff --git a/jOOQ/src/main/java/org/jooq/conf/Settings.java b/jOOQ/src/main/java/org/jooq/conf/Settings.java index 92805cb7c5..5e29a527e7 100644 --- a/jOOQ/src/main/java/org/jooq/conf/Settings.java +++ b/jOOQ/src/main/java/org/jooq/conf/Settings.java @@ -42,11 +42,20 @@ public class Settings @XmlElement(defaultValue = "true") protected Boolean renderSchema = true; protected RenderMapping renderMapping; + @XmlElement(defaultValue = "ALWAYS") + @XmlSchemaType(name = "string") + protected RenderQuotedNames renderQuotedNames = RenderQuotedNames.ALWAYS; + @XmlElement(defaultValue = "AS_IS") + @XmlSchemaType(name = "string") + protected RenderNameCase renderNameCase = RenderNameCase.AS_IS; @XmlElement(defaultValue = "QUOTED") @XmlSchemaType(name = "string") protected RenderNameStyle renderNameStyle = RenderNameStyle.QUOTED; @XmlElement(defaultValue = "AS_IS") @XmlSchemaType(name = "string") + protected RenderKeywordCase renderKeywordCase = RenderKeywordCase.AS_IS; + @XmlElement(defaultValue = "AS_IS") + @XmlSchemaType(name = "string") protected RenderKeywordStyle renderKeywordStyle = RenderKeywordStyle.AS_IS; @XmlElement(type = String.class) @XmlJavaTypeAdapter(LocaleAdapter.class) @@ -217,11 +226,69 @@ public class Settings this.renderMapping = value; } + /** + * Whether rendered schema, table, column names, etc should be quoted. + *

+ * 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. + *

+ * This setting does not affect any plain SQL usage. + * + * @return + * possible object is + * {@link RenderQuotedNames } + * + */ + public RenderQuotedNames getRenderQuotedNames() { + return renderQuotedNames; + } + + /** + * Sets the value of the renderQuotedNames property. + * + * @param value + * allowed object is + * {@link RenderQuotedNames } + * + */ + public void setRenderQuotedNames(RenderQuotedNames value) { + this.renderQuotedNames = value; + } + + /** + * Whether the case of {@link org.jooq.Name} references should be modified in any way. + *

+ * Names are modified irrespective of the {@link #getRenderQuotedNames()} setting. + *

+ * This setting does not affect any plain SQL usage. + * + * @return + * possible object is + * {@link RenderNameCase } + * + */ + public RenderNameCase getRenderNameCase() { + return renderNameCase; + } + + /** + * Sets the value of the renderNameCase property. + * + * @param value + * allowed object is + * {@link RenderNameCase } + * + */ + public void setRenderNameCase(RenderNameCase value) { + this.renderNameCase = value; + } + /** * Whether rendered schema, table, column names, etc should be quoted * in rendered SQL, or transformed in any other way. *

- * This is set to "QUOTED" by default for backwards-compatibility + * This is set to "QUOTED" by default for backwards-compatibility. + *

+ * @deprecated - 3.12.0 - [#5909] - Use {@link RenderQuotedNames} and {@link RenderNameCase} instead. * * @return * possible object is @@ -245,7 +312,33 @@ public class Settings } /** - * Whether SQL keywords should be rendered with upper or lower case. + * Whether the case of {@link org.jooq.Keyword} references should be modified in any way. + * + * @return + * possible object is + * {@link RenderKeywordCase } + * + */ + public RenderKeywordCase getRenderKeywordCase() { + return renderKeywordCase; + } + + /** + * Sets the value of the renderKeywordCase property. + * + * @param value + * allowed object is + * {@link RenderKeywordCase } + * + */ + public void setRenderKeywordCase(RenderKeywordCase value) { + this.renderKeywordCase = value; + } + + /** + * Whether the case of {@link org.jooq.Keyword} references should be modified in any way. + *

+ * @deprecated - 3.12.0 - [#5909] - Use {@link RenderQuotedNames} and {@link RenderNameCase} instead. * * @return * possible object is @@ -1233,11 +1326,26 @@ public class Settings return this; } + public Settings withRenderQuotedNames(RenderQuotedNames value) { + setRenderQuotedNames(value); + return this; + } + + public Settings withRenderNameCase(RenderNameCase value) { + setRenderNameCase(value); + return this; + } + public Settings withRenderNameStyle(RenderNameStyle value) { setRenderNameStyle(value); return this; } + public Settings withRenderKeywordCase(RenderKeywordCase value) { + setRenderKeywordCase(value); + return this; + } + public Settings withRenderKeywordStyle(RenderKeywordStyle value) { setRenderKeywordStyle(value); return this; @@ -1451,11 +1559,26 @@ public class Settings sb.append(renderMapping); sb.append(""); } + if (renderQuotedNames!= null) { + sb.append(""); + sb.append(renderQuotedNames); + sb.append(""); + } + if (renderNameCase!= null) { + sb.append(""); + sb.append(renderNameCase); + sb.append(""); + } if (renderNameStyle!= null) { sb.append(""); sb.append(renderNameStyle); sb.append(""); } + if (renderKeywordCase!= null) { + sb.append(""); + sb.append(renderKeywordCase); + sb.append(""); + } if (renderKeywordStyle!= null) { sb.append(""); sb.append(renderKeywordStyle); @@ -1693,6 +1816,24 @@ public class Settings return false; } } + if (renderQuotedNames == null) { + if (other.renderQuotedNames!= null) { + return false; + } + } else { + if (!renderQuotedNames.equals(other.renderQuotedNames)) { + return false; + } + } + if (renderNameCase == null) { + if (other.renderNameCase!= null) { + return false; + } + } else { + if (!renderNameCase.equals(other.renderNameCase)) { + return false; + } + } if (renderNameStyle == null) { if (other.renderNameStyle!= null) { return false; @@ -1702,6 +1843,15 @@ public class Settings return false; } } + if (renderKeywordCase == null) { + if (other.renderKeywordCase!= null) { + return false; + } + } else { + if (!renderKeywordCase.equals(other.renderKeywordCase)) { + return false; + } + } if (renderKeywordStyle == null) { if (other.renderKeywordStyle!= null) { return false; @@ -2063,7 +2213,10 @@ public class Settings result = ((prime*result)+((renderCatalog == null)? 0 :renderCatalog.hashCode())); result = ((prime*result)+((renderSchema == null)? 0 :renderSchema.hashCode())); result = ((prime*result)+((renderMapping == null)? 0 :renderMapping.hashCode())); + result = ((prime*result)+((renderQuotedNames == null)? 0 :renderQuotedNames.hashCode())); + result = ((prime*result)+((renderNameCase == null)? 0 :renderNameCase.hashCode())); result = ((prime*result)+((renderNameStyle == null)? 0 :renderNameStyle.hashCode())); + result = ((prime*result)+((renderKeywordCase == null)? 0 :renderKeywordCase.hashCode())); result = ((prime*result)+((renderKeywordStyle == null)? 0 :renderKeywordStyle.hashCode())); result = ((prime*result)+((renderLocale == null)? 0 :renderLocale.hashCode())); result = ((prime*result)+((renderFormatted == null)? 0 :renderFormatted.hashCode())); diff --git a/jOOQ/src/main/java/org/jooq/conf/SettingsTools.java b/jOOQ/src/main/java/org/jooq/conf/SettingsTools.java index af97be1d4e..9dd9737450 100644 --- a/jOOQ/src/main/java/org/jooq/conf/SettingsTools.java +++ b/jOOQ/src/main/java/org/jooq/conf/SettingsTools.java @@ -180,6 +180,74 @@ public final class SettingsTools { return settings.getRenderMapping(); } + /** + * Backwards compatible access to {@link RenderKeywordCase} and/or + * {@link RenderKeywordStyle} (the latter being deprecated). + */ + public static final RenderKeywordCase getRenderKeywordCase(Settings settings) { + RenderKeywordCase result = settings.getRenderKeywordCase(); + + if (result == null || result == RenderKeywordCase.AS_IS) { + RenderKeywordStyle style = settings.getRenderKeywordStyle(); + + if (style != null) { + switch (style) { + case AS_IS: result = RenderKeywordCase.AS_IS; break; + case LOWER: result = RenderKeywordCase.LOWER; break; + case UPPER: result = RenderKeywordCase.UPPER; break; + case PASCAL: result = RenderKeywordCase.PASCAL; break; + default: + throw new UnsupportedOperationException("Unsupported style: " + style); + } + } + else { + result = RenderKeywordCase.AS_IS; + } + } + + return result; + } + + /** + * Backwards compatible access to {@link RenderNameCase} and/or + * {@link RenderNameStyle} (the latter being deprecated). + */ + public static final RenderNameCase getRenderNameCase(Settings settings) { + RenderNameCase result = settings.getRenderNameCase(); + + if (result == null || result == RenderNameCase.AS_IS) { + RenderNameStyle style = settings.getRenderNameStyle(); + + if (style == RenderNameStyle.LOWER) + result = RenderNameCase.LOWER; + else if (style == RenderNameStyle.UPPER) + result = RenderNameCase.UPPER; + else + result = RenderNameCase.AS_IS; + } + + return result; + } + + /** + * Backwards compatible access to {@link RenderQuotedNames} and/or + * {@link RenderNameStyle} (the latter being deprecated). + */ + public static final RenderQuotedNames getRenderQuotedNames(Settings settings) { + RenderQuotedNames result = settings.getRenderQuotedNames(); + + if (result == null || result == RenderQuotedNames.ALWAYS) { + RenderNameStyle style = settings.getRenderNameStyle(); + + if (style == null || style == RenderNameStyle.QUOTED) + result = RenderQuotedNames.ALWAYS; + else + result = RenderQuotedNames.NEVER; + } + + return result; + } + /** * Lazy access to {@link Settings#getExecuteUpdateWithoutWhere()}. */ diff --git a/jOOQ/src/main/java/org/jooq/impl/AbstractContext.java b/jOOQ/src/main/java/org/jooq/impl/AbstractContext.java index 2d081d3035..1cbdd2329c 100644 --- a/jOOQ/src/main/java/org/jooq/impl/AbstractContext.java +++ b/jOOQ/src/main/java/org/jooq/impl/AbstractContext.java @@ -80,7 +80,7 @@ import org.jooq.VisitListener; import org.jooq.VisitListenerProvider; import org.jooq.conf.ParamCastMode; import org.jooq.conf.ParamType; -import org.jooq.conf.RenderNameStyle; +import org.jooq.conf.RenderQuotedNames; import org.jooq.conf.Settings; import org.jooq.conf.SettingsTools; import org.jooq.conf.StatementType; @@ -179,7 +179,7 @@ abstract class AbstractContext> extends AbstractScope imple : m == ParamCastMode.NEVER ? CastMode.NEVER : CastMode.DEFAULT; - this.quote = settings().getRenderNameStyle() == RenderNameStyle.QUOTED; + this.quote = SettingsTools.getRenderQuotedNames(settings()) == RenderQuotedNames.ALWAYS; this.scopeStack = new ScopeStack(); } diff --git a/jOOQ/src/main/java/org/jooq/impl/AbstractDMLQuery.java b/jOOQ/src/main/java/org/jooq/impl/AbstractDMLQuery.java index e69275e6a0..21c8bd4e62 100644 --- a/jOOQ/src/main/java/org/jooq/impl/AbstractDMLQuery.java +++ b/jOOQ/src/main/java/org/jooq/impl/AbstractDMLQuery.java @@ -46,8 +46,6 @@ import static org.jooq.SQLDialect.HSQLDB; // ... // ... // ... -import static org.jooq.conf.RenderNameStyle.LOWER; -import static org.jooq.conf.RenderNameStyle.UPPER; import static org.jooq.conf.SettingsTools.renderLocale; import static org.jooq.impl.DSL.select; import static org.jooq.impl.DSL.unquotedName; @@ -104,7 +102,8 @@ import org.jooq.Select; import org.jooq.SelectFieldOrAsterisk; import org.jooq.Table; import org.jooq.conf.ExecuteWithoutWhere; -import org.jooq.conf.RenderNameStyle; +import org.jooq.conf.RenderNameCase; +import org.jooq.conf.SettingsTools; import org.jooq.exception.DataAccessException; import org.jooq.impl.Tools.DataKey; import org.jooq.tools.JooqLogger; @@ -619,22 +618,22 @@ abstract class AbstractDMLQuery extends AbstractQuery { case HSQLDB: default: { String[] names = new String[returningResolvedAsterisks.size()]; - RenderNameStyle style = configuration().settings().getRenderNameStyle(); + RenderNameCase style = SettingsTools.getRenderNameCase(configuration().settings()); - for (int i = 0; i < names.length; i++) { - - // [#2845] Field names should be passed to JDBC in the case - // imposed by the user. For instance, if the user uses - // PostgreSQL generated case-insensitive Fields (default to lower case) - // and wants to query HSQLDB (default to upper case), they may choose - // to overwrite casing using RenderKeywordStyle. - if (style == UPPER) + // [#2845] Field names should be passed to JDBC in the case + // imposed by the user. For instance, if the user uses + // PostgreSQL generated case-insensitive Fields (default to lower case) + // and wants to query HSQLDB (default to upper case), they may choose + // to overwrite casing using RenderNameCase. + if (style == RenderNameCase.UPPER) + for (int i = 0; i < names.length; i++) names[i] = returningResolvedAsterisks.get(i).getName().toUpperCase(renderLocale(configuration().settings())); - else if (style == LOWER) + else if (style == RenderNameCase.LOWER) + for (int i = 0; i < names.length; i++) names[i] = returningResolvedAsterisks.get(i).getName().toLowerCase(renderLocale(configuration().settings())); - else + else + for (int i = 0; i < names.length; i++) names[i] = returningResolvedAsterisks.get(i).getName(); - } ctx.statement(connection.prepareStatement(ctx.sql(), names)); return; diff --git a/jOOQ/src/main/java/org/jooq/impl/DSL.java b/jOOQ/src/main/java/org/jooq/impl/DSL.java index a10e4a7a4f..a70b23205f 100644 --- a/jOOQ/src/main/java/org/jooq/impl/DSL.java +++ b/jOOQ/src/main/java/org/jooq/impl/DSL.java @@ -359,7 +359,6 @@ import org.jooq.WithAsStep7; import org.jooq.WithAsStep8; import org.jooq.WithAsStep9; import org.jooq.WithStep; -import org.jooq.conf.RenderNameStyle; import org.jooq.conf.Settings; import org.jooq.exception.SQLDialectNotSupportedException; import org.jooq.tools.Convert; @@ -8888,7 +8887,7 @@ public class DSL { *

* A Keyword is a {@link QueryPart} that renders a SQL keyword * according to the settings specified in - * {@link Settings#getRenderKeywordStyle()}. It can be embedded in other + * {@link Settings#getRenderKeywordCase()}. It can be embedded in other * plain SQL QueryParts as shown in this example: *

*

@@ -8923,7 +8922,7 @@ public class DSL {
      * // This unqualified name here
      * name("book");
      *
-     * // ... will render this SQL on SQL Server with RenderNameStyle.QUOTED set
+     * // ... will render this SQL by default, using the SQL Server dialect
      * [book].[title]
      * 
* @@ -8950,7 +8949,7 @@ public class DSL { * // This qualified name here * name("book", "title"); * - * // ... will render this SQL on SQL Server with RenderNameStyle.QUOTED set + * // ... will render this SQL by default, using the SQL Server dialect * [book].[title] * * @@ -8984,7 +8983,7 @@ public class DSL { * // This qualified name here * name(quotedName("book"), unquotedName("title")); * - * // ... will render this SQL on SQL Server with RenderNameStyle.QUOTED set + * // ... will render this SQL by default, using the SQL Server dialect * [book].title * * @@ -9011,7 +9010,7 @@ public class DSL { * // This qualified name here * name("book", "title"); * - * // ... will render this SQL on SQL Server with RenderNameStyle.QUOTED set + * // ... will render this SQL by default, using the SQL Server dialect * [book].[title] * * @@ -9178,16 +9177,12 @@ public class DSL { * Create a qualified schema, given its schema name. *

* This constructs a schema reference given the schema's qualified name. - * jOOQ will render the schema name according to your - * {@link Settings#getRenderNameStyle()} settings. Choose - * {@link RenderNameStyle#QUOTED} to prevent syntax errors and/or SQL - * injection. *

* Example:

      * // This schema...
      * schemaByName("MY_SCHEMA");
      *
-     * // ... will render this SQL on SQL Server with RenderNameStyle.QUOTED set
+     * // ... will render this SQL by default, using the SQL Server dialect
      * [MY_SCHEMA]
      * 
* @@ -9205,16 +9200,12 @@ public class DSL { * Create a qualified catalog, given its catalog name. *

* This constructs a catalog reference given the catalog's qualified name. - * jOOQ will render the catalog name according to your - * {@link Settings#getRenderNameStyle()} settings. Choose - * {@link RenderNameStyle#QUOTED} to prevent syntax errors and/or SQL - * injection. *

* Example:

      * // This catalog...
      * catalog(name("MY_CATALOG"));
      *
-     * // ... will render this SQL on SQL Server with RenderNameStyle.QUOTED set
+     * // ... will render this SQL by default, using the SQL Server dialect
      * [MY_CATALOG]
      * 
*/ @@ -9227,16 +9218,12 @@ public class DSL { * Create a qualified schema, given its schema name. *

* This constructs a schema reference given the schema's qualified name. - * jOOQ will render the schema name according to your - * {@link Settings#getRenderNameStyle()} settings. Choose - * {@link RenderNameStyle#QUOTED} to prevent syntax errors and/or SQL - * injection. *

* Example:

      * // This schema...
      * schema(name("MY_CATALOG", "MY_SCHEMA"));
      *
-     * // ... will render this SQL on SQL Server with RenderNameStyle.QUOTED set
+     * // ... will render this SQL by default, using the SQL Server dialect
      * [MY_CATALOG].[MY_SCHEMA]
      * 
*/ @@ -9249,16 +9236,12 @@ public class DSL { * Create a qualified sequence, given its sequence name. *

* This constructs a sequence reference given the sequence's qualified name. - * jOOQ will render the sequence name according to your - * {@link Settings#getRenderNameStyle()} settings. Choose - * {@link RenderNameStyle#QUOTED} to prevent syntax errors and/or SQL - * injection. *

* Example:

      * // This sequence...
      * sequenceByName("MY_SCHEMA", "MY_SEQUENCE");
      *
-     * // ... will render this SQL on SQL Server with RenderNameStyle.QUOTED set
+     * // ... will render this SQL by default, using the SQL Server dialect
      * [MY_SCHEMA].[MY_SEQUENCE]
      * 
* @@ -9277,16 +9260,12 @@ public class DSL { * Create a qualified sequence, given its sequence name. *

* This constructs a sequence reference given the sequence's qualified name. - * jOOQ will render the sequence name according to your - * {@link Settings#getRenderNameStyle()} settings. Choose - * {@link RenderNameStyle#QUOTED} to prevent syntax errors and/or SQL - * injection. *

* Example:

      * // This sequence...
      * sequenceByName("MY_SCHEMA", "MY_SEQUENCE");
      *
-     * // ... will render this SQL on SQL Server with RenderNameStyle.QUOTED set
+     * // ... will render this SQL by default, using the SQL Server dialect
      * [MY_SCHEMA].[MY_SEQUENCE]
      * 
* @@ -9306,16 +9285,12 @@ public class DSL { * Create a qualified sequence, given its sequence name. *

* This constructs a sequence reference given the sequence's qualified name. - * jOOQ will render the sequence name according to your - * {@link Settings#getRenderNameStyle()} settings. Choose - * {@link RenderNameStyle#QUOTED} to prevent syntax errors and/or SQL - * injection. *

* Example:

      * // This sequence...
      * sequenceByName("MY_SCHEMA", "MY_SEQUENCE");
      *
-     * // ... will render this SQL on SQL Server with RenderNameStyle.QUOTED set
+     * // ... will render this SQL by default, using the SQL Server dialect
      * [MY_SCHEMA].[MY_SEQUENCE]
      * 
* @@ -9344,16 +9319,12 @@ public class DSL { * Create a qualified sequence, given its sequence name. *

* This constructs a sequence reference given the sequence's qualified name. - * jOOQ will render the sequence name according to your - * {@link Settings#getRenderNameStyle()} settings. Choose - * {@link RenderNameStyle#QUOTED} to prevent syntax errors and/or SQL - * injection. *

* Example:

      * // This sequence...
      * sequence(name("MY_SCHEMA", "MY_SEQUENCE"));
      *
-     * // ... will render this SQL on SQL Server with RenderNameStyle.QUOTED set
+     * // ... will render this SQL by default, using the SQL Server dialect
      * [MY_SCHEMA].[MY_SEQUENCE]
      * 
*/ @@ -9366,16 +9337,12 @@ public class DSL { * Create a qualified sequence, given its sequence name. *

* This constructs a sequence reference given the sequence's qualified name. - * jOOQ will render the sequence name according to your - * {@link Settings#getRenderNameStyle()} settings. Choose - * {@link RenderNameStyle#QUOTED} to prevent syntax errors and/or SQL - * injection. *

* Example:

      * // This sequence...
      * sequence(name("MY_SCHEMA", "MY_SEQUENCE"));
      *
-     * // ... will render this SQL on SQL Server with RenderNameStyle.QUOTED set
+     * // ... will render this SQL by default, using the SQL Server dialect
      * [MY_SCHEMA].[MY_SEQUENCE]
      * 
*/ @@ -9388,16 +9355,12 @@ public class DSL { * Create a qualified sequence, given its sequence name. *

* This constructs a sequence reference given the sequence's qualified name. - * jOOQ will render the sequence name according to your - * {@link Settings#getRenderNameStyle()} settings. Choose - * {@link RenderNameStyle#QUOTED} to prevent syntax errors and/or SQL - * injection. *

* Example:

      * // This sequence...
      * sequence(name("MY_SCHEMA", "MY_SEQUENCE"));
      *
-     * // ... will render this SQL on SQL Server with RenderNameStyle.QUOTED set
+     * // ... will render this SQL by default, using the SQL Server dialect
      * [MY_SCHEMA].[MY_SEQUENCE]
      * 
*/ @@ -9419,16 +9382,12 @@ public class DSL { * Create a qualified table, given its table name. *

* This constructs a table reference given the table's qualified name. jOOQ - * will render the table name according to your - * {@link Settings#getRenderNameStyle()} settings. Choose - * {@link RenderNameStyle#QUOTED} to prevent syntax errors and/or SQL - * injection. *

* Example:

      * // This table...
      * tableByName("MY_SCHEMA", "MY_TABLE");
      *
-     * // ... will render this SQL on SQL Server with RenderNameStyle.QUOTED set
+     * // ... will render this SQL by default, using the SQL Server dialect
      * [MY_SCHEMA].[MY_TABLE]
      * 
* @@ -9447,16 +9406,12 @@ public class DSL { * Create a qualified table, given its table name. *

* This constructs a table reference given the table's qualified name. jOOQ - * will render the table name according to your - * {@link Settings#getRenderNameStyle()} settings. Choose - * {@link RenderNameStyle#QUOTED} to prevent syntax errors and/or SQL - * injection. *

* Example:

      * // This table...
      * tableByName("MY_SCHEMA", "MY_TABLE");
      *
-     * // ... will render this SQL on SQL Server with RenderNameStyle.QUOTED set
+     * // ... will render this SQL by default, using the SQL Server dialect
      * [MY_SCHEMA].[MY_TABLE]
      * 
*

@@ -9472,16 +9427,12 @@ public class DSL { * Create a qualified table, given its table name. *

* This constructs a table reference given the table's qualified name. jOOQ - * will render the table name according to your - * {@link Settings#getRenderNameStyle()} settings. Choose - * {@link RenderNameStyle#QUOTED} to prevent syntax errors and/or SQL - * injection. *

* Example:

      * // This table...
      * tableByName("MY_SCHEMA", "MY_TABLE");
      *
-     * // ... will render this SQL on SQL Server with RenderNameStyle.QUOTED set
+     * // ... will render this SQL by default, using the SQL Server dialect
      * [MY_SCHEMA].[MY_TABLE]
      * 
*

@@ -9497,16 +9448,12 @@ public class DSL { * Create a qualified field, given its (qualified) field name. *

* This constructs a field reference given the field's qualified name. jOOQ - * will render the field name according to your - * {@link Settings#getRenderNameStyle()} settings. Choose - * {@link RenderNameStyle#QUOTED} to prevent syntax errors and/or SQL - * injection. *

* Example:

      * // This field...
      * fieldByName("MY_SCHEMA", "MY_TABLE", "MY_FIELD");
      *
-     * // ... will render this SQL on SQL Server with RenderNameStyle.QUOTED set
+     * // ... will render this SQL by default, using the SQL Server dialect
      * [MY_SCHEMA].[MY_TABLE].[MY_FIELD]
      * 
*

@@ -9534,16 +9481,12 @@ public class DSL { * Create a qualified field, given its (qualified) field name. *

* This constructs a field reference given the field's qualified name. jOOQ - * will render the field name according to your - * {@link Settings#getRenderNameStyle()} settings. Choose - * {@link RenderNameStyle#QUOTED} to prevent syntax errors and/or SQL - * injection. *

* Example:

      * // This field...
      * fieldByName("MY_SCHEMA", "MY_TABLE", "MY_FIELD");
      *
-     * // ... will render this SQL on SQL Server with RenderNameStyle.QUOTED set
+     * // ... will render this SQL by default, using the SQL Server dialect
      * [MY_SCHEMA].[MY_TABLE].[MY_FIELD]
      * 
*

@@ -9572,16 +9515,12 @@ public class DSL { * Create a qualified field, given its (qualified) field name. *

* This constructs a field reference given the field's qualified name. jOOQ - * will render the field name according to your - * {@link Settings#getRenderNameStyle()} settings. Choose - * {@link RenderNameStyle#QUOTED} to prevent syntax errors and/or SQL - * injection. *

* Example:

      * // This field...
      * fieldByName("MY_SCHEMA", "MY_TABLE", "MY_FIELD");
      *
-     * // ... will render this SQL on SQL Server with RenderNameStyle.QUOTED set
+     * // ... will render this SQL by default, using the SQL Server dialect
      * [MY_SCHEMA].[MY_TABLE].[MY_FIELD]
      * 
*

@@ -9610,16 +9549,12 @@ public class DSL { * Create a qualified field, given its (qualified) field name. *

* This constructs a field reference given the field's qualified name. jOOQ - * will render the field name according to your - * {@link Settings#getRenderNameStyle()} settings. Choose - * {@link RenderNameStyle#QUOTED} to prevent syntax errors and/or SQL - * injection. *

* Example:

      * // This field...
      * field(name("MY_SCHEMA", "MY_TABLE", "MY_FIELD"));
      *
-     * // ... will render this SQL on SQL Server with RenderNameStyle.QUOTED set
+     * // ... will render this SQL by default, using the SQL Server dialect
      * [MY_SCHEMA].[MY_TABLE].[MY_FIELD]
      * 
*

@@ -9641,16 +9576,12 @@ public class DSL { * Create a qualified field, given its (qualified) field name. *

* This constructs a field reference given the field's qualified name. jOOQ - * will render the field name according to your - * {@link Settings#getRenderNameStyle()} settings. Choose - * {@link RenderNameStyle#QUOTED} to prevent syntax errors and/or SQL - * injection. *

* Example:

      * // This field...
      * field(name("MY_SCHEMA", "MY_TABLE", "MY_FIELD"));
      *
-     * // ... will render this SQL on SQL Server with RenderNameStyle.QUOTED set
+     * // ... will render this SQL by default, using the SQL Server dialect
      * [MY_SCHEMA].[MY_TABLE].[MY_FIELD]
      * 
*

@@ -9672,16 +9603,12 @@ public class DSL { * Create a qualified field, given its (qualified) field name. *

* This constructs a field reference given the field's qualified name. jOOQ - * will render the field name according to your - * {@link Settings#getRenderNameStyle()} settings. Choose - * {@link RenderNameStyle#QUOTED} to prevent syntax errors and/or SQL - * injection. *

* Example:

      * // This field...
      * field(name("MY_SCHEMA", "MY_TABLE", "MY_FIELD"));
      *
-     * // ... will render this SQL on SQL Server with RenderNameStyle.QUOTED set
+     * // ... will render this SQL by default, using the SQL Server dialect
      * [MY_SCHEMA].[MY_TABLE].[MY_FIELD]
      * 
*

@@ -9703,16 +9630,12 @@ public class DSL { * Create a qualified field, given its (qualified) field name. *

* This constructs a field reference given the field's qualified name. jOOQ - * will render the field name according to your - * {@link Settings#getRenderNameStyle()} settings. Choose - * {@link RenderNameStyle#QUOTED} to prevent syntax errors and/or SQL - * injection. *

* Example:

      * // This field...
      * field(name("MY_SCHEMA", "MY_TABLE", "MY_FIELD"));
      *
-     * // ... will render this SQL on SQL Server with RenderNameStyle.QUOTED set
+     * // ... will render this SQL by default, using the SQL Server dialect
      * [MY_SCHEMA].[MY_TABLE].[MY_FIELD]
      * 
*

@@ -10072,7 +9995,7 @@ public class DSL { * // The following query * query("select {0}, {1} from {2}", val(1), inline("test"), name("DUAL")); * - * // Will render this SQL on an Oracle database with RenderNameStyle.QUOTED: + * // Will render this SQL by default, using Oracle SQL dialect * select ?, 'test' from "DUAL" * *

@@ -10253,7 +10176,7 @@ public class DSL { * // The following query * resultQuery("select {0}, {1} from {2}", val(1), inline("test"), name("DUAL")); * - * // Will render this SQL on an Oracle database with RenderNameStyle.QUOTED: + * // Will render this SQL by default, using Oracle SQL dialect * select ?, 'test' from "DUAL" * *

diff --git a/jOOQ/src/main/java/org/jooq/impl/DefaultRenderContext.java b/jOOQ/src/main/java/org/jooq/impl/DefaultRenderContext.java index 7299147f01..2af15620da 100644 --- a/jOOQ/src/main/java/org/jooq/impl/DefaultRenderContext.java +++ b/jOOQ/src/main/java/org/jooq/impl/DefaultRenderContext.java @@ -41,8 +41,6 @@ import static org.jooq.SQLDialect.SQLITE; import static org.jooq.conf.ParamType.INDEXED; import static org.jooq.conf.ParamType.INLINED; import static org.jooq.conf.ParamType.NAMED; -import static org.jooq.conf.RenderNameStyle.LOWER; -import static org.jooq.conf.RenderNameStyle.UPPER; import static org.jooq.conf.SettingsTools.renderLocale; import static org.jooq.impl.Identifiers.QUOTES; import static org.jooq.impl.Identifiers.QUOTE_END_DELIMITER; @@ -71,9 +69,11 @@ import org.jooq.RenderContext; import org.jooq.SQLDialect; import org.jooq.Table; import org.jooq.conf.RenderFormatting; -import org.jooq.conf.RenderKeywordStyle; -import org.jooq.conf.RenderNameStyle; +import org.jooq.conf.RenderKeywordCase; +import org.jooq.conf.RenderNameCase; +import org.jooq.conf.RenderQuotedNames; import org.jooq.conf.Settings; +import org.jooq.conf.SettingsTools; import org.jooq.exception.ControlFlowSignal; import org.jooq.exception.DataAccessException; import org.jooq.impl.Tools.DataKey; @@ -102,8 +102,9 @@ class DefaultRenderContext extends AbstractContext implements Ren private int skipUpdateCounts; // [#1632] Cached values from Settings - RenderKeywordStyle cachedRenderKeywordStyle; - RenderNameStyle cachedRenderNameStyle; + RenderKeywordCase cachedRenderKeywordCase; + RenderNameCase cachedRenderNameCase; + RenderQuotedNames cachedRenderQuotedNames; boolean cachedRenderFormatted; // [#6525] Cached values from Settings.renderFormatting @@ -119,9 +120,10 @@ class DefaultRenderContext extends AbstractContext implements Ren this.sql = new StringBuilder(); this.bindValues = new QueryPartList>(); - this.cachedRenderKeywordStyle = settings.getRenderKeywordStyle(); + this.cachedRenderKeywordCase = SettingsTools.getRenderKeywordCase(settings); this.cachedRenderFormatted = Boolean.TRUE.equals(settings.isRenderFormatted()); - this.cachedRenderNameStyle = settings.getRenderNameStyle(); + this.cachedRenderNameCase = SettingsTools.getRenderNameCase(settings); + this.cachedRenderQuotedNames = SettingsTools.getRenderQuotedNames(settings); RenderFormatting formatting = settings.getRenderFormatting(); if (formatting == null) @@ -467,15 +469,12 @@ class DefaultRenderContext extends AbstractContext implements Ren // [#1982] [#3360] ... yet, do quote when an identifier contains special characters (family == SQLITE && !IDENTIFIER_PATTERN.matcher(literal).matches()); - if (!needsQuote) { - if (LOWER == cachedRenderNameStyle) - literal = literal.toLowerCase(renderLocale(configuration().settings())); - else if (UPPER == cachedRenderNameStyle) - literal = literal.toUpperCase(renderLocale(configuration().settings())); + if (RenderNameCase.LOWER == cachedRenderNameCase) + literal = literal.toLowerCase(renderLocale(configuration().settings())); + else if (RenderNameCase.UPPER == cachedRenderNameCase) + literal = literal.toUpperCase(renderLocale(configuration().settings())); - sql(literal, true); - } - else { + if (needsQuote) { char[][][] quotes = QUOTES.get(family); char start = quotes[QUOTE_START_DELIMITER][0][0]; @@ -493,6 +492,9 @@ class DefaultRenderContext extends AbstractContext implements Ren sql(end); } + else { + sql(literal, true); + } return this; } diff --git a/jOOQ/src/main/java/org/jooq/impl/KeywordImpl.java b/jOOQ/src/main/java/org/jooq/impl/KeywordImpl.java index 26c76efc7b..5efecb1b33 100644 --- a/jOOQ/src/main/java/org/jooq/impl/KeywordImpl.java +++ b/jOOQ/src/main/java/org/jooq/impl/KeywordImpl.java @@ -40,7 +40,8 @@ package org.jooq.impl; import org.jooq.Clause; import org.jooq.Context; import org.jooq.Keyword; -import org.jooq.conf.RenderKeywordStyle; +import org.jooq.conf.RenderKeywordCase; +import org.jooq.conf.SettingsTools; /** * A default {@link Keyword} implementation. @@ -70,16 +71,16 @@ public class KeywordImpl extends AbstractQueryPart implements Keyword { @Override public final void accept(Context ctx) { - RenderKeywordStyle style = ctx.settings().getRenderKeywordStyle(); + RenderKeywordCase style = SettingsTools.getRenderKeywordCase(ctx.settings()); - if (RenderKeywordStyle.AS_IS == style) - ctx.sql(asIs, true); - else if (RenderKeywordStyle.UPPER == style) - ctx.sql(upper, true); - else if (RenderKeywordStyle.PASCAL == style) - ctx.sql(pascal, true); - else - ctx.sql(lower, true); + switch (style) { + case AS_IS: ctx.sql(asIs, true); break; + case LOWER: ctx.sql(lower, true); break; + case UPPER: ctx.sql(upper, true); break; + case PASCAL: ctx.sql(pascal, true); break; + default: + throw new UnsupportedOperationException("Unsupported style: " + style); + } } @Override diff --git a/jOOQ/src/main/resources/xsd/jooq-runtime-3.12.0.xsd b/jOOQ/src/main/resources/xsd/jooq-runtime-3.12.0.xsd index 6bab48cf9e..908fc938b4 100644 --- a/jOOQ/src/main/resources/xsd/jooq-runtime-3.12.0.xsd +++ b/jOOQ/src/main/resources/xsd/jooq-runtime-3.12.0.xsd @@ -33,15 +33,39 @@ available using synonyms]]> generated SQL.]]> + + +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. +

+This setting does not affect any plain SQL usage.]]> + + + + +Names are modified irrespective of the {@link #getRenderQuotedNames()} setting. +

+This setting does not affect any plain SQL usage.]]> + + -This is set to "QUOTED" by default for backwards-compatibility]]> +This is set to "QUOTED" by default for backwards-compatibility. +

+@deprecated - 3.12.0 - [#5909] - Use {@link RenderQuotedNames} and {@link RenderNameCase} instead.]]> + + + + - + +@deprecated - 3.12.0 - [#5909] - Use {@link RenderQuotedNames} and {@link RenderNameCase} instead.]]> @@ -402,6 +426,57 @@ Either <input/> or <inputExpression/> must be provided]]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +