diff --git a/jOOQ/src/main/java/org/jooq/DSLContext.java b/jOOQ/src/main/java/org/jooq/DSLContext.java index 210334d17f..6228cbd7ad 100644 --- a/jOOQ/src/main/java/org/jooq/DSLContext.java +++ b/jOOQ/src/main/java/org/jooq/DSLContext.java @@ -3899,6 +3899,22 @@ public interface DSLContext extends Scope , AutoCloseable { @Support({ FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE }) WithAsStep with(String alias, String... fieldAliases); + /** + * Create a WITH clause to supply subsequent + * SELECT, UPDATE, INSERT, + * DELETE, and MERGE statements with + * {@link CommonTableExpression}s. + *

+ * The RECURSIVE keyword may be optional or unsupported in some + * databases, in case of which it will not be rendered. For optimal database + * interoperability and readability, however, it is suggested that you use + * {@link #with(String, String...)} for strictly non-recursive CTE + * and {@link #withRecursive(String, String...)} for strictly + * recursive CTE. + */ + @Support({ FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE }) + WithAsStep with(String alias, Collection fieldAliases); + /** * Create a WITH clause to supply subsequent * SELECT, UPDATE, INSERT, @@ -3931,6 +3947,22 @@ public interface DSLContext extends Scope , AutoCloseable { @Support({ FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE }) WithAsStep with(Name alias, Name... fieldAliases); + /** + * Create a WITH clause to supply subsequent + * SELECT, UPDATE, INSERT, + * DELETE, and MERGE statements with + * {@link CommonTableExpression}s. + *

+ * The RECURSIVE keyword may be optional or unsupported in some + * databases, in case of which it will not be rendered. For optimal database + * interoperability and readability, however, it is suggested that you use + * {@link #with(Name, Name...)} for strictly non-recursive CTE + * and {@link #withRecursive(Name, Name...)} for strictly + * recursive CTE. + */ + @Support({ FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE }) + WithAsStep with(Name alias, Collection fieldAliases); + /** * Create a WITH clause to supply subsequent @@ -4703,6 +4735,30 @@ public interface DSLContext extends Scope , AutoCloseable { @Support({ FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE }) WithStep with(CommonTableExpression... tables); + /** + * Create a WITH clause to supply subsequent + * SELECT, UPDATE, INSERT, + * DELETE, and MERGE statements with + * {@link CommonTableExpression}s. + *

+ * Reusable {@link CommonTableExpression} types can be constructed through + *

+ *

+ * The RECURSIVE keyword may be optional or unsupported in some + * databases, in case of which it will not be rendered. For optimal database + * interoperability and readability, however, it is suggested that you use + * {@link #with(CommonTableExpression...)} for strictly non-recursive CTE + * and {@link #withRecursive(CommonTableExpression...)} for strictly + * recursive CTE. + */ + @Support({ FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE }) + WithStep with(Collection> tables); + /** * Create a WITH clause to supply subsequent * SELECT, UPDATE, INSERT, @@ -4735,6 +4791,22 @@ public interface DSLContext extends Scope , AutoCloseable { @Support({ FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE }) WithAsStep withRecursive(String alias, String... fieldAliases); + /** + * Create a WITH clause to supply subsequent + * SELECT, UPDATE, INSERT, + * DELETE, and MERGE statements with + * {@link CommonTableExpression}s. + *

+ * The RECURSIVE keyword may be optional or unsupported in some + * databases, in case of which it will not be rendered. For optimal database + * interoperability and readability, however, it is suggested that you use + * {@link #with(String, String...)} for strictly non-recursive CTE + * and {@link #withRecursive(String, String...)} for strictly + * recursive CTE. + */ + @Support({ FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE }) + WithAsStep withRecursive(String alias, Collection fieldAliases); + /** * Create a WITH clause to supply subsequent * SELECT, UPDATE, INSERT, @@ -4767,6 +4839,22 @@ public interface DSLContext extends Scope , AutoCloseable { @Support({ FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE }) WithAsStep withRecursive(Name alias, Name... fieldAliases); + /** + * Create a WITH clause to supply subsequent + * SELECT, UPDATE, INSERT, + * DELETE, and MERGE statements with + * {@link CommonTableExpression}s. + *

+ * The RECURSIVE keyword may be optional or unsupported in some + * databases, in case of which it will not be rendered. For optimal database + * interoperability and readability, however, it is suggested that you use + * {@link #with(Name, Name...)} for strictly non-recursive CTE + * and {@link #withRecursive(Name, Name...)} for strictly + * recursive CTE. + */ + @Support({ FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE }) + WithAsStep withRecursive(Name alias, Collection fieldAliases); + /** * Create a WITH clause to supply subsequent @@ -5541,6 +5629,30 @@ public interface DSLContext extends Scope , AutoCloseable { @Support({ FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE }) WithStep withRecursive(CommonTableExpression... tables); + /** + * Create a WITH clause to supply subsequent + * SELECT, UPDATE, INSERT, + * DELETE, and MERGE statements with + * {@link CommonTableExpression}s. + *

+ * Reusable {@link CommonTableExpression} types can be constructed through + *

+ *

+ * The RECURSIVE keyword may be optional or unsupported in some + * databases, in case of which it will not be rendered. For optimal database + * interoperability and readability, however, it is suggested that you use + * {@link #with(CommonTableExpression...)} for strictly non-recursive CTE + * and {@link #withRecursive(CommonTableExpression...)} for strictly + * recursive CTE. + */ + @Support({ FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE }) + WithStep withRecursive(Collection> tables); + /** * Create a new DSL select statement, projecting the known columns from a * table. diff --git a/jOOQ/src/main/java/org/jooq/WithStep.java b/jOOQ/src/main/java/org/jooq/WithStep.java index bc93a1ce7c..56c30e4cb9 100644 --- a/jOOQ/src/main/java/org/jooq/WithStep.java +++ b/jOOQ/src/main/java/org/jooq/WithStep.java @@ -115,6 +115,12 @@ public interface WithStep extends QueryPart { @Support({ FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE }) WithAsStep with(String alias, String... fieldAliases); + /** + * Add another common table expression to the WITH clause. + */ + @Support({ FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE }) + WithAsStep with(String alias, Collection fieldAliases); + /** * Add another common table expression to the WITH clause. */ @@ -127,6 +133,12 @@ public interface WithStep extends QueryPart { @Support({ FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE }) WithAsStep with(Name alias, Name... fieldAliases); + /** + * Add another common table expression to the WITH clause. + */ + @Support({ FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE }) + WithAsStep with(Name alias, Collection fieldAliases); + /** * Add another common table expression to the WITH clause. @@ -431,6 +443,20 @@ public interface WithStep extends QueryPart { @Support({ FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE }) WithStep with(CommonTableExpression... tables); + /** + * Add another common table expression to the WITH clause. + *

+ * Reusable {@link CommonTableExpression} types can be constructed through + *

+ */ + @Support({ FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE }) + WithStep with(Collection> tables); + // ------------------------------------------------------------------------- // XXX Continue with the actual INSERT, UPDATE, DELETE, SELECT statement type // ------------------------------------------------------------------------- diff --git a/jOOQ/src/main/java/org/jooq/impl/DSL.java b/jOOQ/src/main/java/org/jooq/impl/DSL.java index 193b27e994..b46f611e38 100644 --- a/jOOQ/src/main/java/org/jooq/impl/DSL.java +++ b/jOOQ/src/main/java/org/jooq/impl/DSL.java @@ -776,6 +776,24 @@ public class DSL { return new WithImpl(null, false).with(alias, fieldAliases); } + /** + * Create a WITH clause to supply subsequent + * SELECT, UPDATE, INSERT, + * DELETE, and MERGE statements with + * {@link CommonTableExpression}s. + *

+ * The RECURSIVE keyword may be optional or unsupported in some + * databases, in case of which it will not be rendered. For optimal database + * interoperability and readability, however, it is suggested that you use + * {@link #with(String, String...)} for strictly non-recursive CTE + * and {@link #withRecursive(String, String...)} for strictly + * recursive CTE. + */ + @Support({ FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE }) + public static WithAsStep with(String alias, Collection fieldAliases) { + return new WithImpl(null, false).with(alias, fieldAliases); + } + /** * Create a WITH clause to supply subsequent * SELECT, UPDATE, INSERT, @@ -812,6 +830,24 @@ public class DSL { return new WithImpl(null, false).with(alias, fieldAliases); } + /** + * Create a WITH clause to supply subsequent + * SELECT, UPDATE, INSERT, + * DELETE, and MERGE statements with + * {@link CommonTableExpression}s. + *

+ * The RECURSIVE keyword may be optional or unsupported in some + * databases, in case of which it will not be rendered. For optimal database + * interoperability and readability, however, it is suggested that you use + * {@link #with(Name, Name...)} for strictly non-recursive CTE + * and {@link #withRecursive(Name, Name...)} for strictly + * recursive CTE. + */ + @Support({ FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE }) + public static WithAsStep with(Name alias, Collection fieldAliases) { + return new WithImpl(null, false).with(alias, fieldAliases); + } + /** * Create a WITH clause to supply subsequent @@ -1657,6 +1693,32 @@ public class DSL { return new WithImpl(null, false).with(tables); } + /** + * Create a WITH clause to supply subsequent + * SELECT, UPDATE, INSERT, + * DELETE, and MERGE statements with + * {@link CommonTableExpression}s. + *

+ * Reusable {@link CommonTableExpression} types can be constructed through + *

+ *

+ * The RECURSIVE keyword may be optional or unsupported in some + * databases, in case of which it will not be rendered. For optimal database + * interoperability and readability, however, it is suggested that you use + * {@link #with(CommonTableExpression...)} for strictly non-recursive CTE + * and {@link #withRecursive(CommonTableExpression...)} for strictly + * recursive CTE. + */ + @Support({ FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE }) + public static WithStep with(Collection> tables) { + return new WithImpl(null, false).with(tables); + } + /** * Create a WITH clause to supply subsequent * SELECT, UPDATE, INSERT, @@ -1699,6 +1761,27 @@ public class DSL { return new WithImpl(null, true).with(alias, fieldAliases); } + /** + * Create a WITH clause to supply subsequent + * SELECT, UPDATE, INSERT, + * DELETE, and MERGE statements with + * {@link CommonTableExpression}s. + *

+ * The RECURSIVE keyword may be optional or unsupported in some + * databases, in case of which it will not be rendered. For optimal database + * interoperability and readability, however, it is suggested that you use + * {@link #with(String, String...)} for strictly non-recursive CTE + * and {@link #withRecursive(String, String...)} for strictly + * recursive CTE. + *

+ * Note that the {@link SQLDialect#H2} database only supports single-table, + * RECURSIVE common table expression lists. + */ + @Support({ FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE }) + public static WithAsStep withRecursive(String alias, Collection fieldAliases) { + return new WithImpl(null, true).with(alias, fieldAliases); + } + /** * Create a WITH clause to supply subsequent * SELECT, UPDATE, INSERT, @@ -1738,6 +1821,24 @@ public class DSL { return new WithImpl(null, true).with(alias, fieldAliases); } + /** + * Create a WITH clause to supply subsequent + * SELECT, UPDATE, INSERT, + * DELETE, and MERGE statements with + * {@link CommonTableExpression}s. + *

+ * The RECURSIVE keyword may be optional or unsupported in some + * databases, in case of which it will not be rendered. For optimal database + * interoperability and readability, however, it is suggested that you use + * {@link #with(Name, Name...)} for strictly non-recursive CTE + * and {@link #withRecursive(Name, Name...)} for strictly + * recursive CTE. + */ + @Support({ FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE }) + public static WithAsStep withRecursive(Name alias, Collection fieldAliases) { + return new WithImpl(null, true).with(alias, fieldAliases); + } + /** * Create a WITH clause to supply subsequent @@ -2590,6 +2691,35 @@ public class DSL { return new WithImpl(null, true).with(tables); } + /** + * Create a WITH clause to supply subsequent + * SELECT, UPDATE, INSERT, + * DELETE, and MERGE statements with + * {@link CommonTableExpression}s. + *

+ * Reusable {@link CommonTableExpression} types can be constructed through + *

+ *

+ * The RECURSIVE keyword may be optional or unsupported in some + * databases, in case of which it will not be rendered. For optimal database + * interoperability and readability, however, it is suggested that you use + * {@link #with(CommonTableExpression...)} for strictly non-recursive CTE + * and {@link #withRecursive(CommonTableExpression...)} for strictly + * recursive CTE. + *

+ * Note that the {@link SQLDialect#H2} database only supports single-table, + * RECURSIVE common table expression lists. + */ + @Support({ FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE }) + public static WithStep withRecursive(Collection> tables) { + return new WithImpl(null, true).with(tables); + } + /** * Create a new DSL select statement, projecting the known columns from a * table. diff --git a/jOOQ/src/main/java/org/jooq/impl/DefaultDSLContext.java b/jOOQ/src/main/java/org/jooq/impl/DefaultDSLContext.java index c9b99282d2..3a8b98e991 100644 --- a/jOOQ/src/main/java/org/jooq/impl/DefaultDSLContext.java +++ b/jOOQ/src/main/java/org/jooq/impl/DefaultDSLContext.java @@ -1592,6 +1592,11 @@ public class DefaultDSLContext extends AbstractScope implements DSLContext, Seri return new WithImpl(configuration(), false).with(alias, fieldAliases); } + @Override + public WithAsStep with(String alias, Collection fieldAliases) { + return new WithImpl(configuration(), false).with(alias, fieldAliases); + } + @Override public WithAsStep with(Name alias) { return new WithImpl(configuration(), false).with(alias); @@ -1602,6 +1607,11 @@ public class DefaultDSLContext extends AbstractScope implements DSLContext, Seri return new WithImpl(configuration(), false).with(alias, fieldAliases); } + @Override + public WithAsStep with(Name alias, Collection fieldAliases) { + return new WithImpl(configuration(), false).with(alias, fieldAliases); + } + @Override public WithAsStep with(String alias, Function, ? extends String> fieldNameFunction) { @@ -1843,6 +1853,11 @@ public class DefaultDSLContext extends AbstractScope implements DSLContext, Seri return new WithImpl(configuration(), false).with(tables); } + @Override + public WithStep with(Collection> tables) { + return new WithImpl(configuration(), false).with(tables); + } + @Override public WithAsStep withRecursive(String alias) { return new WithImpl(configuration(), true).with(alias); @@ -1853,6 +1868,11 @@ public class DefaultDSLContext extends AbstractScope implements DSLContext, Seri return new WithImpl(configuration(), true).with(alias, fieldAliases); } + @Override + public WithAsStep withRecursive(String alias, Collection fieldAliases) { + return new WithImpl(configuration(), true).with(alias, fieldAliases); + } + @Override public WithAsStep withRecursive(Name alias) { return new WithImpl(configuration(), true).with(alias); @@ -1863,6 +1883,11 @@ public class DefaultDSLContext extends AbstractScope implements DSLContext, Seri return new WithImpl(configuration(), true).with(alias, fieldAliases); } + @Override + public WithAsStep withRecursive(Name alias, Collection fieldAliases) { + return new WithImpl(configuration(), true).with(alias, fieldAliases); + } + @Override public WithAsStep withRecursive(String alias, Function, ? extends String> fieldNameFunction) { @@ -2104,6 +2129,11 @@ public class DefaultDSLContext extends AbstractScope implements DSLContext, Seri return new WithImpl(configuration(), true).with(tables); } + @Override + public WithStep withRecursive(Collection> tables) { + return new WithImpl(configuration(), true).with(tables); + } + @Override public SelectWhereStep selectFrom(Table table) { return new SelectImpl(configuration(), null).from(table); diff --git a/jOOQ/src/main/java/org/jooq/impl/WithImpl.java b/jOOQ/src/main/java/org/jooq/impl/WithImpl.java index b575c286fd..7569c4ea57 100644 --- a/jOOQ/src/main/java/org/jooq/impl/WithImpl.java +++ b/jOOQ/src/main/java/org/jooq/impl/WithImpl.java @@ -48,6 +48,7 @@ import static org.jooq.impl.DSL.one; import static org.jooq.impl.DSL.zero; import static org.jooq.impl.Keywords.K_RECURSIVE; import static org.jooq.impl.Keywords.K_WITH; +import static org.jooq.impl.Tools.EMPTY_NAME; import java.util.Arrays; import java.util.Collection; @@ -262,6 +263,11 @@ implements return with(DSL.name(a), Tools.names(f)); } + @Override + public final WithImpl with(String a, Collection f) { + return with(DSL.name(a), Tools.names(f)); + } + @Override public final WithImpl with(Name a) { return with(a, new Name[0]); @@ -275,6 +281,11 @@ implements return this; } + @Override + public final WithImpl with(Name a, Collection f) { + return with(a, f.toArray(EMPTY_NAME)); + } + @Override public final WithImpl with(String a, Function, ? extends String> f) { @@ -519,6 +530,11 @@ implements @Override public final WithStep with(CommonTableExpression... tables) { + return with(Arrays.asList(tables)); + } + + @Override + public final WithStep with(Collection> tables) { for (CommonTableExpression table : tables) cte.add(table);