diff --git a/jOOQ-meta-extensions/src/main/java/org/jooq/meta/extensions/ddl/DDLDatabase.java b/jOOQ-meta-extensions/src/main/java/org/jooq/meta/extensions/ddl/DDLDatabase.java index cf93d4012b..791b9d725c 100644 --- a/jOOQ-meta-extensions/src/main/java/org/jooq/meta/extensions/ddl/DDLDatabase.java +++ b/jOOQ-meta-extensions/src/main/java/org/jooq/meta/extensions/ddl/DDLDatabase.java @@ -37,6 +37,7 @@ */ package org.jooq.meta.extensions.ddl; +// ... import static org.jooq.conf.SettingsTools.renderLocale; import static org.jooq.impl.DSL.name; import static org.jooq.tools.StringUtils.isBlank; @@ -55,6 +56,7 @@ import org.jooq.Name; import org.jooq.Name.Quoted; import org.jooq.Queries; import org.jooq.Query; +// ... import org.jooq.ResultQuery; import org.jooq.Source; import org.jooq.VisitContext; @@ -171,6 +173,12 @@ public class DDLDatabase extends AbstractInterpretingDatabase { Scanner s = new Scanner(r = source.reader()).useDelimiter("\\A"); Queries queries = ctx.parser().parse(s.hasNext() ? s.next() : ""); + + + + + + for (Query query : queries) { repeat: diff --git a/jOOQ/src/main/java/org/jooq/AlterTableStep.java b/jOOQ/src/main/java/org/jooq/AlterTableStep.java index 5686af6836..653abdfd01 100644 --- a/jOOQ/src/main/java/org/jooq/AlterTableStep.java +++ b/jOOQ/src/main/java/org/jooq/AlterTableStep.java @@ -325,7 +325,7 @@ public interface AlterTableStep { */ @NotNull @CheckReturnValue @Support({ FIREBIRD, H2, IGNITE, MARIADB, MYSQL, POSTGRES, YUGABYTEDB }) - AlterTableAddStep add(FieldOrConstraint... fields); + AlterTableAddStep add(TableElement... fields); /** * Add an ADD clause with multiple columns or constraints to @@ -333,7 +333,7 @@ public interface AlterTableStep { */ @NotNull @CheckReturnValue @Support({ FIREBIRD, H2, IGNITE, MARIADB, MYSQL, POSTGRES, YUGABYTEDB }) - AlterTableAddStep add(Collection fields); + AlterTableAddStep add(Collection fields); /** * Add an ADD COLUMN clause to the ALTER TABLE diff --git a/jOOQ/src/main/java/org/jooq/Constraint.java b/jOOQ/src/main/java/org/jooq/Constraint.java index cbb2c57bec..d56adb1a25 100644 --- a/jOOQ/src/main/java/org/jooq/Constraint.java +++ b/jOOQ/src/main/java/org/jooq/Constraint.java @@ -61,6 +61,10 @@ import org.jooq.impl.DSL; * * @author Lukas Eder */ -public /* non-sealed */ interface Constraint extends FieldOrConstraint { +public /* non-sealed */ interface Constraint +extends + FieldOrConstraint, + TableElement +{ } diff --git a/jOOQ/src/main/java/org/jooq/CreateTableAsStep.java b/jOOQ/src/main/java/org/jooq/CreateTableAsStep.java index e9d1838078..94b5d4f7f9 100644 --- a/jOOQ/src/main/java/org/jooq/CreateTableAsStep.java +++ b/jOOQ/src/main/java/org/jooq/CreateTableAsStep.java @@ -37,37 +37,14 @@ */ package org.jooq; -// ... -// ... -// ... -// ... -// ... -import static org.jooq.SQLDialect.CUBRID; -// ... -import static org.jooq.SQLDialect.DERBY; -// ... -import static org.jooq.SQLDialect.H2; -// ... -import static org.jooq.SQLDialect.HSQLDB; -// ... -import static org.jooq.SQLDialect.MARIADB; -// ... -import static org.jooq.SQLDialect.MYSQL; -// ... -import static org.jooq.SQLDialect.POSTGRES; -// ... -// ... -// ... -import static org.jooq.SQLDialect.SQLITE; -// ... -// ... -// ... -import static org.jooq.SQLDialect.YUGABYTEDB; +import static org.jooq.SQLDialect.*; -import org.jetbrains.annotations.NotNull; +import java.util.*; + +import org.jetbrains.annotations.*; /** - * A {@link Query} that can create tables. + * A step in the construction of the CREATE TABLE statement. *

*

Referencing XYZ*Step types directly from client code

*

@@ -86,15 +63,14 @@ import org.jetbrains.annotations.NotNull; *

  • They're less readable
  • *
  • They might have binary incompatible changes between minor releases
  • * - * - * @author Lukas Eder */ -public interface CreateTableAsStep { +@SuppressWarnings({ "unused" }) +public interface CreateTableAsStep extends CreateTableOnCommitStep { /** - * Add an AS clause to the CREATE TABLE statement. + * Add the AS clause to the CREATE TABLE statement. */ - @NotNull @CheckReturnValue @Support({ CUBRID, DERBY, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE, YUGABYTEDB }) - CreateTableWithDataStep as(Select select); + @NotNull @CheckReturnValue + CreateTableWithDataStep as(Select select); } diff --git a/jOOQ/src/main/java/org/jooq/CreateTableColumnStep.java b/jOOQ/src/main/java/org/jooq/CreateTableColumnStep.java deleted file mode 100644 index 8d720c7cbe..0000000000 --- a/jOOQ/src/main/java/org/jooq/CreateTableColumnStep.java +++ /dev/null @@ -1,147 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Other licenses: - * ----------------------------------------------------------------------------- - * Commercial licenses for this work are available. These replace the above - * ASL 2.0 and offer limited warranties, support, maintenance, and commercial - * database integrations. - * - * For more information, please visit: http://www.jooq.org/licenses - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - */ -package org.jooq; - -import org.jetbrains.annotations.*; - - -import java.util.Collection; - -/** - * A {@link Query} that can create tables. - *

    - *

    Referencing XYZ*Step types directly from client code

    - *

    - * It is usually not recommended to reference any XYZ*Step types - * directly from client code, or assign them to local variables. When writing - * dynamic SQL, creating a statement's components dynamically, and passing them - * to the DSL API statically is usually a better choice. See the manual's - * section about dynamic SQL for details: https://www.jooq.org/doc/latest/manual/sql-building/dynamic-sql. - *

    - * Drawbacks of referencing the XYZ*Step types directly: - *

    - * - * @author Lukas Eder - */ -public interface CreateTableColumnStep extends CreateTableAsStep, CreateTableConstraintStep { - - /** - * Add a column to the column list of the CREATE TABLE - * statement. - *

    - * This is the same as calling {@link #column(Field, DataType)} with - * {@link Field#getDataType()} as the argument data type. - */ - @NotNull @CheckReturnValue - @Support - CreateTableColumnStep column(Field field); - - /** - * Add a column to the column list of the CREATE TABLE statement. - */ - @NotNull @CheckReturnValue - @Support - CreateTableColumnStep column(Field field, DataType type); - - /** - * Add a column to the column list of the CREATE TABLE statement. - */ - @NotNull @CheckReturnValue - @Support - CreateTableColumnStep column(Name field, DataType type); - - /** - * Add a column to the column list of the CREATE TABLE statement. - */ - @NotNull @CheckReturnValue - @Support - CreateTableColumnStep column(String field, DataType type); - - /** - * Add several columns to the column list of the CREATE TABLE - * statement. - *

    - * This is the same as calling {@link #column(Field, DataType)} for each - * column, with {@link Field#getDataType()} as the argument data type. - */ - @NotNull @CheckReturnValue - @Support - CreateTableColumnStep columns(Field... fields); - - /** - * Add several columns to the column list of the CREATE TABLE - * statement. - *

    - * This is the same as calling {@link #column(Field, DataType)} for each - * column. Lacking an explicit data type, this makes sense only for a - * CREATE TABLE AS SELECT... statement. - */ - @NotNull @CheckReturnValue - @Support - CreateTableColumnStep columns(Name... fields); - - /** - * Add several columns to the column list of the CREATE TABLE - * statement. - *

    - * This is the same as calling {@link #column(Field, DataType)} for each - * column. Lacking an explicit data type, this makes sense only for a - * CREATE TABLE AS SELECT... statement. - */ - @NotNull @CheckReturnValue - @Support - CreateTableColumnStep columns(String... fields); - - /** - * Add several columns to the column list of the CREATE TABLE - * statement. - *

    - * This is the same as calling {@link #column(Field, DataType)} for each - * column, with {@link Field#getDataType()} as the argument data type. - */ - @NotNull @CheckReturnValue - @Support - CreateTableColumnStep columns(Collection> fields); -} diff --git a/jOOQ/src/main/java/org/jooq/CreateTableCommentStep.java b/jOOQ/src/main/java/org/jooq/CreateTableCommentStep.java index b6ba7a4694..f3d7043707 100644 --- a/jOOQ/src/main/java/org/jooq/CreateTableCommentStep.java +++ b/jOOQ/src/main/java/org/jooq/CreateTableCommentStep.java @@ -37,13 +37,14 @@ */ package org.jooq; -import org.jetbrains.annotations.*; - - import static org.jooq.SQLDialect.*; +import java.util.*; + +import org.jetbrains.annotations.*; + /** - * A {@link Query} that can create tables. + * A step in the construction of the CREATE TABLE statement. *

    *

    Referencing XYZ*Step types directly from client code

    *

    @@ -62,23 +63,21 @@ import static org.jooq.SQLDialect.*; *

  • They're less readable
  • *
  • They might have binary incompatible changes between minor releases
  • * - * - * @author Lukas Eder */ +@SuppressWarnings({ "unused" }) public interface CreateTableCommentStep extends CreateTableStorageStep { /** - * Add a comment to the table. + * Add the COMMENT clause to the CREATE TABLE statement. */ - @NotNull @CheckReturnValue @Support({ FIREBIRD, MARIADB, MYSQL, POSTGRES, YUGABYTEDB }) - CreateTableStorageStep comment(String comment); + @NotNull @CheckReturnValue + CreateTableStorageStep comment(@Stringly.Comment String comment); /** - * Add a comment to the table. + * Add the COMMENT clause to the CREATE TABLE statement. */ - @NotNull @CheckReturnValue @Support({ FIREBIRD, MARIADB, MYSQL, POSTGRES, YUGABYTEDB }) + @NotNull @CheckReturnValue CreateTableStorageStep comment(Comment comment); - } diff --git a/jOOQ/src/main/java/org/jooq/CreateTableConstraintStep.java b/jOOQ/src/main/java/org/jooq/CreateTableConstraintStep.java deleted file mode 100644 index 50951ac4ae..0000000000 --- a/jOOQ/src/main/java/org/jooq/CreateTableConstraintStep.java +++ /dev/null @@ -1,214 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Other licenses: - * ----------------------------------------------------------------------------- - * Commercial licenses for this work are available. These replace the above - * ASL 2.0 and offer limited warranties, support, maintenance, and commercial - * database integrations. - * - * For more information, please visit: http://www.jooq.org/licenses - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - */ -package org.jooq; - -import org.jooq.impl.DSL; - -import org.jetbrains.annotations.*; - -// ... -// ... -// ... -// ... -import static org.jooq.SQLDialect.CUBRID; -// ... -import static org.jooq.SQLDialect.DERBY; -import static org.jooq.SQLDialect.FIREBIRD; -import static org.jooq.SQLDialect.H2; -// ... -import static org.jooq.SQLDialect.HSQLDB; -// ... -// ... -import static org.jooq.SQLDialect.MARIADB; -import static org.jooq.SQLDialect.MYSQL; -// ... -import static org.jooq.SQLDialect.POSTGRES; -import static org.jooq.SQLDialect.SQLITE; -// ... -// ... -// ... -// ... -import static org.jooq.SQLDialect.YUGABYTEDB; - -import java.util.Collection; - -/** - * A {@link Query} that can create tables. - *

    - *

    Referencing XYZ*Step types directly from client code

    - *

    - * It is usually not recommended to reference any XYZ*Step types - * directly from client code, or assign them to local variables. When writing - * dynamic SQL, creating a statement's components dynamically, and passing them - * to the DSL API statically is usually a better choice. See the manual's - * section about dynamic SQL for details: https://www.jooq.org/doc/latest/manual/sql-building/dynamic-sql. - *

    - * Drawbacks of referencing the XYZ*Step types directly: - *

    - * - * @author Lukas Eder - */ -public interface CreateTableConstraintStep extends CreateTableIndexStep { - - /** - * Add a constraint to the table. - */ - @NotNull @CheckReturnValue - @Support - CreateTableConstraintStep constraint(Constraint constraint); - - /** - * Add constraints to the table. - */ - @NotNull @CheckReturnValue - @Support - CreateTableConstraintStep constraints(Constraint... constraints); - - /** - * Add constraints to the table. - */ - @NotNull @CheckReturnValue - @Support - CreateTableConstraintStep constraints(Collection constraints); - - /** - * Convenience method to add an unnamed (system named) - * PRIMARY KEY constraint to the table. - *

    - * This does the same as adding {@link DSL#primaryKey(String...)} via - * {@link #constraint(Constraint)} explicitly. - */ - @NotNull @CheckReturnValue - @Support - CreateTableConstraintStep primaryKey(String... fields); - - /** - * Convenience method to add an unnamed (system named) - * PRIMARY KEY constraint to the table. - *

    - * This does the same as adding {@link DSL#primaryKey(Name...)} via - * {@link #constraint(Constraint)} explicitly. - */ - @NotNull @CheckReturnValue - @Support - CreateTableConstraintStep primaryKey(Name... fields); - - /** - * Convenience method to add an unnamed (system named) - * PRIMARY KEY constraint to the table. - *

    - * This does the same as adding {@link DSL#primaryKey(Field...)} via - * {@link #constraint(Constraint)} explicitly. - */ - @NotNull @CheckReturnValue - @Support - CreateTableConstraintStep primaryKey(Field... fields); - - /** - * Convenience method to add an unnamed (system named) - * PRIMARY KEY constraint to the table. - *

    - * This does the same as adding {@link DSL#primaryKey(Field...)} via - * {@link #constraint(Constraint)} explicitly. - */ - @NotNull @CheckReturnValue - @Support - CreateTableConstraintStep primaryKey(Collection> fields); - - /** - * Convenience method to add an unnamed (system named) UNIQUE - * constraint to the table. - *

    - * This does the same as adding {@link DSL#unique(String...)} via - * {@link #constraint(Constraint)} explicitly. - */ - @NotNull @CheckReturnValue - @Support - CreateTableConstraintStep unique(String... fields); - - /** - * Convenience method to add an unnamed (system named) UNIQUE - * constraint to the table. - *

    - * This does the same as adding {@link DSL#unique(Name...)} via - * {@link #constraint(Constraint)} explicitly. - */ - @NotNull @CheckReturnValue - @Support - CreateTableConstraintStep unique(Name... fields); - - /** - * Convenience method to add an unnamed (system named) UNIQUE - * constraint to the table. - *

    - * This does the same as adding {@link DSL#unique(Field...)} via - * {@link #constraint(Constraint)} explicitly. - */ - @NotNull @CheckReturnValue - @Support - CreateTableConstraintStep unique(Field... fields); - - /** - * Convenience method to add an unnamed (system named) UNIQUE - * constraint to the table. - *

    - * This does the same as adding {@link DSL#unique(Field...)} via - * {@link #constraint(Constraint)} explicitly. - */ - @NotNull @CheckReturnValue - @Support - CreateTableConstraintStep unique(Collection> fields); - - /** - * Convenience method to add an unnamed (system named) CHECK - * constraint to the table. - *

    - * This does the same as adding {@link DSL#check(Condition)} via - * {@link #constraint(Constraint)} explicitly. - */ - @NotNull @CheckReturnValue - @Support({ CUBRID, DERBY, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE, YUGABYTEDB }) - CreateTableConstraintStep check(Condition condition); -} diff --git a/jOOQ/src/main/java/org/jooq/CreateTableElementListStep.java b/jOOQ/src/main/java/org/jooq/CreateTableElementListStep.java new file mode 100644 index 0000000000..42ea316ba2 --- /dev/null +++ b/jOOQ/src/main/java/org/jooq/CreateTableElementListStep.java @@ -0,0 +1,244 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Other licenses: + * ----------------------------------------------------------------------------- + * Commercial licenses for this work are available. These replace the above + * ASL 2.0 and offer limited warranties, support, maintenance, and commercial + * database integrations. + * + * For more information, please visit: http://www.jooq.org/licenses + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + */ +package org.jooq; + +import static org.jooq.SQLDialect.*; + +import java.util.*; + +import org.jetbrains.annotations.*; + +/** + * A step in the construction of the CREATE TABLE statement. + *

    + *

    Referencing XYZ*Step types directly from client code

    + *

    + * It is usually not recommended to reference any XYZ*Step types + * directly from client code, or assign them to local variables. When writing + * dynamic SQL, creating a statement's components dynamically, and passing them + * to the DSL API statically is usually a better choice. See the manual's + * section about dynamic SQL for details: https://www.jooq.org/doc/latest/manual/sql-building/dynamic-sql. + *

    + * Drawbacks of referencing the XYZ*Step types directly: + *

    + */ +@SuppressWarnings({ "unused" }) +public interface CreateTableElementListStep extends CreateTableAsStep { + + /** + * Add the TABLE ELEMENTS clause to the CREATE TABLE statement. + */ + @Support + @NotNull @CheckReturnValue + CreateTableElementListStep tableElements(TableElement... tableElements); + + /** + * Add the TABLE ELEMENTS clause to the CREATE TABLE statement. + */ + @Support + @NotNull @CheckReturnValue + CreateTableElementListStep tableElements(Collection tableElements); + + /** + * Add the COLUMNS clause to the CREATE TABLE statement. + */ + @Support + @NotNull @CheckReturnValue + CreateTableElementListStep columns(String... columns); + + /** + * Add the COLUMNS clause to the CREATE TABLE statement. + */ + @Support + @NotNull @CheckReturnValue + CreateTableElementListStep columns(Name... columns); + + /** + * Add the COLUMNS clause to the CREATE TABLE statement. + */ + @Support + @NotNull @CheckReturnValue + CreateTableElementListStep columns(Field... columns); + + /** + * Add the COLUMNS clause to the CREATE TABLE statement. + */ + @Support + @NotNull @CheckReturnValue + CreateTableElementListStep columns(Collection> columns); + + /** + * Add the COLUMN clause to the CREATE TABLE statement. + */ + @Support + @NotNull @CheckReturnValue + CreateTableElementListStep column(Field column); + + /** + * Add the COLUMN clause to the CREATE TABLE statement. + */ + @Support + @NotNull @CheckReturnValue + CreateTableElementListStep column(@Stringly.Name String field, DataType type); + + /** + * Add the COLUMN clause to the CREATE TABLE statement. + */ + @Support + @NotNull @CheckReturnValue + CreateTableElementListStep column(Name field, DataType type); + + /** + * Add the COLUMN clause to the CREATE TABLE statement. + */ + @Support + @NotNull @CheckReturnValue + CreateTableElementListStep column(Field field, DataType type); + + /** + * Add the CONSTRAINTS clause to the CREATE TABLE statement. + */ + @Support + @NotNull @CheckReturnValue + CreateTableElementListStep constraints(Constraint... constraints); + + /** + * Add the CONSTRAINTS clause to the CREATE TABLE statement. + */ + @Support + @NotNull @CheckReturnValue + CreateTableElementListStep constraints(Collection constraints); + + /** + * Add the CONSTRAINT clause to the CREATE TABLE statement. + */ + @Support + @NotNull @CheckReturnValue + CreateTableElementListStep constraint(Constraint constraint); + + /** + * Add the PRIMARY KEY clause to the CREATE TABLE statement. + */ + @Support + @NotNull @CheckReturnValue + CreateTableElementListStep primaryKey(String... fields); + + /** + * Add the PRIMARY KEY clause to the CREATE TABLE statement. + */ + @Support + @NotNull @CheckReturnValue + CreateTableElementListStep primaryKey(Name... fields); + + /** + * Add the PRIMARY KEY clause to the CREATE TABLE statement. + */ + @Support + @NotNull @CheckReturnValue + CreateTableElementListStep primaryKey(Field... fields); + + /** + * Add the PRIMARY KEY clause to the CREATE TABLE statement. + */ + @Support + @NotNull @CheckReturnValue + CreateTableElementListStep primaryKey(Collection> fields); + + /** + * Add the UNIQUE clause to the CREATE TABLE statement. + */ + @Support + @NotNull @CheckReturnValue + CreateTableElementListStep unique(String... fields); + + /** + * Add the UNIQUE clause to the CREATE TABLE statement. + */ + @Support + @NotNull @CheckReturnValue + CreateTableElementListStep unique(Name... fields); + + /** + * Add the UNIQUE clause to the CREATE TABLE statement. + */ + @Support + @NotNull @CheckReturnValue + CreateTableElementListStep unique(Field... fields); + + /** + * Add the UNIQUE clause to the CREATE TABLE statement. + */ + @Support + @NotNull @CheckReturnValue + CreateTableElementListStep unique(Collection> fields); + + /** + * Add the CHECK clause to the CREATE TABLE statement. + */ + @Support({ CUBRID, DERBY, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE, YUGABYTEDB }) + @NotNull @CheckReturnValue + CreateTableElementListStep check(Condition condition); + + /** + * Add the INDEXES clause to the CREATE TABLE statement. + */ + @Support({ FIREBIRD, MARIADB, MYSQL, POSTGRES, YUGABYTEDB }) + @NotNull @CheckReturnValue + CreateTableElementListStep indexes(Index... indexes); + + /** + * Add the INDEXES clause to the CREATE TABLE statement. + */ + @Support({ FIREBIRD, MARIADB, MYSQL, POSTGRES, YUGABYTEDB }) + @NotNull @CheckReturnValue + CreateTableElementListStep indexes(Collection indexes); + + /** + * Add the INDEX clause to the CREATE TABLE statement. + */ + @Support({ FIREBIRD, MARIADB, MYSQL, POSTGRES, YUGABYTEDB }) + @NotNull @CheckReturnValue + CreateTableElementListStep index(Index index); +} diff --git a/jOOQ/src/main/java/org/jooq/CreateTableFinalStep.java b/jOOQ/src/main/java/org/jooq/CreateTableFinalStep.java index e16b1586d9..a5c3d05da5 100644 --- a/jOOQ/src/main/java/org/jooq/CreateTableFinalStep.java +++ b/jOOQ/src/main/java/org/jooq/CreateTableFinalStep.java @@ -37,9 +37,16 @@ */ package org.jooq; +import static org.jooq.SQLDialect.*; + +import java.util.*; + +import org.jetbrains.annotations.*; /** - * A {@link Query} that can create tables. + * A step in the construction of the CREATE TABLE statement. + *

    + * @deprecated - [#11329] - 3.15.0 - This type will be removed in the future. Do not reference it directly *

    *

    Referencing XYZ*Step types directly from client code

    *

    @@ -58,11 +65,8 @@ package org.jooq; *

  • They're less readable
  • *
  • They might have binary incompatible changes between minor releases
  • * - * - * @deprecated - [#11329] - 3.15.0 - This type will be removed in the future. Do not reference it directly - * @author Lukas Eder */ +@SuppressWarnings({ "unused" }) @Deprecated(forRemoval = true, since = "3.15") public interface CreateTableFinalStep extends DDLQuery { - } diff --git a/jOOQ/src/main/java/org/jooq/CreateTableIndexStep.java b/jOOQ/src/main/java/org/jooq/CreateTableIndexStep.java deleted file mode 100644 index e4bdf759c4..0000000000 --- a/jOOQ/src/main/java/org/jooq/CreateTableIndexStep.java +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Other licenses: - * ----------------------------------------------------------------------------- - * Commercial licenses for this work are available. These replace the above - * ASL 2.0 and offer limited warranties, support, maintenance, and commercial - * database integrations. - * - * For more information, please visit: http://www.jooq.org/licenses - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - */ -package org.jooq; - -import org.jetbrains.annotations.*; - - -// ... -// ... -// ... -// ... -import static org.jooq.SQLDialect.FIREBIRD; -import static org.jooq.SQLDialect.MARIADB; -// ... -import static org.jooq.SQLDialect.MYSQL; -// ... -import static org.jooq.SQLDialect.POSTGRES; -// ... -import static org.jooq.SQLDialect.YUGABYTEDB; - -import java.util.Collection; - -/** - * A {@link Query} that can create tables. - *

    - *

    Referencing XYZ*Step types directly from client code

    - *

    - * It is usually not recommended to reference any XYZ*Step types - * directly from client code, or assign them to local variables. When writing - * dynamic SQL, creating a statement's components dynamically, and passing them - * to the DSL API statically is usually a better choice. See the manual's - * section about dynamic SQL for details: https://www.jooq.org/doc/latest/manual/sql-building/dynamic-sql. - *

    - * Drawbacks of referencing the XYZ*Step types directly: - *

    - * - * @author Lukas Eder - */ -public interface CreateTableIndexStep extends CreateTableOnCommitStep { - - /** - * Add an index to the table. - */ - @NotNull @CheckReturnValue - @Support({ FIREBIRD, MARIADB, MYSQL, POSTGRES, YUGABYTEDB }) - CreateTableIndexStep index(Index index); - - /** - * Add indexes to the table. - */ - @NotNull @CheckReturnValue - @Support({ FIREBIRD, MARIADB, MYSQL, POSTGRES, YUGABYTEDB }) - CreateTableIndexStep indexes(Index... indexes); - - /** - * Add indexes to the table. - */ - @NotNull @CheckReturnValue - @Support({ FIREBIRD, MARIADB, MYSQL, POSTGRES, YUGABYTEDB }) - CreateTableIndexStep indexes(Collection indexes); -} diff --git a/jOOQ/src/main/java/org/jooq/CreateTableOnCommitStep.java b/jOOQ/src/main/java/org/jooq/CreateTableOnCommitStep.java index b45c16b434..21f41ea64d 100644 --- a/jOOQ/src/main/java/org/jooq/CreateTableOnCommitStep.java +++ b/jOOQ/src/main/java/org/jooq/CreateTableOnCommitStep.java @@ -37,18 +37,14 @@ */ package org.jooq; +import static org.jooq.SQLDialect.*; + +import java.util.*; + import org.jetbrains.annotations.*; - -// ... -// ... -import static org.jooq.SQLDialect.POSTGRES; -import static org.jooq.SQLDialect.YUGABYTEDB; - -import org.jooq.impl.DSL; - /** - * A {@link Query} that can create tables. + * A step in the construction of the CREATE TABLE statement. *

    *

    Referencing XYZ*Step types directly from client code

    *

    @@ -67,44 +63,28 @@ import org.jooq.impl.DSL; *

  • They're less readable
  • *
  • They might have binary incompatible changes between minor releases
  • * - * - * @author Lukas Eder */ +@SuppressWarnings({ "unused" }) public interface CreateTableOnCommitStep extends CreateTableCommentStep { /** - * Add an ON COMMIT DELETE ROWS clause. - *

    - * This clause will only be rendered when used with a - * GLOBAL TEMPORARY TABLE - * - * @see DSL#createGlobalTemporaryTable(Table) + * Add the ON COMMIT DELETE ROWS clause to the CREATE TABLE statement. */ - @NotNull @CheckReturnValue @Support({ POSTGRES, YUGABYTEDB }) + @NotNull @CheckReturnValue CreateTableCommentStep onCommitDeleteRows(); /** - * Add an ON COMMIT PRESERVE ROWS clause. - *

    - * This clause will only be rendered when used with a - * GLOBAL TEMPORARY TABLE - * - * @see DSL#createGlobalTemporaryTable(Table) + * Add the ON COMMIT PRESERVE ROWS clause to the CREATE TABLE statement. */ - @NotNull @CheckReturnValue @Support({ POSTGRES, YUGABYTEDB }) + @NotNull @CheckReturnValue CreateTableCommentStep onCommitPreserveRows(); /** - * Add an ON COMMIT DROP clause. - *

    - * This clause will only be rendered when used with a - * GLOBAL TEMPORARY TABLE - * - * @see DSL#createGlobalTemporaryTable(Table) + * Add the ON COMMIT DROP clause to the CREATE TABLE statement. */ - @NotNull @CheckReturnValue @Support({ POSTGRES, YUGABYTEDB }) + @NotNull @CheckReturnValue CreateTableCommentStep onCommitDrop(); } diff --git a/jOOQ/src/main/java/org/jooq/CreateTableStorageStep.java b/jOOQ/src/main/java/org/jooq/CreateTableStorageStep.java index 537d05b684..eae8547805 100644 --- a/jOOQ/src/main/java/org/jooq/CreateTableStorageStep.java +++ b/jOOQ/src/main/java/org/jooq/CreateTableStorageStep.java @@ -37,13 +37,14 @@ */ package org.jooq; +import static org.jooq.SQLDialect.*; + +import java.util.*; + import org.jetbrains.annotations.*; - -import org.jooq.impl.DSL; - /** - * A {@link Query} that can create tables. + * A step in the construction of the CREATE TABLE statement. *

    *

    Referencing XYZ*Step types directly from client code

    *

    @@ -62,156 +63,47 @@ import org.jooq.impl.DSL; *

  • They're less readable
  • *
  • They might have binary incompatible changes between minor releases
  • * - * - * @author Lukas Eder */ +@SuppressWarnings({ "unused" }) public interface CreateTableStorageStep extends CreateTableFinalStep { /** - * Add vendor-specific storage clauses to the CREATE TABLE statement. - *

    - * Storage clauses will always be appended to the end of everything - * else that jOOQ renders, including possibly other storage clauses, such as - * {@link CreateTableOnCommitStep#onCommitDeleteRows()} or similar clauses. - * If custom storage clauses should be mixed with jOOQ-provided storage - * clauses, it is recommended not to use the jOOQ API and use the custom - * clause API for all storage clauses instead. - *

    - * Storage clauses will be separated from previous elements by a separator - * (whitespace or newline) to ensure syntactic integrity. - *

    - * Example usage: - *

    - *

    -     * DSL.using(configuration)
    -     *    .createTable("t")
    -     *    .column(field("i", SQLDataType.INTEGER))
    -     *    .storage("TABLESPACE my_tablespace")
    -     *    .execute();
    -     * 
    - *

    - * NOTE: When inserting plain SQL into jOOQ objects, you must - * guarantee syntax integrity. You may also create the possibility of - * malicious SQL injection. Be sure to properly use bind variables and/or - * escape literals when concatenated into SQL clauses! One way to escape - * literals is to use {@link DSL#name(String...)} and similar methods + * Add the STORAGE clause to the CREATE TABLE statement. * - * @param sql The SQL + * @see SQL */ - @NotNull @CheckReturnValue @Support @PlainSQL - CreateTableFinalStep storage(SQL sql); + @NotNull @CheckReturnValue + CreateTableFinalStep storage(SQL storage); /** - * Add vendor-specific storage clauses to the CREATE TABLE statement. - *

    - * Storage clauses will always be appended to the end of everything - * else that jOOQ renders, including possibly other storage clauses, such as - * {@link CreateTableOnCommitStep#onCommitDeleteRows()} or similar clauses. - * If custom storage clauses should be mixed with jOOQ-provided storage - * clauses, it is recommended not to use the jOOQ API and use the custom - * clause API for all storage clauses instead. - *

    - * Storage clauses will be separated from previous elements by a separator - * (whitespace or newline) to ensure syntactic integrity. - *

    - * Example usage: - *

    - *

    -     * DSL.using(configuration)
    -     *    .createTable("t")
    -     *    .column(field("i", SQLDataType.INTEGER))
    -     *    .storage("TABLESPACE my_tablespace")
    -     *    .execute();
    -     * 
    - *

    - * NOTE: When inserting plain SQL into jOOQ objects, you must - * guarantee syntax integrity. You may also create the possibility of - * malicious SQL injection. Be sure to properly use bind variables and/or - * escape literals when concatenated into SQL clauses! One way to escape - * literals is to use {@link DSL#name(String...)} and similar methods + * Add the STORAGE clause to the CREATE TABLE statement. * - * @param sql The SQL + * @see SQL */ - @NotNull @CheckReturnValue @Support @PlainSQL - CreateTableFinalStep storage(String sql); + @NotNull @CheckReturnValue + CreateTableFinalStep storage(@Stringly.SQL String storage, QueryPart... parts); /** - * Add vendor-specific storage clauses to the CREATE TABLE statement. - *

    - * Storage clauses will always be appended to the end of everything - * else that jOOQ renders, including possibly other storage clauses, such as - * {@link CreateTableOnCommitStep#onCommitDeleteRows()} or similar clauses. - * If custom storage clauses should be mixed with jOOQ-provided storage - * clauses, it is recommended not to use the jOOQ API and use the custom - * clause API for all storage clauses instead. - *

    - * Storage clauses will be separated from previous elements by a separator - * (whitespace or newline) to ensure syntactic integrity. - *

    - * Example usage: - *

    - *

    -     * DSL.using(configuration)
    -     *    .createTable("t")
    -     *    .column(field("i", SQLDataType.INTEGER))
    -     *    .storage("TABLESPACE my_tablespace")
    -     *    .execute();
    -     * 
    - *

    - * NOTE: When inserting plain SQL into jOOQ objects, you must - * guarantee syntax integrity. You may also create the possibility of - * malicious SQL injection. Be sure to properly use bind variables and/or - * escape literals when concatenated into SQL clauses! One way to escape - * literals is to use {@link DSL#name(String...)} and similar methods + * Add the STORAGE clause to the CREATE TABLE statement. * - * @param sql The SQL - * @param bindings The bindings + * @see SQL */ - @NotNull @CheckReturnValue @Support @PlainSQL - CreateTableFinalStep storage(String sql, Object... bindings); + @NotNull @CheckReturnValue + CreateTableFinalStep storage(@Stringly.SQL String storage, Object... bindings); /** - * Add vendor-specific storage clauses to the CREATE TABLE - * statement. - *

    - * Storage clauses will always be appended to the end of everything - * else that jOOQ renders, including possibly other storage clauses, such as - * {@link CreateTableOnCommitStep#onCommitDeleteRows()} or similar clauses. - * If custom storage clauses should be mixed with jOOQ-provided storage - * clauses, it is recommended not to use the jOOQ API and use the custom - * clause API for all storage clauses instead. - *

    - * Storage clauses will be separated from previous elements by a separator - * (whitespace or newline) to ensure syntactic integrity. - *

    - * Example usage: - *

    - *

    -     * DSL.using(configuration)
    -     *    .createTable("t")
    -     *    .column(field("i", SQLDataType.INTEGER))
    -     *    .storage("TABLESPACE my_tablespace")
    -     *    .execute();
    -     * 
    - *

    - * NOTE: When inserting plain SQL into jOOQ objects, you must - * guarantee syntax integrity. You may also create the possibility of - * malicious SQL injection. Be sure to properly use bind variables and/or - * escape literals when concatenated into SQL clauses! One way to escape - * literals is to use {@link DSL#name(String...)} and similar methods + * Add the STORAGE clause to the CREATE TABLE statement. * - * @param sql The SQL - * @param parts The {@link QueryPart} objects that are rendered at the - * {numbered placeholder} locations + * @see SQL */ - @NotNull @CheckReturnValue @Support @PlainSQL - CreateTableFinalStep storage(String sql, QueryPart... parts); + @NotNull @CheckReturnValue + CreateTableFinalStep storage(@Stringly.SQL String storage); } diff --git a/jOOQ/src/main/java/org/jooq/CreateTableWithDataStep.java b/jOOQ/src/main/java/org/jooq/CreateTableWithDataStep.java index 4a8c303cec..c746ef7220 100644 --- a/jOOQ/src/main/java/org/jooq/CreateTableWithDataStep.java +++ b/jOOQ/src/main/java/org/jooq/CreateTableWithDataStep.java @@ -37,37 +37,14 @@ */ package org.jooq; -// ... -// ... -// ... -// ... -// ... -import static org.jooq.SQLDialect.CUBRID; -// ... -import static org.jooq.SQLDialect.DERBY; -// ... -import static org.jooq.SQLDialect.H2; -// ... -import static org.jooq.SQLDialect.HSQLDB; -// ... -import static org.jooq.SQLDialect.MARIADB; -// ... -import static org.jooq.SQLDialect.MYSQL; -// ... -import static org.jooq.SQLDialect.POSTGRES; -// ... -// ... -// ... -import static org.jooq.SQLDialect.SQLITE; -// ... -// ... -// ... -import static org.jooq.SQLDialect.YUGABYTEDB; +import static org.jooq.SQLDialect.*; -import org.jetbrains.annotations.NotNull; +import java.util.*; + +import org.jetbrains.annotations.*; /** - * A {@link Query} that can create tables. + * A step in the construction of the CREATE TABLE statement. *

    *

    Referencing XYZ*Step types directly from client code

    *

    @@ -86,22 +63,21 @@ import org.jetbrains.annotations.NotNull; *

  • They're less readable
  • *
  • They might have binary incompatible changes between minor releases
  • * - * - * @author Lukas Eder */ +@SuppressWarnings({ "unused" }) public interface CreateTableWithDataStep extends CreateTableOnCommitStep { /** - * Add a WITH DATA clause. + * Add the WITH DATA clause to the CREATE TABLE statement. */ - @NotNull @CheckReturnValue @Support({ CUBRID, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE, YUGABYTEDB }) - CreateTableCommentStep withData(); + @NotNull @CheckReturnValue + CreateTableOnCommitStep withData(); /** - * Add a WITH DATA clause. + * Add the WITH NO DATA clause to the CREATE TABLE statement. */ - @NotNull @CheckReturnValue @Support({ CUBRID, DERBY, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE, YUGABYTEDB }) - CreateTableCommentStep withNoData(); + @NotNull @CheckReturnValue + CreateTableOnCommitStep withNoData(); } diff --git a/jOOQ/src/main/java/org/jooq/DSLContext.java b/jOOQ/src/main/java/org/jooq/DSLContext.java index f6e516c8e6..a21289373e 100644 --- a/jOOQ/src/main/java/org/jooq/DSLContext.java +++ b/jOOQ/src/main/java/org/jooq/DSLContext.java @@ -9992,6 +9992,172 @@ public interface DSLContext extends Scope { + /** + * The CREATE TABLE statement. + * + * @see DSL#createTable(String) + */ + @NotNull @CheckReturnValue + @Support + CreateTableElementListStep createTable(@Stringly.Name String table); + + /** + * The CREATE TABLE statement. + * + * @see DSL#createTable(Name) + */ + @NotNull @CheckReturnValue + @Support + CreateTableElementListStep createTable(Name table); + + /** + * The CREATE TABLE statement. + * + * @see DSL#createTable(Table) + */ + @NotNull @CheckReturnValue + @Support + CreateTableElementListStep createTable(Table table); + + /** + * The CREATE TABLE IF NOT EXISTS statement. + * + * @see DSL#createTableIfNotExists(String) + */ + @NotNull @CheckReturnValue + @Support({ FIREBIRD, H2, HSQLDB, IGNITE, MARIADB, MYSQL, POSTGRES, SQLITE, YUGABYTEDB }) + CreateTableElementListStep createTableIfNotExists(@Stringly.Name String table); + + /** + * The CREATE TABLE IF NOT EXISTS statement. + * + * @see DSL#createTableIfNotExists(Name) + */ + @NotNull @CheckReturnValue + @Support({ FIREBIRD, H2, HSQLDB, IGNITE, MARIADB, MYSQL, POSTGRES, SQLITE, YUGABYTEDB }) + CreateTableElementListStep createTableIfNotExists(Name table); + + /** + * The CREATE TABLE IF NOT EXISTS statement. + * + * @see DSL#createTableIfNotExists(Table) + */ + @NotNull @CheckReturnValue + @Support({ FIREBIRD, H2, HSQLDB, IGNITE, MARIADB, MYSQL, POSTGRES, SQLITE, YUGABYTEDB }) + CreateTableElementListStep createTableIfNotExists(Table table); + + /** + * The CREATE TEMPORARY TABLE statement. + * + * @see DSL#createTemporaryTable(String) + */ + @NotNull @CheckReturnValue + @Support({ FIREBIRD, MARIADB, MYSQL, POSTGRES, YUGABYTEDB }) + CreateTableElementListStep createTemporaryTable(@Stringly.Name String table); + + /** + * The CREATE TEMPORARY TABLE statement. + * + * @see DSL#createTemporaryTable(Name) + */ + @NotNull @CheckReturnValue + @Support({ FIREBIRD, MARIADB, MYSQL, POSTGRES, YUGABYTEDB }) + CreateTableElementListStep createTemporaryTable(Name table); + + /** + * The CREATE TEMPORARY TABLE statement. + * + * @see DSL#createTemporaryTable(Table) + */ + @NotNull @CheckReturnValue + @Support({ FIREBIRD, MARIADB, MYSQL, POSTGRES, YUGABYTEDB }) + CreateTableElementListStep createTemporaryTable(Table table); + + /** + * The CREATE TEMPORARY TABLE IF NOT EXISTS statement. + * + * @see DSL#createTemporaryTableIfNotExists(String) + */ + @NotNull @CheckReturnValue + @Support({ FIREBIRD, MARIADB, MYSQL, POSTGRES, YUGABYTEDB }) + CreateTableElementListStep createTemporaryTableIfNotExists(@Stringly.Name String table); + + /** + * The CREATE TEMPORARY TABLE IF NOT EXISTS statement. + * + * @see DSL#createTemporaryTableIfNotExists(Name) + */ + @NotNull @CheckReturnValue + @Support({ FIREBIRD, MARIADB, MYSQL, POSTGRES, YUGABYTEDB }) + CreateTableElementListStep createTemporaryTableIfNotExists(Name table); + + /** + * The CREATE TEMPORARY TABLE IF NOT EXISTS statement. + * + * @see DSL#createTemporaryTableIfNotExists(Table) + */ + @NotNull @CheckReturnValue + @Support({ FIREBIRD, MARIADB, MYSQL, POSTGRES, YUGABYTEDB }) + CreateTableElementListStep createTemporaryTableIfNotExists(Table table); + + /** + * The CREATE GLOBAL TEMPORARY TABLE statement. + * + * @see DSL#createGlobalTemporaryTable(String) + */ + @NotNull @CheckReturnValue + @Support({ FIREBIRD, MARIADB, MYSQL, POSTGRES, YUGABYTEDB }) + CreateTableElementListStep createGlobalTemporaryTable(@Stringly.Name String table); + + /** + * The CREATE GLOBAL TEMPORARY TABLE statement. + * + * @see DSL#createGlobalTemporaryTable(Name) + */ + @NotNull @CheckReturnValue + @Support({ FIREBIRD, MARIADB, MYSQL, POSTGRES, YUGABYTEDB }) + CreateTableElementListStep createGlobalTemporaryTable(Name table); + + /** + * The CREATE GLOBAL TEMPORARY TABLE statement. + * + * @see DSL#createGlobalTemporaryTable(Table) + */ + @NotNull @CheckReturnValue + @Support({ FIREBIRD, MARIADB, MYSQL, POSTGRES, YUGABYTEDB }) + CreateTableElementListStep createGlobalTemporaryTable(Table table); + + /** + * The CREATE GLOBAL TEMPORARY TABLE IF NOT EXISTS statement. + * + * @see DSL#createGlobalTemporaryTableIfNotExists(String) + */ + @NotNull @CheckReturnValue + @Support({ FIREBIRD, H2, HSQLDB, IGNITE, MARIADB, MYSQL, POSTGRES, SQLITE, YUGABYTEDB }) + CreateTableElementListStep createGlobalTemporaryTableIfNotExists(@Stringly.Name String table); + + /** + * The CREATE GLOBAL TEMPORARY TABLE IF NOT EXISTS statement. + * + * @see DSL#createGlobalTemporaryTableIfNotExists(Name) + */ + @NotNull @CheckReturnValue + @Support({ FIREBIRD, H2, HSQLDB, IGNITE, MARIADB, MYSQL, POSTGRES, SQLITE, YUGABYTEDB }) + CreateTableElementListStep createGlobalTemporaryTableIfNotExists(Name table); + + /** + * The CREATE GLOBAL TEMPORARY TABLE IF NOT EXISTS statement. + * + * @see DSL#createGlobalTemporaryTableIfNotExists(Table) + */ + @NotNull @CheckReturnValue + @Support({ FIREBIRD, H2, HSQLDB, IGNITE, MARIADB, MYSQL, POSTGRES, SQLITE, YUGABYTEDB }) + CreateTableElementListStep createGlobalTemporaryTableIfNotExists(Table table); + + + + + @@ -10960,141 +11126,6 @@ public interface DSLContext extends Scope { - - /** - * Create a new DSL CREATE TABLE statement. - * - * @see DSL#createTable(String) - */ - @NotNull @CheckReturnValue - @Support - CreateTableColumnStep createTable(String table); - - /** - * Create a new DSL CREATE TABLE statement. - * - * @see DSL#createTable(Name) - */ - @NotNull @CheckReturnValue - @Support - CreateTableColumnStep createTable(Name table); - - /** - * Create a new DSL CREATE TABLE statement. - * - * @see DSL#createTable(Table) - */ - @NotNull @CheckReturnValue - @Support - CreateTableColumnStep createTable(Table table); - - /** - * Create a new DSL CREATE TABLE statement. - * - * @see DSL#createTableIfNotExists(String) - */ - @NotNull @CheckReturnValue - @Support({ FIREBIRD, H2, HSQLDB, IGNITE, MARIADB, MYSQL, POSTGRES, SQLITE, YUGABYTEDB }) - CreateTableColumnStep createTableIfNotExists(String table); - - /** - * Create a new DSL CREATE TABLE statement. - * - * @see DSL#createTableIfNotExists(Name) - */ - @NotNull @CheckReturnValue - @Support({ FIREBIRD, H2, HSQLDB, IGNITE, MARIADB, MYSQL, POSTGRES, SQLITE, YUGABYTEDB }) - CreateTableColumnStep createTableIfNotExists(Name table); - - /** - * Create a new DSL CREATE TABLE statement. - * - * @see DSL#createTableIfNotExists(Table) - */ - @NotNull @CheckReturnValue - @Support({ FIREBIRD, H2, HSQLDB, IGNITE, MARIADB, MYSQL, POSTGRES, SQLITE, YUGABYTEDB }) - CreateTableColumnStep createTableIfNotExists(Table table); - - /** - * Create a new DSL CREATE TEMPORARY TABLE statement. - * - * @see DSL#createTemporaryTable(String) - */ - @NotNull @CheckReturnValue - @Support({ FIREBIRD, MARIADB, MYSQL, POSTGRES, YUGABYTEDB }) - CreateTableColumnStep createTemporaryTable(String table); - - /** - * Create a new DSL CREATE TEMPORARY TABLE statement. - * - * @see DSL#createTemporaryTable(Name) - */ - @NotNull @CheckReturnValue - @Support({ FIREBIRD, MARIADB, MYSQL, POSTGRES, YUGABYTEDB }) - CreateTableColumnStep createTemporaryTable(Name table); - - /** - * Create a new DSL CREATE TEMPORARY TABLE statement. - * - * @see DSL#createTemporaryTable(Table) - */ - @NotNull @CheckReturnValue - @Support({ FIREBIRD, MARIADB, MYSQL, POSTGRES, YUGABYTEDB }) - CreateTableColumnStep createTemporaryTable(Table table); - - /** - * Create a new DSL CREATE TEMPORARY TABLE IF NOT EXISTS statement. - * - * @see DSL#createTemporaryTableIfNotExists(String) - */ - @NotNull @CheckReturnValue - @Support({ FIREBIRD, MARIADB, MYSQL, POSTGRES, YUGABYTEDB }) - CreateTableColumnStep createTemporaryTableIfNotExists(String table); - - /** - * Create a new DSL CREATE TEMPORARY TABLE IF NOT EXISTS statement. - * - * @see DSL#createTemporaryTableIfNotExists(Name) - */ - @NotNull @CheckReturnValue - @Support({ FIREBIRD, MARIADB, MYSQL, POSTGRES, YUGABYTEDB }) - CreateTableColumnStep createTemporaryTableIfNotExists(Name table); - - /** - * Create a new DSL CREATE TEMPORARY TABLE IF NOT EXISTS statement. - * - * @see DSL#createTemporaryTableIfNotExists(Table) - */ - @NotNull @CheckReturnValue - @Support({ FIREBIRD, MARIADB, MYSQL, POSTGRES, YUGABYTEDB }) - CreateTableColumnStep createTemporaryTableIfNotExists(Table table); - - /** - * Create a new DSL CREATE GLOBAL TEMPORARY TABLE statement. - * - * @see DSL#createGlobalTemporaryTable(String) - */ - @NotNull @CheckReturnValue - @Support({ FIREBIRD, MARIADB, MYSQL, POSTGRES, YUGABYTEDB }) - CreateTableColumnStep createGlobalTemporaryTable(String table); - - /** - * Create a new DSL CREATE GLOBAL TEMPORARY TABLE statement. - * - * @see DSL#createGlobalTemporaryTable(Name) - */ - @NotNull @CheckReturnValue - @Support({ FIREBIRD, MARIADB, MYSQL, POSTGRES, YUGABYTEDB }) - CreateTableColumnStep createGlobalTemporaryTable(Name table); - - /** - * Create a new DSL CREATE GLOBAL TEMPORARY TABLE statement. - * - * @see DSL#createGlobalTemporaryTable(Table) - */ - @NotNull @CheckReturnValue - @Support({ FIREBIRD, MARIADB, MYSQL, POSTGRES, YUGABYTEDB }) - CreateTableColumnStep createGlobalTemporaryTable(Table table); /** * Create a new DSL CREATE VIEW statement. diff --git a/jOOQ/src/main/java/org/jooq/Field.java b/jOOQ/src/main/java/org/jooq/Field.java index b6cbabc102..4f3a901122 100644 --- a/jOOQ/src/main/java/org/jooq/Field.java +++ b/jOOQ/src/main/java/org/jooq/Field.java @@ -150,7 +150,8 @@ extends GroupField, OrderField, FieldOrRow, - FieldOrConstraint + FieldOrConstraint, + TableElement { // ------------------------------------------------------------------------ diff --git a/jOOQ/src/main/java/org/jooq/FieldOrConstraint.java b/jOOQ/src/main/java/org/jooq/FieldOrConstraint.java index f4c0233df4..949da78fc9 100644 --- a/jOOQ/src/main/java/org/jooq/FieldOrConstraint.java +++ b/jOOQ/src/main/java/org/jooq/FieldOrConstraint.java @@ -46,10 +46,12 @@ package org.jooq; * Instances of this type cannot be created directly, only of its subtypes. * * @author Lukas Eder + * @deprecated - 3.17.0 - [#13005] - Use {@link TableElement} instead. */ +@Deprecated public /* sealed */ interface FieldOrConstraint extends - Named + TableElement /* permits Field, Constraint */ diff --git a/jOOQ/src/main/java/org/jooq/Index.java b/jOOQ/src/main/java/org/jooq/Index.java index 2a6203c4c8..306bb6470e 100644 --- a/jOOQ/src/main/java/org/jooq/Index.java +++ b/jOOQ/src/main/java/org/jooq/Index.java @@ -53,7 +53,7 @@ import org.jetbrains.annotations.ApiStatus.Experimental; * * @author Lukas Eder */ -public interface Index extends Named { +public /* non-sealed */ interface Index extends TableElement { /** * The table on which this index is defined. diff --git a/jOOQ/src/main/java/org/jooq/Named.java b/jOOQ/src/main/java/org/jooq/Named.java index fb0d9fbb5e..346fb461f7 100644 --- a/jOOQ/src/main/java/org/jooq/Named.java +++ b/jOOQ/src/main/java/org/jooq/Named.java @@ -40,8 +40,8 @@ package org.jooq; import org.jooq.impl.QOM; -import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.ApiStatus.Experimental; +import org.jetbrains.annotations.NotNull; /** diff --git a/jOOQ/src/main/java/org/jooq/Replacers.java b/jOOQ/src/main/java/org/jooq/Replacers.java index edf0f34209..a8c9b79a6c 100644 --- a/jOOQ/src/main/java/org/jooq/Replacers.java +++ b/jOOQ/src/main/java/org/jooq/Replacers.java @@ -74,6 +74,87 @@ package org.jooq; + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/jOOQ/src/main/java/org/jooq/TableElement.java b/jOOQ/src/main/java/org/jooq/TableElement.java new file mode 100644 index 0000000000..df81b8af3a --- /dev/null +++ b/jOOQ/src/main/java/org/jooq/TableElement.java @@ -0,0 +1,60 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Other licenses: + * ----------------------------------------------------------------------------- + * Commercial licenses for this work are available. These replace the above + * ASL 2.0 and offer limited warranties, support, maintenance, and commercial + * database integrations. + * + * For more information, please visit: http://www.jooq.org/licenses + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + */ +package org.jooq; + +/** + * A common base type for {@link Field}, {@link Constraint}, and {@link Index} + * where DSL API accepts all types alike. + *

    + * This is useful for DDL statements. + *

    + * Instances of this type cannot be created directly, only of its subtypes. + * + * @author Lukas Eder + */ +public /* sealed */ interface TableElement +extends + Named +/* permits + FieldOrConstraint, + Field, + Constraint, + Index */ +{ + +} diff --git a/jOOQ/src/main/java/org/jooq/TableOptions.java b/jOOQ/src/main/java/org/jooq/TableOptions.java index 1497739db9..c7aae521f1 100644 --- a/jOOQ/src/main/java/org/jooq/TableOptions.java +++ b/jOOQ/src/main/java/org/jooq/TableOptions.java @@ -40,9 +40,14 @@ package org.jooq; // ... // ... import static org.jooq.SQLDialect.POSTGRES; +import static org.jooq.TableOptions.OnCommit.DELETE_ROWS; +import static org.jooq.TableOptions.OnCommit.DROP; +import static org.jooq.TableOptions.OnCommit.PRESERVE_ROWS; import java.io.Serializable; +import org.jooq.impl.QOM.TableCommitAction; + import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -141,6 +146,22 @@ public final class TableOptions implements Serializable { return new TableOptions(onCommit); } + /** + * Create a new {@link TableOptions} object for a {@link TableType#TEMPORARY}. + */ + @NotNull + public static final TableOptions temporaryTable(TableCommitAction onCommit) { + if (onCommit == null) + return new TableOptions((OnCommit) null); + + switch (onCommit) { + case DELETE_ROWS: return temporaryTable(DELETE_ROWS); + case PRESERVE_ROWS: return temporaryTable(PRESERVE_ROWS); + case DROP: return temporaryTable(DROP); + default: throw new IllegalArgumentException("TableCommitAction not supported: " + onCommit); + } + } + /** * Create a new {@link TableOptions} object for a {@link TableType#VIEW} of * unknown content. diff --git a/jOOQ/src/main/java/org/jooq/impl/AbstractNamed.java b/jOOQ/src/main/java/org/jooq/impl/AbstractNamed.java index b125218a5e..2c9c0638b1 100644 --- a/jOOQ/src/main/java/org/jooq/impl/AbstractNamed.java +++ b/jOOQ/src/main/java/org/jooq/impl/AbstractNamed.java @@ -39,7 +39,6 @@ package org.jooq.impl; import static org.jooq.impl.AbstractName.NO_NAME; -import static org.jooq.impl.Tools.findAny; import java.util.ArrayList; import java.util.List; diff --git a/jOOQ/src/main/java/org/jooq/impl/AlterTableImpl.java b/jOOQ/src/main/java/org/jooq/impl/AlterTableImpl.java index 509017eda5..3b15472212 100644 --- a/jOOQ/src/main/java/org/jooq/impl/AlterTableImpl.java +++ b/jOOQ/src/main/java/org/jooq/impl/AlterTableImpl.java @@ -199,6 +199,7 @@ import org.jooq.Record1; import org.jooq.SQLDialect; import org.jooq.Select; import org.jooq.Table; +import org.jooq.TableElement; // ... import org.jooq.impl.QOM.Cascade; import org.jooq.impl.QOM.UNotYetImplemented; @@ -223,18 +224,18 @@ implements UNotYetImplemented { - private static final Clause[] CLAUSES = { ALTER_TABLE }; - private static final Set NO_SUPPORT_IF_EXISTS = SQLDialect.supportedBy(CUBRID, DERBY, FIREBIRD, MARIADB); - private static final Set NO_SUPPORT_IF_EXISTS_COLUMN = SQLDialect.supportedBy(CUBRID, DERBY, FIREBIRD); - private static final Set NO_SUPPORT_IF_EXISTS_CONSTRAINT = SQLDialect.supportedBy(CUBRID, DERBY, FIREBIRD); - private static final Set NO_SUPPORT_IF_NOT_EXISTS_COLUMN = SQLDialect.supportedBy(CUBRID, DERBY, FIREBIRD); - private static final Set SUPPORT_RENAME_COLUMN = SQLDialect.supportedBy(DERBY); - private static final Set SUPPORT_RENAME_TABLE = SQLDialect.supportedBy(DERBY); - private static final Set NO_SUPPORT_RENAME_QUALIFIED_TABLE = SQLDialect.supportedBy(POSTGRES, YUGABYTEDB); - private static final Set NO_SUPPORT_ALTER_TYPE_AND_NULL = SQLDialect.supportedBy(POSTGRES, YUGABYTEDB); - private static final Set NO_SUPPORT_DROP_CONSTRAINT = SQLDialect.supportedBy(MARIADB, MYSQL); - private static final Set REQUIRE_REPEAT_ADD_ON_MULTI_ALTER = SQLDialect.supportedBy(FIREBIRD, MARIADB, MYSQL, POSTGRES, YUGABYTEDB); - private static final Set REQUIRE_REPEAT_DROP_ON_MULTI_ALTER = SQLDialect.supportedBy(FIREBIRD, MARIADB, MYSQL, POSTGRES, YUGABYTEDB); + private static final Clause[] CLAUSES = { ALTER_TABLE }; + private static final Set NO_SUPPORT_IF_EXISTS = SQLDialect.supportedBy(CUBRID, DERBY, FIREBIRD, MARIADB); + private static final Set NO_SUPPORT_IF_EXISTS_COLUMN = SQLDialect.supportedBy(CUBRID, DERBY, FIREBIRD); + private static final Set NO_SUPPORT_IF_EXISTS_CONSTRAINT = SQLDialect.supportedBy(CUBRID, DERBY, FIREBIRD); + private static final Set NO_SUPPORT_IF_NOT_EXISTS_COLUMN = SQLDialect.supportedBy(CUBRID, DERBY, FIREBIRD); + private static final Set SUPPORT_RENAME_COLUMN = SQLDialect.supportedBy(DERBY); + private static final Set SUPPORT_RENAME_TABLE = SQLDialect.supportedBy(DERBY); + private static final Set NO_SUPPORT_RENAME_QUALIFIED_TABLE = SQLDialect.supportedBy(POSTGRES, YUGABYTEDB); + private static final Set NO_SUPPORT_ALTER_TYPE_AND_NULL = SQLDialect.supportedBy(POSTGRES, YUGABYTEDB); + private static final Set NO_SUPPORT_DROP_CONSTRAINT = SQLDialect.supportedBy(MARIADB, MYSQL); + private static final Set REQUIRE_REPEAT_ADD_ON_MULTI_ALTER = SQLDialect.supportedBy(FIREBIRD, MARIADB, MYSQL, POSTGRES, YUGABYTEDB); + private static final Set REQUIRE_REPEAT_DROP_ON_MULTI_ALTER = SQLDialect.supportedBy(FIREBIRD, MARIADB, MYSQL, POSTGRES, YUGABYTEDB); @@ -248,41 +249,41 @@ implements - private final Table table; - private final boolean ifExists; - private boolean ifExistsColumn; - private boolean ifExistsConstraint; - private boolean ifNotExistsColumn; - private Comment comment; - private Table renameTo; - private Field renameColumn; - private Field renameColumnTo; - private Index renameIndex; - private Index renameIndexTo; - private Constraint renameConstraint; - private Constraint renameConstraintTo; - private QueryPartList add; - private Field addColumn; - private DataType addColumnType; - private Constraint addConstraint; - private boolean addFirst; - private Field addBefore; - private Field addAfter; + private final Table table; + private final boolean ifExists; + private boolean ifExistsColumn; + private boolean ifExistsConstraint; + private boolean ifNotExistsColumn; + private Comment comment; + private Table renameTo; + private Field renameColumn; + private Field renameColumnTo; + private Index renameIndex; + private Index renameIndexTo; + private Constraint renameConstraint; + private Constraint renameConstraintTo; + private QueryPartList add; + private Field addColumn; + private DataType addColumnType; + private Constraint addConstraint; + private boolean addFirst; + private Field addBefore; + private Field addAfter; - private Constraint alterConstraint; - private boolean alterConstraintEnforced; - private Field alterColumn; - private Nullability alterColumnNullability; - private DataType alterColumnType; - private Field alterColumnDefault; - private boolean alterColumnDropDefault; - private QueryPartList> dropColumns; - private Constraint dropConstraint; - private ConstraintType dropConstraintType; - private Cascade dropCascade; + private Constraint alterConstraint; + private boolean alterConstraintEnforced; + private Field alterColumn; + private Nullability alterColumnNullability; + private DataType alterColumnType; + private Field alterColumnDefault; + private boolean alterColumnDropDefault; + private QueryPartList> dropColumns; + private Constraint dropConstraint; + private ConstraintType dropConstraintType; + private Cascade dropCascade; AlterTableImpl(Configuration configuration, Table table) { this(configuration, table, false); @@ -300,7 +301,7 @@ implements final boolean $ifExistsColumn() { return ifExistsColumn; } final boolean $ifExistsConstraint() { return ifExistsConstraint; } final boolean $ifNotExistsColumn() { return ifNotExistsColumn; } - final List $add() { return add; } + final List $add() { return add; } final Field $addColumn() { return addColumn; } final DataType $addColumnType() { return addColumnType; } final Constraint $addConstraint() { return addConstraint; } @@ -457,21 +458,23 @@ implements } @Override - public final AlterTableImpl add(FieldOrConstraint... fields) { + public final AlterTableImpl add(TableElement... fields) { return add(Arrays.asList(fields)); } @Override - public final AlterTableImpl add(Collection fields) { + public final AlterTableImpl add(Collection fields) { // [#9570] Better portability of single item ADD statements if (fields.size() == 1) { - FieldOrConstraint first = fields.iterator().next(); + TableElement first = fields.iterator().next(); if (first instanceof Field) return add((Field) first); else if (first instanceof Constraint) return add((Constraint) first); + else if (first instanceof Index) + throw new UnsupportedOperationException("ALTER TABLE .. ADD INDEX not yet supported, see https://github.com/jOOQ/jOOQ/issues/13006"); } add = new QueryPartList<>(fields); @@ -1295,7 +1298,7 @@ implements ctx.visit(addColumnKeyword(ctx)).sql(' '); } - FieldOrConstraint part = add.get(i); + TableElement part = add.get(i); ctx.qualify(false, c -> c.visit(part)); if (part instanceof Field) { Field f = (Field) part; diff --git a/jOOQ/src/main/java/org/jooq/impl/CreateTableImpl.java b/jOOQ/src/main/java/org/jooq/impl/CreateTableImpl.java index 514aba7bf8..392c0cfd7a 100644 --- a/jOOQ/src/main/java/org/jooq/impl/CreateTableImpl.java +++ b/jOOQ/src/main/java/org/jooq/impl/CreateTableImpl.java @@ -37,125 +37,311 @@ */ package org.jooq.impl; -import static java.lang.Boolean.FALSE; -import static java.lang.Boolean.TRUE; -import static org.jooq.Clause.CREATE_TABLE; -import static org.jooq.Clause.CREATE_TABLE_AS; -import static org.jooq.Clause.CREATE_TABLE_COLUMNS; -import static org.jooq.Clause.CREATE_TABLE_CONSTRAINTS; -import static org.jooq.Clause.CREATE_TABLE_NAME; -// ... -// ... -// ... -// ... -// ... -import static org.jooq.SQLDialect.CUBRID; -// ... -import static org.jooq.SQLDialect.DERBY; -// ... -import static org.jooq.SQLDialect.FIREBIRD; -import static org.jooq.SQLDialect.H2; -// ... -import static org.jooq.SQLDialect.HSQLDB; -import static org.jooq.SQLDialect.IGNITE; -// ... -// ... -import static org.jooq.SQLDialect.MARIADB; -// ... -import static org.jooq.SQLDialect.MYSQL; -// ... -import static org.jooq.SQLDialect.POSTGRES; -// ... -// ... -// ... -import static org.jooq.SQLDialect.SQLITE; -// ... -// ... -// ... -// ... -import static org.jooq.SQLDialect.YUGABYTEDB; -import static org.jooq.impl.DSL.asterisk; -import static org.jooq.impl.DSL.commentOnTable; -import static org.jooq.impl.DSL.createIndex; -import static org.jooq.impl.DSL.field; -import static org.jooq.impl.DSL.inline; -import static org.jooq.impl.DSL.insertInto; -import static org.jooq.impl.DSL.name; -import static org.jooq.impl.DSL.select; -import static org.jooq.impl.DSL.sql; -import static org.jooq.impl.DSL.table; -import static org.jooq.impl.Keywords.K_AS; -import static org.jooq.impl.Keywords.K_COMMENT; -import static org.jooq.impl.Keywords.K_CREATE; -import static org.jooq.impl.Keywords.K_GLOBAL_TEMPORARY; -import static org.jooq.impl.Keywords.K_IF_NOT_EXISTS; -import static org.jooq.impl.Keywords.K_INDEX; -import static org.jooq.impl.Keywords.K_IS; -import static org.jooq.impl.Keywords.K_ON_COMMIT_DELETE_ROWS; -import static org.jooq.impl.Keywords.K_ON_COMMIT_DROP; -import static org.jooq.impl.Keywords.K_ON_COMMIT_PRESERVE_ROWS; -import static org.jooq.impl.Keywords.K_TABLE; -import static org.jooq.impl.Keywords.K_TEMPORARY; -import static org.jooq.impl.Keywords.K_UNIQUE; -import static org.jooq.impl.Keywords.K_WITH_DATA; -import static org.jooq.impl.Keywords.K_WITH_NO_DATA; -import static org.jooq.impl.SQLDataType.INTEGER; -import static org.jooq.impl.Tools.EMPTY_FIELD; -import static org.jooq.impl.Tools.anyMatch; -import static org.jooq.impl.Tools.begin; -import static org.jooq.impl.Tools.enums; -import static org.jooq.impl.Tools.executeImmediate; -import static org.jooq.impl.Tools.findAny; -import static org.jooq.impl.Tools.map; -import static org.jooq.impl.Tools.storedEnumType; -import static org.jooq.impl.Tools.tryCatch; -import static org.jooq.impl.Tools.BooleanDataKey.DATA_SELECT_NO_DATA; -import static org.jooq.impl.Tools.DataKey.DATA_SELECT_INTO_TABLE; +import static org.jooq.impl.DSL.*; +import static org.jooq.impl.Internal.*; +import static org.jooq.impl.Keywords.*; +import static org.jooq.impl.Names.*; +import static org.jooq.impl.SQLDataType.*; +import static org.jooq.impl.Tools.*; +import static org.jooq.impl.Tools.BooleanDataKey.*; +import static org.jooq.impl.Tools.DataExtendedKey.*; +import static org.jooq.impl.Tools.DataKey.*; +import static org.jooq.SQLDialect.*; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.List; -import java.util.Set; -import java.util.function.Consumer; - -import org.jooq.Comment; -import org.jooq.Condition; -import org.jooq.Configuration; -import org.jooq.Constraint; -import org.jooq.Context; -import org.jooq.CreateTableColumnStep; -import org.jooq.CreateTableConstraintStep; -import org.jooq.CreateTableWithDataStep; -import org.jooq.DataType; -import org.jooq.EnumType; -import org.jooq.Field; -import org.jooq.Index; -import org.jooq.Name; -import org.jooq.Nullability; -// ... -import org.jooq.QueryPart; +import org.jooq.*; +import org.jooq.Function1; import org.jooq.Record; -import org.jooq.SQL; -import org.jooq.SQLDialect; -import org.jooq.Select; -import org.jooq.Table; -import org.jooq.TableOptions.OnCommit; -import org.jooq.impl.QOM.UNotYetImplemented; +import org.jooq.conf.*; +import org.jooq.impl.*; +import org.jooq.impl.QOM.*; +import org.jooq.tools.*; + +import java.util.*; +import java.util.function.*; +import java.util.stream.*; /** - * @author Lukas Eder + * The CREATE TABLE statement. */ +@SuppressWarnings({ "hiding", "rawtypes", "unused" }) final class CreateTableImpl extends AbstractDDLQuery implements + QOM.CreateTable, + CreateTableElementListStep, + CreateTableAsStep, CreateTableWithDataStep, - CreateTableColumnStep, - UNotYetImplemented - + CreateTableOnCommitStep, + CreateTableCommentStep, + CreateTableStorageStep, + CreateTableFinalStep { + + final Table table; + final boolean temporary; + final boolean ifNotExists; + QueryPartListView tableElements; + Select select; + WithOrWithoutData withData; + TableCommitAction onCommit; + Comment comment; + SQL storage; + + CreateTableImpl( + Configuration configuration, + Table table, + boolean temporary, + boolean ifNotExists + ) { + this( + configuration, + table, + temporary, + ifNotExists, + null, + null, + null, + null, + null, + null + ); + } + + CreateTableImpl( + Configuration configuration, + Table table, + boolean temporary, + boolean ifNotExists, + Collection tableElements, + Select select, + WithOrWithoutData withData, + TableCommitAction onCommit, + Comment comment, + SQL storage + ) { + super(configuration); + + this.table = table; + this.temporary = temporary; + this.ifNotExists = ifNotExists; + this.tableElements = new QueryPartList<>(tableElements); + this.select = select; + this.withData = withData; + this.onCommit = onCommit; + this.comment = comment; + this.storage = storage; + } + + // ------------------------------------------------------------------------- + // XXX: DSL API + // ------------------------------------------------------------------------- + + @Override + public final CreateTableImpl tableElements(TableElement... tableElements) { + return tableElements(Arrays.asList(tableElements)); + } + + @Override + public final CreateTableImpl tableElements(Collection tableElements) { + if (this.tableElements == null) + this.tableElements = new QueryPartList<>(tableElements); + else + this.tableElements.addAll((Collection) tableElements); + + return this; + } + + @Override + public final CreateTableImpl columns(String... columns) { + return columns(Tools.fieldsByName(columns)); + } + + @Override + public final CreateTableImpl columns(Name... columns) { + return columns(Tools.fieldsByName(columns)); + } + + @Override + public final CreateTableImpl columns(Field... columns) { + return columns(Arrays.asList(columns)); + } + + @Override + public final CreateTableImpl columns(Collection> columns) { + return tableElements(new QueryPartList<>(columns)); + } + + @Override + public final CreateTableImpl column(Field column) { + return tableElements(column); + } + + @Override + public final CreateTableImpl column(String field, DataType type) { + return column(DSL.name(field), type); + } + + @Override + public final CreateTableImpl column(Name field, DataType type) { + return tableElements(DSL.field(field, type)); + } + + @Override + public final CreateTableImpl column(Field field, DataType type) { + return tableElements(DSL.field(field.getQualifiedName(), type)); + } + + @Override + public final CreateTableImpl constraints(Constraint... constraints) { + return constraints(Arrays.asList(constraints)); + } + + @Override + public final CreateTableImpl constraints(Collection constraints) { + return tableElements(new QueryPartList<>(constraints)); + } + + @Override + public final CreateTableImpl constraint(Constraint constraint) { + return tableElements(constraint); + } + + @Override + public final CreateTableImpl primaryKey(String... fields) { + return primaryKey(Tools.fieldsByName(fields)); + } + + @Override + public final CreateTableImpl primaryKey(Name... fields) { + return primaryKey(Tools.fieldsByName(fields)); + } + + @Override + public final CreateTableImpl primaryKey(Field... fields) { + return primaryKey(Arrays.asList(fields)); + } + + @Override + public final CreateTableImpl primaryKey(Collection> fields) { + return tableElements(DSL.primaryKey(new QueryPartList<>(fields))); + } + + @Override + public final CreateTableImpl unique(String... fields) { + return unique(Tools.fieldsByName(fields)); + } + + @Override + public final CreateTableImpl unique(Name... fields) { + return unique(Tools.fieldsByName(fields)); + } + + @Override + public final CreateTableImpl unique(Field... fields) { + return unique(Arrays.asList(fields)); + } + + @Override + public final CreateTableImpl unique(Collection> fields) { + return tableElements(DSL.unique(new QueryPartList<>(fields))); + } + + @Override + public final CreateTableImpl check(Condition condition) { + return tableElements(DSL.check(condition)); + } + + @Override + public final CreateTableImpl indexes(Index... indexes) { + return indexes(Arrays.asList(indexes)); + } + + @Override + public final CreateTableImpl indexes(Collection indexes) { + return tableElements(new QueryPartList<>(indexes)); + } + + @Override + public final CreateTableImpl index(Index index) { + return tableElements(index); + } + + @Override + public final CreateTableImpl as(Select select) { + this.select = select; + return this; + } + + @Override + public final CreateTableImpl withData() { + this.withData = WithOrWithoutData.WITH_DATA; + return this; + } + + @Override + public final CreateTableImpl withNoData() { + this.withData = WithOrWithoutData.WITH_NO_DATA; + return this; + } + + @Override + public final CreateTableImpl onCommitDeleteRows() { + this.onCommit = TableCommitAction.DELETE_ROWS; + return this; + } + + @Override + public final CreateTableImpl onCommitPreserveRows() { + this.onCommit = TableCommitAction.PRESERVE_ROWS; + return this; + } + + @Override + public final CreateTableImpl onCommitDrop() { + this.onCommit = TableCommitAction.DROP; + return this; + } + + @Override + public final CreateTableImpl comment(String comment) { + return comment(DSL.comment(comment)); + } + + @Override + public final CreateTableImpl comment(Comment comment) { + this.comment = comment; + return this; + } + + @Override + public final CreateTableImpl storage(SQL storage) { + this.storage = storage; + return this; + } + + @Override + public final CreateTableImpl storage(String storage, QueryPart... parts) { + return storage(DSL.sql(storage, parts)); + } + + @Override + public final CreateTableImpl storage(String storage, Object... bindings) { + return storage(DSL.sql(storage, bindings)); + } + + @Override + public final CreateTableImpl storage(String storage) { + return storage(DSL.sql(storage)); + } + + // ------------------------------------------------------------------------- + // XXX: QueryPart API + // ------------------------------------------------------------------------- + + + private static final Set NO_SUPPORT_IF_NOT_EXISTS = SQLDialect.supportedBy(DERBY, FIREBIRD); private static final Set NO_SUPPORT_WITH_DATA = SQLDialect.supportedBy(H2, MARIADB, MYSQL, SQLITE); private static final Set NO_SUPPORT_CTAS_COLUMN_NAMES = SQLDialect.supportedBy(H2); @@ -174,243 +360,24 @@ implements - private final Table table; - private Select select; - private Boolean withData; - private final List> columnFields; - private final List> columnTypes; - private final List constraints; - private final List indexes; - private final boolean temporary; - private final boolean ifNotExists; - private OnCommit onCommit; - private Comment comment; - private SQL storage; - - CreateTableImpl(Configuration configuration, Table table, boolean temporary, boolean ifNotExists) { - super(configuration); - - this.table = table; - this.temporary = temporary; - this.ifNotExists = ifNotExists; - this.columnFields = new ArrayList<>(); - this.columnTypes = new ArrayList<>(); - this.constraints = new ArrayList<>(); - this.indexes = new ArrayList<>(); + final UnmodifiableList> $columns() { + return QOM.unmodifiable( + tableElements.stream().filter(e -> e instanceof Field).map(e -> (Field) e).collect(Collectors.toList()) + ); } - final Table $table() { return table; } - final boolean $temporary() { return temporary; } - final OnCommit $onCommit() { return onCommit; } - final Select $select() { return select; } - final List> $columnFields() { return columnFields; } - final List> $columnTypes() { return columnTypes; } - final List $constraints() { return constraints; } - final List $indexes() { return indexes; } - final boolean $ifNotExists() { return ifNotExists; } - final Comment $comment() { return comment; } - - // ------------------------------------------------------------------------ - // XXX: DSL API - // ------------------------------------------------------------------------ - - @Override - public final CreateTableImpl as(Select s) { - this.select = s; - return this; + final UnmodifiableList $constraints() { + return QOM.unmodifiable( + tableElements.stream().filter(e -> e instanceof Constraint).map(e -> (Constraint) e).collect(Collectors.toList()) + ); } - @Override - public final CreateTableImpl withData() { - withData = true; - return this; + final UnmodifiableList $indexes() { + return QOM.unmodifiable( + tableElements.stream().filter(e -> e instanceof Index).map(e -> (Index) e).collect(Collectors.toList()) + ); } - @Override - public final CreateTableImpl withNoData() { - withData = false; - return this; - } - - @SuppressWarnings({ "unchecked", "rawtypes" }) - @Override - public final CreateTableImpl column(Field field) { - return column((Field) field, field.getDataType()); - } - - @Override - public final CreateTableImpl columns(Field... fields) { - return columns(Arrays.asList(fields)); - } - - @Override - public final CreateTableImpl columns(Name... fields) { - return columns(Tools.fieldsByName(fields)); - } - - @Override - public final CreateTableImpl columns(String... fields) { - return columns(Tools.fieldsByName(fields)); - } - - @Override - public final CreateTableImpl columns(Collection> fields) { - for (Field field : fields) - column(field); - - return this; - } - - @Override - public final CreateTableImpl column(Field field, DataType type) { - columnFields.add(field); - columnTypes.add(type); - return this; - } - - @Override - public final CreateTableImpl column(Name field, DataType type) { - columnFields.add(field(field, type)); - columnTypes.add(type); - return this; - } - - @Override - public final CreateTableImpl column(String field, DataType type) { - return column(name(field), type); - } - - @Override - public final CreateTableImpl constraint(Constraint c) { - return constraints(Arrays.asList(c)); - } - - @Override - public final CreateTableImpl constraints(Constraint... c) { - return constraints(Arrays.asList(c)); - } - - @Override - public final CreateTableImpl constraints(Collection c) { - constraints.addAll(c); - return this; - } - - @Override - public final CreateTableConstraintStep primaryKey(String... fields) { - return constraint(DSL.primaryKey(fields)); - } - - @Override - public final CreateTableConstraintStep primaryKey(Name... fields) { - return constraint(DSL.primaryKey(fields)); - } - - @Override - public final CreateTableConstraintStep primaryKey(Field... fields) { - return constraint(DSL.primaryKey(fields)); - } - - @Override - public final CreateTableConstraintStep primaryKey(Collection> fields) { - return constraint(DSL.primaryKey(fields)); - } - - @Override - public final CreateTableConstraintStep unique(String... fields) { - return constraint(DSL.unique(fields)); - } - - @Override - public final CreateTableConstraintStep unique(Name... fields) { - return constraint(DSL.unique(fields)); - } - - @Override - public final CreateTableConstraintStep unique(Field... fields) { - return constraint(DSL.unique(fields)); - } - - @Override - public final CreateTableConstraintStep unique(Collection> fields) { - return constraint(DSL.unique(fields)); - } - - @Override - public final CreateTableConstraintStep check(Condition condition) { - return constraint(DSL.check(condition)); - } - - @Override - public final CreateTableImpl index(Index i) { - return indexes(Arrays.asList(i)); - } - - @Override - public final CreateTableImpl indexes(Index... i) { - return indexes(Arrays.asList(i)); - } - - @Override - public final CreateTableImpl indexes(Collection i) { - indexes.addAll(i); - return this; - } - - @Override - public final CreateTableImpl onCommitDeleteRows() { - onCommit = OnCommit.DELETE_ROWS; - return this; - } - - @Override - public final CreateTableImpl onCommitPreserveRows() { - onCommit = OnCommit.PRESERVE_ROWS; - return this; - } - - @Override - public final CreateTableImpl onCommitDrop() { - onCommit = OnCommit.DROP; - return this; - } - - @Override - public final CreateTableImpl comment(String c) { - return comment(DSL.comment(c)); - } - - @Override - public final CreateTableImpl comment(Comment c) { - comment = c; - return this; - } - - @Override - public final CreateTableImpl storage(SQL sql) { - storage = sql; - return this; - } - - @Override - public final CreateTableImpl storage(String sql) { - return storage(sql(sql)); - } - - @Override - public final CreateTableImpl storage(String sql, Object... bindings) { - return storage(sql(sql, bindings)); - } - - @Override - public final CreateTableImpl storage(String sql, QueryPart... parts) { - return storage(sql(sql, parts)); - } - - // ------------------------------------------------------------------------ - // XXX: QueryPart API - // ------------------------------------------------------------------------ - private final boolean supportsIfNotExists(Context ctx) { return !NO_SUPPORT_IF_NOT_EXISTS.contains(ctx.dialect()); } @@ -435,7 +402,7 @@ implements private final void accept0(Context ctx) { boolean bc = comment != null && EMULATE_COMMENT_IN_BLOCK.contains(ctx.dialect()); - boolean bi = !indexes.isEmpty() && EMULATE_INDEXES_IN_BLOCK.contains(ctx.dialect()); + boolean bi = !$indexes().isEmpty() && EMULATE_INDEXES_IN_BLOCK.contains(ctx.dialect()); if (bc || bi) { begin(ctx, c1 -> { @@ -450,7 +417,7 @@ implements } if (bi) { - for (Index index : indexes) { + for (Index index : $indexes()) { c1.formatSeparator(); executeImmediateIf(REQUIRE_EXECUTE_IMMEDIATE.contains(c1.dialect()), c1, c2 -> { @@ -468,7 +435,7 @@ implements } private final void accept1(Context ctx) { - ctx.start(CREATE_TABLE); + ctx.start(Clause.CREATE_TABLE); if (select != null) { @@ -505,34 +472,37 @@ implements ctx.formatSeparator() .visit(storage); - ctx.end(CREATE_TABLE); + ctx.end(Clause.CREATE_TABLE); } private void toSQLCreateTable(Context ctx) { toSQLCreateTableName(ctx); - if (!columnFields.isEmpty() + UnmodifiableList> columns = $columns(); + if (!columns.isEmpty() && (select == null || !NO_SUPPORT_CTAS_COLUMN_NAMES.contains(ctx.dialect()))) { ctx.sqlIndentStart(" (") - .start(CREATE_TABLE_COLUMNS); + .start(Clause.CREATE_TABLE_COLUMNS); Field identity = null; boolean qualify = ctx.qualify(); ctx.qualify(false); - for (int i = 0; i < columnFields.size(); i++) { - DataType type = columnType(ctx, i); - if (identity == null && type.identity()) - identity = columnFields.get(i); + for (int i = 0; i < columns.size(); i++) { + Field field = columns.get(i); + DataType type = columnType(ctx, field); - ctx.visit(columnFields.get(i)); + if (identity == null && type.identity()) + identity = field; + + ctx.visit(field); if (select == null) { ctx.sql(' '); Tools.toSQLDDLTypeDeclarationForAddition(ctx, type); } - if (i < columnFields.size() - 1) + if (i < columns.size() - 1) ctx.sql(',').formatSeparator(); } @@ -540,22 +510,21 @@ implements toSQLDummyColumns(ctx); ctx.qualify(qualify); - ctx.end(CREATE_TABLE_COLUMNS) - .start(CREATE_TABLE_CONSTRAINTS); + ctx.end(Clause.CREATE_TABLE_COLUMNS) + .start(Clause.CREATE_TABLE_CONSTRAINTS); - if (!constraints.isEmpty()) - for (Constraint constraint : constraints) + for (Constraint constraint : $constraints()) - // [#6841] SQLite has a weird requirement of the PRIMARY KEY keyword being on the column directly, - // when there is an identity. Thus, we must not repeat the primary key specification here. - if (((ConstraintImpl) constraint).supported(ctx) && (ctx.family() != SQLITE || !matchingPrimaryKey(constraint, identity))) - ctx.sql(',') - .formatSeparator() - .visit(constraint); + // [#6841] SQLite has a weird requirement of the PRIMARY KEY keyword being on the column directly, + // when there is an identity. Thus, we must not repeat the primary key specification here. + if (((ConstraintImpl) constraint).supported(ctx) && (ctx.family() != SQLITE || !matchingPrimaryKey(constraint, identity))) + ctx.sql(',') + .formatSeparator() + .visit(constraint); if (EMULATE_SOME_ENUM_TYPES_AS_CHECK.contains(ctx.dialect())) { - for (int i = 0; i < columnFields.size(); i++) { - DataType type = columnTypes.get(i); + for (Field field : $columns()) { + DataType type = field.getDataType(); if (EnumType.class.isAssignableFrom(type.getType())) { @@ -563,7 +532,6 @@ implements DataType enumType = (DataType) type; if (EMULATE_STORED_ENUM_TYPES_AS_CHECK.contains(ctx.dialect()) || !storedEnumType(enumType)) { - Field field = columnFields.get(i); List> literals = map(enums(enumType.getType()), e -> inline(e.getLiteral())); ctx.sql(',') @@ -575,12 +543,12 @@ implements } } - ctx.end(CREATE_TABLE_CONSTRAINTS); + ctx.end(Clause.CREATE_TABLE_CONSTRAINTS); - if (!indexes.isEmpty() && !EMULATE_INDEXES_IN_BLOCK.contains(ctx.dialect())) { + if (!$indexes().isEmpty() && !EMULATE_INDEXES_IN_BLOCK.contains(ctx.dialect())) { ctx.qualify(false); - for (Index index : indexes) { + for (Index index : $indexes()) { ctx.sql(',').formatSeparator(); if (index.getUnique()) @@ -609,9 +577,9 @@ implements if (REQUIRE_NON_PK_COLUMNS.contains(ctx.dialect())) { Field[] primaryKeyColumns = primaryKeyColumns(); - if (primaryKeyColumns != null && primaryKeyColumns.length == columnFields.size()) { + if (primaryKeyColumns != null && primaryKeyColumns.length == $columns().size()) { ctx.sql(',').formatSeparator(); - ctx.visit(field(name("dummy"))); + ctx.visit(DSL.field(name("dummy"))); if (select == null) { ctx.sql(' '); @@ -621,10 +589,12 @@ implements } } - private final DataType columnType(Context ctx, int i) { - DataType type = columnTypes.get(i); + private final DataType columnType(Context ctx, Field field) { + DataType type = field.getDataType(); - if (NO_SUPPORT_NULLABLE_PRIMARY_KEY.contains(ctx.dialect()) && type.nullability() == Nullability.DEFAULT && isPrimaryKey(i)) + if (NO_SUPPORT_NULLABLE_PRIMARY_KEY.contains(ctx.dialect()) + && type.nullability() == Nullability.DEFAULT + && isPrimaryKey(field)) type = type.nullable(false); return type; @@ -632,14 +602,14 @@ implements private final Field[] primaryKeyColumns() { return Tools.findAny( - constraints, + $constraints(), c -> c instanceof ConstraintImpl && ((ConstraintImpl) c).$primaryKey() != null, c -> ((ConstraintImpl) c).$primaryKey() ); } - private final boolean isPrimaryKey(int i) { - return anyMatch(primaryKeyColumns(), columnFields.get(i)::equals); + private final boolean isPrimaryKey(Field field) { + return anyMatch(primaryKeyColumns(), field::equals); } private final boolean matchingPrimaryKey(Constraint constraint, Field identity) { @@ -660,29 +630,29 @@ implements else ctx.formatSeparator(); - if (FALSE.equals(withData) && NO_SUPPORT_WITH_DATA.contains(ctx.dialect())) + if (WithOrWithoutData.WITH_NO_DATA == withData && NO_SUPPORT_WITH_DATA.contains(ctx.dialect())) ctx.data(DATA_SELECT_NO_DATA, true); - ctx.start(CREATE_TABLE_AS); + ctx.start(Clause.CREATE_TABLE_AS); - if (!columnFields.isEmpty() && NO_SUPPORT_CTAS_COLUMN_NAMES.contains(ctx.dialect())) - ctx.visit(select(asterisk()).from(select.asTable(table(name("t")), columnFields.toArray(EMPTY_FIELD)))); + if (!$columns().isEmpty() && NO_SUPPORT_CTAS_COLUMN_NAMES.contains(ctx.dialect())) + ctx.visit(select(asterisk()).from(select.asTable(table(name("t")), $columns().toArray(EMPTY_FIELD)))); else ctx.visit(select); - ctx.end(CREATE_TABLE_AS); + ctx.end(Clause.CREATE_TABLE_AS); - if (FALSE.equals(withData) && NO_SUPPORT_WITH_DATA.contains(ctx.dialect())) + if (WithOrWithoutData.WITH_NO_DATA == withData && NO_SUPPORT_WITH_DATA.contains(ctx.dialect())) ctx.data().remove(DATA_SELECT_NO_DATA); if (WRAP_SELECT_IN_PARENS.contains(ctx.dialect())) { ctx.sqlIndentEnd(')'); } - if (FALSE.equals(withData) && !NO_SUPPORT_WITH_DATA.contains(ctx.dialect())) + if (WithOrWithoutData.WITH_NO_DATA == withData && !NO_SUPPORT_WITH_DATA.contains(ctx.dialect())) ctx.formatSeparator() .visit(K_WITH_NO_DATA); - else if (TRUE.equals(withData) && !NO_SUPPORT_WITH_DATA.contains(ctx.dialect())) + else if (WithOrWithoutData.WITH_DATA == withData && !NO_SUPPORT_WITH_DATA.contains(ctx.dialect())) ctx.formatSeparator() .visit(K_WITH_DATA); else if (REQUIRES_WITH_DATA.contains(ctx.dialect())) @@ -725,7 +695,7 @@ implements private final void toSQLCreateTableName(Context ctx) { - ctx.start(CREATE_TABLE_NAME) + ctx.start(Clause.CREATE_TABLE_NAME) .visit(K_CREATE) .sql(' '); @@ -743,7 +713,7 @@ implements .sql(' '); ctx.visit(table) - .end(CREATE_TABLE_NAME); + .end(Clause.CREATE_TABLE_NAME); } private final void toSQLOnCommit(Context ctx) { @@ -762,6 +732,139 @@ implements + + + + + + + + + + + + + + + + + // ------------------------------------------------------------------------- + // XXX: Query Object Model + // ------------------------------------------------------------------------- + + @Override + public final Table $table() { + return table; + } + + @Override + public final boolean $temporary() { + return temporary; + } + + @Override + public final boolean $ifNotExists() { + return ifNotExists; + } + + @Override + public final UnmodifiableList $tableElements() { + return QOM.unmodifiable(tableElements); + } + + @Override + public final Select $select() { + return select; + } + + @Override + public final WithOrWithoutData $withData() { + return withData; + } + + @Override + public final TableCommitAction $onCommit() { + return onCommit; + } + + @Override + public final Comment $comment() { + return comment; + } + + @Override + public final SQL $storage() { + return storage; + } + + @Override + public final QOM.CreateTable $table(Table newValue) { + return $constructor().apply(newValue, $temporary(), $ifNotExists(), $tableElements(), $select(), $withData(), $onCommit(), $comment(), $storage()); + } + + @Override + public final QOM.CreateTable $temporary(boolean newValue) { + return $constructor().apply($table(), newValue, $ifNotExists(), $tableElements(), $select(), $withData(), $onCommit(), $comment(), $storage()); + } + + @Override + public final QOM.CreateTable $ifNotExists(boolean newValue) { + return $constructor().apply($table(), $temporary(), newValue, $tableElements(), $select(), $withData(), $onCommit(), $comment(), $storage()); + } + + @Override + public final QOM.CreateTable $tableElements(Collection newValue) { + return $constructor().apply($table(), $temporary(), $ifNotExists(), newValue, $select(), $withData(), $onCommit(), $comment(), $storage()); + } + + @Override + public final QOM.CreateTable $select(Select newValue) { + return $constructor().apply($table(), $temporary(), $ifNotExists(), $tableElements(), newValue, $withData(), $onCommit(), $comment(), $storage()); + } + + @Override + public final QOM.CreateTable $withData(WithOrWithoutData newValue) { + return $constructor().apply($table(), $temporary(), $ifNotExists(), $tableElements(), $select(), newValue, $onCommit(), $comment(), $storage()); + } + + @Override + public final QOM.CreateTable $onCommit(TableCommitAction newValue) { + return $constructor().apply($table(), $temporary(), $ifNotExists(), $tableElements(), $select(), $withData(), newValue, $comment(), $storage()); + } + + @Override + public final QOM.CreateTable $comment(Comment newValue) { + return $constructor().apply($table(), $temporary(), $ifNotExists(), $tableElements(), $select(), $withData(), $onCommit(), newValue, $storage()); + } + + @Override + public final QOM.CreateTable $storage(SQL newValue) { + return $constructor().apply($table(), $temporary(), $ifNotExists(), $tableElements(), $select(), $withData(), $onCommit(), $comment(), newValue); + } + + public final Function9, ? super Boolean, ? super Boolean, ? super Collection, ? super Select, ? super WithOrWithoutData, ? super TableCommitAction, ? super Comment, ? super SQL, ? extends QOM.CreateTable> $constructor() { + return (a1, a2, a3, a4, a5, a6, a7, a8, a9) -> new CreateTableImpl(configuration(), a1, a2, a3, (Collection) a4, a5, a6, a7, a8, a9); + } + + + + + + + + + + + + + + + + + + + + diff --git a/jOOQ/src/main/java/org/jooq/impl/DDL.java b/jOOQ/src/main/java/org/jooq/impl/DDL.java index 7883eaeb3e..ddcd2f3593 100644 --- a/jOOQ/src/main/java/org/jooq/impl/DDL.java +++ b/jOOQ/src/main/java/org/jooq/impl/DDL.java @@ -57,7 +57,6 @@ import static org.jooq.impl.Tools.map; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; -import java.util.Collections; import java.util.List; import org.jooq.Check; @@ -138,7 +137,7 @@ final class DDL { .constraints(constraints); if (temporary && onCommit != null) { - switch (table.getOptions().onCommit()) { + switch (onCommit) { case DELETE_ROWS: return asList(s0.onCommitDeleteRows()); case PRESERVE_ROWS: diff --git a/jOOQ/src/main/java/org/jooq/impl/DSL.java b/jOOQ/src/main/java/org/jooq/impl/DSL.java index 1742e06fb7..f68ef811df 100644 --- a/jOOQ/src/main/java/org/jooq/impl/DSL.java +++ b/jOOQ/src/main/java/org/jooq/impl/DSL.java @@ -191,7 +191,6 @@ import org.jooq.ConstraintForeignKeyReferencesStep9; import org.jooq.ConstraintForeignKeyReferencesStepN; import org.jooq.ConstraintTypeStep; // ... -import org.jooq.CreateTableColumnStep; import org.jooq.CreateTypeStep; import org.jooq.CreateViewAsStep; import org.jooq.DSLContext; @@ -8376,6 +8375,280 @@ public class DSL { + /** + * The CREATE TABLE statement. + *

    + * Unlike statement construction methods in the {@link DSLContext} API, this + * creates an unattached, and thus not directly renderable or executable + * statement. It can be used as a subquery or nested in procedural logic. + * + * @see DSLContext#createTable(String) + */ + @NotNull @CheckReturnValue + @Support + public static org.jooq.CreateTableElementListStep createTable(@Stringly.Name String table) { + return dsl().createTable(table); + } + + /** + * The CREATE TABLE statement. + *

    + * Unlike statement construction methods in the {@link DSLContext} API, this + * creates an unattached, and thus not directly renderable or executable + * statement. It can be used as a subquery or nested in procedural logic. + * + * @see DSLContext#createTable(Name) + */ + @NotNull @CheckReturnValue + @Support + public static org.jooq.CreateTableElementListStep createTable(Name table) { + return dsl().createTable(table); + } + + /** + * The CREATE TABLE statement. + *

    + * Unlike statement construction methods in the {@link DSLContext} API, this + * creates an unattached, and thus not directly renderable or executable + * statement. It can be used as a subquery or nested in procedural logic. + * + * @see DSLContext#createTable(Table) + */ + @NotNull @CheckReturnValue + @Support + public static org.jooq.CreateTableElementListStep createTable(Table table) { + return dsl().createTable(table); + } + + /** + * The CREATE TABLE IF NOT EXISTS statement. + *

    + * Unlike statement construction methods in the {@link DSLContext} API, this + * creates an unattached, and thus not directly renderable or executable + * statement. It can be used as a subquery or nested in procedural logic. + * + * @see DSLContext#createTableIfNotExists(String) + */ + @NotNull @CheckReturnValue + @Support({ FIREBIRD, H2, HSQLDB, IGNITE, MARIADB, MYSQL, POSTGRES, SQLITE, YUGABYTEDB }) + public static org.jooq.CreateTableElementListStep createTableIfNotExists(@Stringly.Name String table) { + return dsl().createTableIfNotExists(table); + } + + /** + * The CREATE TABLE IF NOT EXISTS statement. + *

    + * Unlike statement construction methods in the {@link DSLContext} API, this + * creates an unattached, and thus not directly renderable or executable + * statement. It can be used as a subquery or nested in procedural logic. + * + * @see DSLContext#createTableIfNotExists(Name) + */ + @NotNull @CheckReturnValue + @Support({ FIREBIRD, H2, HSQLDB, IGNITE, MARIADB, MYSQL, POSTGRES, SQLITE, YUGABYTEDB }) + public static org.jooq.CreateTableElementListStep createTableIfNotExists(Name table) { + return dsl().createTableIfNotExists(table); + } + + /** + * The CREATE TABLE IF NOT EXISTS statement. + *

    + * Unlike statement construction methods in the {@link DSLContext} API, this + * creates an unattached, and thus not directly renderable or executable + * statement. It can be used as a subquery or nested in procedural logic. + * + * @see DSLContext#createTableIfNotExists(Table) + */ + @NotNull @CheckReturnValue + @Support({ FIREBIRD, H2, HSQLDB, IGNITE, MARIADB, MYSQL, POSTGRES, SQLITE, YUGABYTEDB }) + public static org.jooq.CreateTableElementListStep createTableIfNotExists(Table table) { + return dsl().createTableIfNotExists(table); + } + + /** + * The CREATE TEMPORARY TABLE statement. + *

    + * Unlike statement construction methods in the {@link DSLContext} API, this + * creates an unattached, and thus not directly renderable or executable + * statement. It can be used as a subquery or nested in procedural logic. + * + * @see DSLContext#createTemporaryTable(String) + */ + @NotNull @CheckReturnValue + @Support({ FIREBIRD, MARIADB, MYSQL, POSTGRES, YUGABYTEDB }) + public static org.jooq.CreateTableElementListStep createTemporaryTable(@Stringly.Name String table) { + return dsl().createTemporaryTable(table); + } + + /** + * The CREATE TEMPORARY TABLE statement. + *

    + * Unlike statement construction methods in the {@link DSLContext} API, this + * creates an unattached, and thus not directly renderable or executable + * statement. It can be used as a subquery or nested in procedural logic. + * + * @see DSLContext#createTemporaryTable(Name) + */ + @NotNull @CheckReturnValue + @Support({ FIREBIRD, MARIADB, MYSQL, POSTGRES, YUGABYTEDB }) + public static org.jooq.CreateTableElementListStep createTemporaryTable(Name table) { + return dsl().createTemporaryTable(table); + } + + /** + * The CREATE TEMPORARY TABLE statement. + *

    + * Unlike statement construction methods in the {@link DSLContext} API, this + * creates an unattached, and thus not directly renderable or executable + * statement. It can be used as a subquery or nested in procedural logic. + * + * @see DSLContext#createTemporaryTable(Table) + */ + @NotNull @CheckReturnValue + @Support({ FIREBIRD, MARIADB, MYSQL, POSTGRES, YUGABYTEDB }) + public static org.jooq.CreateTableElementListStep createTemporaryTable(Table table) { + return dsl().createTemporaryTable(table); + } + + /** + * The CREATE TEMPORARY TABLE IF NOT EXISTS statement. + *

    + * Unlike statement construction methods in the {@link DSLContext} API, this + * creates an unattached, and thus not directly renderable or executable + * statement. It can be used as a subquery or nested in procedural logic. + * + * @see DSLContext#createTemporaryTableIfNotExists(String) + */ + @NotNull @CheckReturnValue + @Support({ FIREBIRD, MARIADB, MYSQL, POSTGRES, YUGABYTEDB }) + public static org.jooq.CreateTableElementListStep createTemporaryTableIfNotExists(@Stringly.Name String table) { + return dsl().createTemporaryTableIfNotExists(table); + } + + /** + * The CREATE TEMPORARY TABLE IF NOT EXISTS statement. + *

    + * Unlike statement construction methods in the {@link DSLContext} API, this + * creates an unattached, and thus not directly renderable or executable + * statement. It can be used as a subquery or nested in procedural logic. + * + * @see DSLContext#createTemporaryTableIfNotExists(Name) + */ + @NotNull @CheckReturnValue + @Support({ FIREBIRD, MARIADB, MYSQL, POSTGRES, YUGABYTEDB }) + public static org.jooq.CreateTableElementListStep createTemporaryTableIfNotExists(Name table) { + return dsl().createTemporaryTableIfNotExists(table); + } + + /** + * The CREATE TEMPORARY TABLE IF NOT EXISTS statement. + *

    + * Unlike statement construction methods in the {@link DSLContext} API, this + * creates an unattached, and thus not directly renderable or executable + * statement. It can be used as a subquery or nested in procedural logic. + * + * @see DSLContext#createTemporaryTableIfNotExists(Table) + */ + @NotNull @CheckReturnValue + @Support({ FIREBIRD, MARIADB, MYSQL, POSTGRES, YUGABYTEDB }) + public static org.jooq.CreateTableElementListStep createTemporaryTableIfNotExists(Table table) { + return dsl().createTemporaryTableIfNotExists(table); + } + + /** + * The CREATE GLOBAL TEMPORARY TABLE statement. + *

    + * Unlike statement construction methods in the {@link DSLContext} API, this + * creates an unattached, and thus not directly renderable or executable + * statement. It can be used as a subquery or nested in procedural logic. + * + * @see DSLContext#createGlobalTemporaryTable(String) + */ + @NotNull @CheckReturnValue + @Support({ FIREBIRD, MARIADB, MYSQL, POSTGRES, YUGABYTEDB }) + public static org.jooq.CreateTableElementListStep createGlobalTemporaryTable(@Stringly.Name String table) { + return dsl().createGlobalTemporaryTable(table); + } + + /** + * The CREATE GLOBAL TEMPORARY TABLE statement. + *

    + * Unlike statement construction methods in the {@link DSLContext} API, this + * creates an unattached, and thus not directly renderable or executable + * statement. It can be used as a subquery or nested in procedural logic. + * + * @see DSLContext#createGlobalTemporaryTable(Name) + */ + @NotNull @CheckReturnValue + @Support({ FIREBIRD, MARIADB, MYSQL, POSTGRES, YUGABYTEDB }) + public static org.jooq.CreateTableElementListStep createGlobalTemporaryTable(Name table) { + return dsl().createGlobalTemporaryTable(table); + } + + /** + * The CREATE GLOBAL TEMPORARY TABLE statement. + *

    + * Unlike statement construction methods in the {@link DSLContext} API, this + * creates an unattached, and thus not directly renderable or executable + * statement. It can be used as a subquery or nested in procedural logic. + * + * @see DSLContext#createGlobalTemporaryTable(Table) + */ + @NotNull @CheckReturnValue + @Support({ FIREBIRD, MARIADB, MYSQL, POSTGRES, YUGABYTEDB }) + public static org.jooq.CreateTableElementListStep createGlobalTemporaryTable(Table table) { + return dsl().createGlobalTemporaryTable(table); + } + + /** + * The CREATE GLOBAL TEMPORARY TABLE IF NOT EXISTS statement. + *

    + * Unlike statement construction methods in the {@link DSLContext} API, this + * creates an unattached, and thus not directly renderable or executable + * statement. It can be used as a subquery or nested in procedural logic. + * + * @see DSLContext#createGlobalTemporaryTableIfNotExists(String) + */ + @NotNull @CheckReturnValue + @Support({ FIREBIRD, H2, HSQLDB, IGNITE, MARIADB, MYSQL, POSTGRES, SQLITE, YUGABYTEDB }) + public static org.jooq.CreateTableElementListStep createGlobalTemporaryTableIfNotExists(@Stringly.Name String table) { + return dsl().createGlobalTemporaryTableIfNotExists(table); + } + + /** + * The CREATE GLOBAL TEMPORARY TABLE IF NOT EXISTS statement. + *

    + * Unlike statement construction methods in the {@link DSLContext} API, this + * creates an unattached, and thus not directly renderable or executable + * statement. It can be used as a subquery or nested in procedural logic. + * + * @see DSLContext#createGlobalTemporaryTableIfNotExists(Name) + */ + @NotNull @CheckReturnValue + @Support({ FIREBIRD, H2, HSQLDB, IGNITE, MARIADB, MYSQL, POSTGRES, SQLITE, YUGABYTEDB }) + public static org.jooq.CreateTableElementListStep createGlobalTemporaryTableIfNotExists(Name table) { + return dsl().createGlobalTemporaryTableIfNotExists(table); + } + + /** + * The CREATE GLOBAL TEMPORARY TABLE IF NOT EXISTS statement. + *

    + * Unlike statement construction methods in the {@link DSLContext} API, this + * creates an unattached, and thus not directly renderable or executable + * statement. It can be used as a subquery or nested in procedural logic. + * + * @see DSLContext#createGlobalTemporaryTableIfNotExists(Table) + */ + @NotNull @CheckReturnValue + @Support({ FIREBIRD, H2, HSQLDB, IGNITE, MARIADB, MYSQL, POSTGRES, SQLITE, YUGABYTEDB }) + public static org.jooq.CreateTableElementListStep createGlobalTemporaryTableIfNotExists(Table table) { + return dsl().createGlobalTemporaryTableIfNotExists(table); + } + + + + + @@ -9950,171 +10223,6 @@ public class DSL { - - /** - * Create a new DSL CREATE TABLE statement. - * - * @see DSLContext#createTable(String) - */ - @NotNull - @Support - public static CreateTableColumnStep createTable(String table) { - return dsl().createTable(table); - } - - /** - * Create a new DSL CREATE TABLE statement. - * - * @see DSLContext#createTable(Name) - */ - @NotNull - @Support - public static CreateTableColumnStep createTable(Name table) { - return dsl().createTable(table); - } - - /** - * Create a new DSL CREATE TABLE statement. - * - * @see DSLContext#createTable(Table) - */ - @NotNull - @Support - public static CreateTableColumnStep createTable(Table table) { - return dsl().createTable(table); - } - - /** - * Create a new DSL CREATE TABLE statement. - * - * @see DSLContext#createTableIfNotExists(String) - */ - @NotNull - @Support({ FIREBIRD, H2, HSQLDB, IGNITE, MARIADB, MYSQL, POSTGRES, SQLITE, YUGABYTEDB }) - public static CreateTableColumnStep createTableIfNotExists(String table) { - return dsl().createTableIfNotExists(table); - } - - /** - * Create a new DSL CREATE TABLE statement. - * - * @see DSLContext#createTableIfNotExists(Name) - */ - @NotNull - @Support({ FIREBIRD, H2, HSQLDB, IGNITE, MARIADB, MYSQL, POSTGRES, SQLITE, YUGABYTEDB }) - public static CreateTableColumnStep createTableIfNotExists(Name table) { - return dsl().createTableIfNotExists(table); - } - - /** - * Create a new DSL CREATE TABLE statement. - * - * @see DSLContext#createTableIfNotExists(Table) - */ - @NotNull - @Support({ FIREBIRD, H2, HSQLDB, IGNITE, MARIADB, MYSQL, POSTGRES, SQLITE, YUGABYTEDB }) - public static CreateTableColumnStep createTableIfNotExists(Table table) { - return dsl().createTableIfNotExists(table); - } - - /** - * Create a new DSL CREATE TEMPORARY TABLE statement. - * - * @see DSLContext#createTemporaryTable(String) - */ - @NotNull - @Support({ FIREBIRD, MARIADB, MYSQL, POSTGRES, YUGABYTEDB }) - public static CreateTableColumnStep createTemporaryTable(String table) { - return dsl().createTemporaryTable(table); - } - - /** - * Create a new DSL CREATE TEMPORARY TABLE statement. - * - * @see DSLContext#createTemporaryTable(Name) - */ - @NotNull - @Support({ FIREBIRD, MARIADB, MYSQL, POSTGRES, YUGABYTEDB }) - public static CreateTableColumnStep createTemporaryTable(Name table) { - return dsl().createTemporaryTable(table); - } - - /** - * Create a new DSL CREATE TEMPORARY TABLE statement. - * - * @see DSLContext#createTemporaryTable(Table) - */ - @NotNull - @Support({ FIREBIRD, MARIADB, MYSQL, POSTGRES, YUGABYTEDB }) - public static CreateTableColumnStep createTemporaryTable(Table table) { - return dsl().createTemporaryTable(table); - } - - /** - * Create a new DSL CREATE TEMPORARY TABLE statement. - * - * @see DSLContext#createTemporaryTableIfNotExists(String) - */ - @NotNull - @Support({ FIREBIRD, MARIADB, MYSQL, POSTGRES, YUGABYTEDB }) - public static CreateTableColumnStep createTemporaryTableIfNotExists(String table) { - return dsl().createTemporaryTableIfNotExists(table); - } - - /** - * Create a new DSL CREATE TEMPORARY TABLE statement. - * - * @see DSLContext#createTemporaryTableIfNotExists(Name) - */ - @NotNull - @Support({ FIREBIRD, MARIADB, MYSQL, POSTGRES, YUGABYTEDB }) - public static CreateTableColumnStep createTemporaryTableIfNotExists(Name table) { - return dsl().createTemporaryTableIfNotExists(table); - } - - /** - * Create a new DSL CREATE TEMPORARY TABLE statement. - * - * @see DSLContext#createTemporaryTableIfNotExists(Table) - */ - @NotNull - @Support({ FIREBIRD, MARIADB, MYSQL, POSTGRES, YUGABYTEDB }) - public static CreateTableColumnStep createTemporaryTableIfNotExists(Table table) { - return dsl().createTemporaryTableIfNotExists(table); - } - - /** - * Create a new DSL CREATE GLOBAL TEMPORARY TABLE statement. - * - * @see DSLContext#createGlobalTemporaryTable(String) - */ - @NotNull - @Support({ FIREBIRD, MARIADB, MYSQL, POSTGRES, YUGABYTEDB }) - public static CreateTableColumnStep createGlobalTemporaryTable(String table) { - return dsl().createGlobalTemporaryTable(table); - } - - /** - * Create a new DSL CREATE GLOBAL TEMPORARY TABLE statement. - * - * @see DSLContext#createGlobalTemporaryTable(Name) - */ - @NotNull - @Support({ FIREBIRD, MARIADB, MYSQL, POSTGRES, YUGABYTEDB }) - public static CreateTableColumnStep createGlobalTemporaryTable(Name table) { - return dsl().createGlobalTemporaryTable(table); - } - - /** - * Create a new DSL CREATE GLOBAL TEMPORARY TABLE statement. - * - * @see DSLContext#createGlobalTemporaryTable(Table) - */ - @NotNull - @Support({ FIREBIRD, MARIADB, MYSQL, POSTGRES, YUGABYTEDB }) - public static CreateTableColumnStep createGlobalTemporaryTable(Table table) { - return dsl().createGlobalTemporaryTable(table); - } /** * Create a new DSL CREATE VIEW statement. diff --git a/jOOQ/src/main/java/org/jooq/impl/DefaultDSLContext.java b/jOOQ/src/main/java/org/jooq/impl/DefaultDSLContext.java index e4dce9fb60..0eefd360d0 100644 --- a/jOOQ/src/main/java/org/jooq/impl/DefaultDSLContext.java +++ b/jOOQ/src/main/java/org/jooq/impl/DefaultDSLContext.java @@ -110,7 +110,6 @@ import org.jooq.ConnectionProvider; import org.jooq.ConnectionRunnable; import org.jooq.ContextTransactionalCallable; import org.jooq.ContextTransactionalRunnable; -import org.jooq.CreateTableColumnStep; import org.jooq.CreateTypeStep; import org.jooq.CreateViewAsStep; import org.jooq.Cursor; @@ -3270,6 +3269,100 @@ public class DefaultDSLContext extends AbstractScope implements DSLContext, Seri + @Override + public org.jooq.CreateTableElementListStep createTable(@Stringly.Name String table) { + return new CreateTableImpl(configuration(), DSL.table(DSL.name(table)), false, false); + } + + @Override + public org.jooq.CreateTableElementListStep createTable(Name table) { + return new CreateTableImpl(configuration(), DSL.table(table), false, false); + } + + @Override + public org.jooq.CreateTableElementListStep createTable(Table table) { + return new CreateTableImpl(configuration(), table, false, false); + } + + @Override + public org.jooq.CreateTableElementListStep createTableIfNotExists(@Stringly.Name String table) { + return new CreateTableImpl(configuration(), DSL.table(DSL.name(table)), false, true); + } + + @Override + public org.jooq.CreateTableElementListStep createTableIfNotExists(Name table) { + return new CreateTableImpl(configuration(), DSL.table(table), false, true); + } + + @Override + public org.jooq.CreateTableElementListStep createTableIfNotExists(Table table) { + return new CreateTableImpl(configuration(), table, false, true); + } + + @Override + public org.jooq.CreateTableElementListStep createTemporaryTable(@Stringly.Name String table) { + return new CreateTableImpl(configuration(), DSL.table(DSL.name(table)), true, false); + } + + @Override + public org.jooq.CreateTableElementListStep createTemporaryTable(Name table) { + return new CreateTableImpl(configuration(), DSL.table(table), true, false); + } + + @Override + public org.jooq.CreateTableElementListStep createTemporaryTable(Table table) { + return new CreateTableImpl(configuration(), table, true, false); + } + + @Override + public org.jooq.CreateTableElementListStep createTemporaryTableIfNotExists(@Stringly.Name String table) { + return new CreateTableImpl(configuration(), DSL.table(DSL.name(table)), true, true); + } + + @Override + public org.jooq.CreateTableElementListStep createTemporaryTableIfNotExists(Name table) { + return new CreateTableImpl(configuration(), DSL.table(table), true, true); + } + + @Override + public org.jooq.CreateTableElementListStep createTemporaryTableIfNotExists(Table table) { + return new CreateTableImpl(configuration(), table, true, true); + } + + @Override + public org.jooq.CreateTableElementListStep createGlobalTemporaryTable(@Stringly.Name String table) { + return new CreateTableImpl(configuration(), DSL.table(DSL.name(table)), true, false); + } + + @Override + public org.jooq.CreateTableElementListStep createGlobalTemporaryTable(Name table) { + return new CreateTableImpl(configuration(), DSL.table(table), true, false); + } + + @Override + public org.jooq.CreateTableElementListStep createGlobalTemporaryTable(Table table) { + return new CreateTableImpl(configuration(), table, true, false); + } + + @Override + public org.jooq.CreateTableElementListStep createGlobalTemporaryTableIfNotExists(@Stringly.Name String table) { + return new CreateTableImpl(configuration(), DSL.table(DSL.name(table)), true, true); + } + + @Override + public org.jooq.CreateTableElementListStep createGlobalTemporaryTableIfNotExists(Name table) { + return new CreateTableImpl(configuration(), DSL.table(table), true, true); + } + + @Override + public org.jooq.CreateTableElementListStep createGlobalTemporaryTableIfNotExists(Table table) { + return new CreateTableImpl(configuration(), table, true, true); + } + + + + + @@ -4029,81 +4122,6 @@ public class DefaultDSLContext extends AbstractScope implements DSLContext, Seri return new CreateViewImpl<>(configuration(), view, fieldNameFunction, true, false); } - @Override - public CreateTableColumnStep createTable(String table) { - return createTable(name(table)); - } - - @Override - public CreateTableColumnStep createTable(Name table) { - return createTable(table(table)); - } - - @Override - public CreateTableColumnStep createTable(Table table) { - return new CreateTableImpl(configuration(), table, false, false); - } - - @Override - public CreateTableColumnStep createTableIfNotExists(String table) { - return createTableIfNotExists(name(table)); - } - - @Override - public CreateTableColumnStep createTableIfNotExists(Name table) { - return createTableIfNotExists(table(table)); - } - - @Override - public CreateTableColumnStep createTableIfNotExists(Table table) { - return new CreateTableImpl(configuration(), table, false, true); - } - - @Override - public CreateTableColumnStep createTemporaryTable(String table) { - return createTemporaryTable(name(table)); - } - - @Override - public CreateTableColumnStep createTemporaryTable(Name table) { - return createTemporaryTable(table(table)); - } - - @Override - public CreateTableColumnStep createTemporaryTable(Table table) { - return new CreateTableImpl(configuration(), table, true, false); - } - - @Override - public CreateTableColumnStep createTemporaryTableIfNotExists(String table) { - return createTemporaryTableIfNotExists(name(table)); - } - - @Override - public CreateTableColumnStep createTemporaryTableIfNotExists(Name table) { - return createTemporaryTableIfNotExists(table(table)); - } - - @Override - public CreateTableColumnStep createTemporaryTableIfNotExists(Table table) { - return new CreateTableImpl(configuration(), table, true, true); - } - - @Override - public CreateTableColumnStep createGlobalTemporaryTable(String table) { - return createGlobalTemporaryTable(name(table)); - } - - @Override - public CreateTableColumnStep createGlobalTemporaryTable(Name table) { - return createGlobalTemporaryTable(table(table)); - } - - @Override - public CreateTableColumnStep createGlobalTemporaryTable(Table table) { - return new CreateTableImpl(configuration(), table, true, false); - } - @Override public CreateTypeStep createType(String type) { return createType(name(type)); diff --git a/jOOQ/src/main/java/org/jooq/impl/Internal.java b/jOOQ/src/main/java/org/jooq/impl/Internal.java index 4c9e8800cc..0cbd078a97 100644 --- a/jOOQ/src/main/java/org/jooq/impl/Internal.java +++ b/jOOQ/src/main/java/org/jooq/impl/Internal.java @@ -44,8 +44,10 @@ import java.lang.reflect.Array; import java.util.function.Consumer; import java.util.function.Supplier; +import org.jooq.Attachable; import org.jooq.Binding; import org.jooq.Check; +import org.jooq.Configuration; import org.jooq.Converter; import org.jooq.DataType; import org.jooq.Domain; @@ -494,4 +496,12 @@ public final class Internal { public static final void requireCommercial(Supplier logMessage) throws DataAccessException { CTX.configuration().requireCommercial(logMessage); } + + /** + * Retrieve a {@link Configuration} from an attachable, or the default + * {@link Configuration} if the attachable is detached. + */ + public static final Configuration configuration(Attachable attachable) { + return Tools.configuration(attachable); + } } diff --git a/jOOQ/src/main/java/org/jooq/impl/Interpreter.java b/jOOQ/src/main/java/org/jooq/impl/Interpreter.java index 95f40ea177..48cef8c816 100644 --- a/jOOQ/src/main/java/org/jooq/impl/Interpreter.java +++ b/jOOQ/src/main/java/org/jooq/impl/Interpreter.java @@ -101,6 +101,7 @@ import org.jooq.Sequence; import org.jooq.SortField; import org.jooq.SortOrder; import org.jooq.Table; +import org.jooq.TableElement; import org.jooq.TableField; import org.jooq.TableOptions; import org.jooq.TableOptions.TableType; @@ -327,7 +328,7 @@ final class Interpreter { return; } - MutableTable mt = newTable(table, schema, query.$columnFields(), query.$columnTypes(), query.$select(), query.$comment(), query.$temporary() ? TableOptions.temporaryTable(query.$onCommit()) : TableOptions.table()); + MutableTable mt = newTable(table, schema, query.$columns(), query.$select(), query.$comment(), query.$temporary() ? TableOptions.temporaryTable(query.$onCommit()) : TableOptions.table()); for (Constraint constraint : query.$constraints()) addConstraint(query, (ConstraintImpl) constraint, mt); @@ -499,7 +500,7 @@ final class Interpreter { throw objectNotTable(table); if (query.$add() != null) { - for (FieldOrConstraint fc : query.$add()) + for (TableElement fc : query.$add()) if (fc instanceof Field && find(existing.fields, (Field) fc) != null) throw alreadyExists(fc); else if (fc instanceof Constraint && !fc.getUnqualifiedName().empty() && existing.constraint((Constraint) fc) != null) @@ -523,7 +524,7 @@ final class Interpreter { addField(existing, index, (UnqualifiedName) f.getUnqualifiedName(), f.getDataType()); } else { - for (FieldOrConstraint fc : query.$add()) + for (TableElement fc : query.$add()) if (fc instanceof Field) addField(existing, Integer.MAX_VALUE, (UnqualifiedName) fc.getUnqualifiedName(), ((Field) fc).getDataType()); else if (fc instanceof ConstraintImpl) @@ -701,9 +702,9 @@ final class Interpreter { throw unsupportedQuery(query); } - private final Iterable> assertFields(Query query, Iterable fields) { + private final Iterable> assertFields(Query query, Iterable fields) { return () -> new Iterator>() { - final Iterator it = fields.iterator(); + final Iterator it = fields.iterator(); @Override public boolean hasNext() { @@ -712,7 +713,7 @@ final class Interpreter { @Override public Field next() { - FieldOrConstraint next = it.next(); + TableElement next = it.next(); if (next instanceof Field) return (Field) next; @@ -810,11 +811,7 @@ final class Interpreter { return; } - List> columnTypes = query.$select() != null - ? dataTypes(query.$select()) - : map(query.$fields(), f -> f.getDataType()); - - newTable(table, schema, query.$fields(), columnTypes, query.$select(), null, TableOptions.view(query.$select())); + newTable(table, schema, query.$fields(), query.$select(), null, TableOptions.view(query.$select())); } private final void accept0(AlterViewImpl query) { @@ -1251,16 +1248,16 @@ final class Interpreter { Table table, MutableSchema schema, List> columns, - List> columnTypes, Select select, Comment comment, TableOptions options ) { MutableTable t = new MutableTable((UnqualifiedName) table.getUnqualifiedName(), schema, comment, options); + // TODO: [#13003] Merge the column and select types if both are available if (!columns.isEmpty()) for (int i = 0; i < columns.size(); i++) - addField(t, Integer.MAX_VALUE, (UnqualifiedName) columns.get(i).getUnqualifiedName(), columnTypes.get(i)); + addField(t, Integer.MAX_VALUE, (UnqualifiedName) columns.get(i).getUnqualifiedName(), columns.get(i).getDataType()); else if (select != null) for (Field column : select.fields()) addField(t, Integer.MAX_VALUE, (UnqualifiedName) column.getUnqualifiedName(), column.getDataType()); diff --git a/jOOQ/src/main/java/org/jooq/impl/ParserImpl.java b/jOOQ/src/main/java/org/jooq/impl/ParserImpl.java index 874346e274..10f73097c1 100644 --- a/jOOQ/src/main/java/org/jooq/impl/ParserImpl.java +++ b/jOOQ/src/main/java/org/jooq/impl/ParserImpl.java @@ -529,9 +529,8 @@ import org.jooq.CreateIndexWhereStep; // ... // ... import org.jooq.CreateSequenceFlagsStep; -import org.jooq.CreateTableColumnStep; import org.jooq.CreateTableCommentStep; -import org.jooq.CreateTableConstraintStep; +import org.jooq.CreateTableElementListStep; import org.jooq.CreateTableOnCommitStep; import org.jooq.CreateTableStorageStep; import org.jooq.CreateTableWithDataStep; @@ -645,6 +644,7 @@ import org.jooq.SortField; import org.jooq.SortOrder; import org.jooq.Statement; import org.jooq.Table; +import org.jooq.TableElement; import org.jooq.TableField; import org.jooq.TableLike; import org.jooq.TableOnStep; @@ -4394,7 +4394,7 @@ final class DefaultParseContext extends AbstractScope implements ParseContext { else ctas = true; - CreateTableColumnStep columnStep = ifNotExists + CreateTableElementListStep elementListStep = ifNotExists ? temporary ? dsl.createTemporaryTableIfNotExists(tableName) : dsl.createTableIfNotExists(tableName) @@ -4403,14 +4403,14 @@ final class DefaultParseContext extends AbstractScope implements ParseContext { : dsl.createTable(tableName); if (!fields.isEmpty()) - columnStep = columnStep.columns(fields); + elementListStep = elementListStep.columns(fields); // [#12888] To avoid ambiguities with T-SQL's support for statement batches // without statement separators, let's accept MySQL's optional AS // keyword only for empty field lists if (parseKeywordIf("AS") || fields.isEmpty() && peekSelectOrWith(true)) { boolean previousMetaLookupsForceIgnore = metaLookupsForceIgnore(); - CreateTableWithDataStep withDataStep = columnStep.as((Select) metaLookupsForceIgnore(false).parseQuery(true, true)); + CreateTableWithDataStep withDataStep = elementListStep.as((Select) metaLookupsForceIgnore(false).parseQuery(true, true)); metaLookupsForceIgnore(previousMetaLookupsForceIgnore); commentStep = parseKeywordIf("WITH DATA") @@ -4423,9 +4423,9 @@ final class DefaultParseContext extends AbstractScope implements ParseContext { throw expected("AS, WITH, SELECT, or ("); } else { - CreateTableConstraintStep constraintStep = constraints.isEmpty() - ? columnStep - : columnStep.constraints(constraints); + CreateTableElementListStep constraintStep = constraints.isEmpty() + ? elementListStep + : elementListStep.constraints(constraints); CreateTableOnCommitStep onCommitStep = indexes.isEmpty() ? constraintStep : constraintStep.indexes(indexes); @@ -5297,7 +5297,7 @@ final class DefaultParseContext extends AbstractScope implements ParseContext { } private final DDLQuery parseAlterTableAdd(AlterTableStep s1, Table tableName) { - List list = new ArrayList<>(); + List list = new ArrayList<>(); if (parseIndexOrKeyIf()) { Name name = parseIdentifierIf(); @@ -5358,7 +5358,7 @@ final class DefaultParseContext extends AbstractScope implements ParseContext { || parseKeywordIf("KEY"); } - private final void parseAlterTableAddFieldsOrConstraints(List list) { + private final void parseAlterTableAddFieldsOrConstraints(List list) { ConstraintTypeStep constraint = parseConstraintNameSpecification(); if (parsePrimaryKeyClusteredNonClusteredKeywordIf()) @@ -5382,7 +5382,7 @@ final class DefaultParseContext extends AbstractScope implements ParseContext { return null; } - private final Field parseAlterTableAddField(List list) { + private final Field parseAlterTableAddField(List list) { // The below code is taken from CREATE TABLE, with minor modifications as // https://github.com/jOOQ/jOOQ/issues/5317 has not yet been implemented diff --git a/jOOQ/src/main/java/org/jooq/impl/QOM.java b/jOOQ/src/main/java/org/jooq/impl/QOM.java index ad569a45cb..291dfcd606 100644 --- a/jOOQ/src/main/java/org/jooq/impl/QOM.java +++ b/jOOQ/src/main/java/org/jooq/impl/QOM.java @@ -110,6 +110,7 @@ import org.jooq.Role; import org.jooq.Row; import org.jooq.RowCountQuery; import org.jooq.RowId; +import org.jooq.SQL; import org.jooq.SQLDialect; import org.jooq.Schema; import org.jooq.Select; @@ -117,6 +118,7 @@ import org.jooq.Sequence; import org.jooq.Spatial; import org.jooq.Statement; import org.jooq.Table; +import org.jooq.TableElement; // ... // ... import org.jooq.WindowDefinition; @@ -1339,6 +1341,37 @@ public final class QOM { + /** + * The CREATE TABLE statement. + */ + public /*sealed*/ interface CreateTable + extends + DDLQuery + //permits + // CreateTableImpl + { + @NotNull Table $table(); + boolean $temporary(); + boolean $ifNotExists(); + @NotNull UnmodifiableList $tableElements(); + @Nullable Select $select(); + @Nullable WithOrWithoutData $withData(); + @Nullable TableCommitAction $onCommit(); + @Nullable Comment $comment(); + @Nullable SQL $storage(); + @NotNull CreateTable $table(Table table); + @NotNull CreateTable $temporary(boolean temporary); + @NotNull CreateTable $ifNotExists(boolean ifNotExists); + @NotNull CreateTable $tableElements(Collection tableElements); + @NotNull CreateTable $select(Select select); + @NotNull CreateTable $withData(WithOrWithoutData withData); + @NotNull CreateTable $onCommit(TableCommitAction onCommit); + @NotNull CreateTable $comment(Comment comment); + @NotNull CreateTable $storage(SQL storage); + } + + + @@ -5721,6 +5754,41 @@ public final class QOM { } } + /** + * The WithOrWithoutData type. + *

    + * Specify whether a table created from a subquery should include the subquery's data. + */ + public enum WithOrWithoutData { + WITH_DATA(keyword("with data")), + WITH_NO_DATA(keyword("with no data")), + ; + + final Keyword keyword; + + private WithOrWithoutData(Keyword keyword) { + this.keyword = keyword; + } + } + + /** + * The TableCommitAction type. + *

    + * Specify the action to be taken on temporary tables when committing. + */ + public enum TableCommitAction { + DELETE_ROWS(keyword("delete rows")), + PRESERVE_ROWS(keyword("preserve rows")), + DROP(keyword("drop")), + ; + + final Keyword keyword; + + private TableCommitAction(Keyword keyword) { + this.keyword = keyword; + } + } +