diff --git a/jOOQ/src/main/java/org/jooq/AlterViewAsStep.java b/jOOQ/src/main/java/org/jooq/AlterViewAsStep.java
new file mode 100644
index 0000000000..15eda762eb
--- /dev/null
+++ b/jOOQ/src/main/java/org/jooq/AlterViewAsStep.java
@@ -0,0 +1,79 @@
+/*
+ * 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 static org.jooq.impl.DSL.*;
+
+import java.util.*;
+
+import org.jooq.impl.DSL;
+
+import org.jetbrains.annotations.*;
+
+/**
+ * A step in the construction of the ALTER VIEW statement.
+ *
+ *
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:
+ *
AS clause to the ALTER VIEW statement.
+ */
+ @Support({ FIREBIRD, H2, MARIADB, MYSQL, POSTGRES, YUGABYTEDB })
+ @NotNull @CheckReturnValue
+ AlterViewFinalStep as(Select> as);
+}
diff --git a/jOOQ/src/main/java/org/jooq/AlterViewStep.java b/jOOQ/src/main/java/org/jooq/AlterViewStep.java
index ddf118feaf..0734ea6d5c 100644
--- a/jOOQ/src/main/java/org/jooq/AlterViewStep.java
+++ b/jOOQ/src/main/java/org/jooq/AlterViewStep.java
@@ -68,14 +68,7 @@ import org.jetbrains.annotations.*;
*
*/
@SuppressWarnings({ "unused" })
-public interface AlterViewStep {
-
- /**
- * Add the AS clause to the ALTER VIEW statement.
- */
- @Support({ FIREBIRD, H2, MARIADB, MYSQL, POSTGRES, YUGABYTEDB })
- @NotNull @CheckReturnValue
- AlterViewFinalStep as(Select> as);
+public interface AlterViewStep extends AlterViewAsStep {
/**
* Add the COMMENT clause to the ALTER VIEW statement.
diff --git a/jOOQ/src/main/java/org/jooq/DSLContext.java b/jOOQ/src/main/java/org/jooq/DSLContext.java
index 419c74d6c5..5eb7511b17 100644
--- a/jOOQ/src/main/java/org/jooq/DSLContext.java
+++ b/jOOQ/src/main/java/org/jooq/DSLContext.java
@@ -9666,6 +9666,24 @@ public interface DSLContext extends Scope {
@Support({ H2, POSTGRES, YUGABYTEDB })
AlterViewStep alterViewIfExists(Table> view);
+ /**
+ * The ALTER VIEW statement.
+ *
+ * @see DSL#alterView(Table, Field...)
+ */
+ @NotNull @CheckReturnValue
+ @Support({ FIREBIRD, H2, MARIADB, MYSQL, POSTGRES, YUGABYTEDB })
+ AlterViewAsStep alterView(Table> view, Field>... fields);
+
+ /**
+ * The ALTER VIEW statement.
+ *
+ * @see DSL#alterView(Table, Collection)
+ */
+ @NotNull @CheckReturnValue
+ @Support({ FIREBIRD, H2, MARIADB, MYSQL, POSTGRES, YUGABYTEDB })
+ AlterViewAsStep alterView(Table> view, Collection extends Field>> fields);
+
/**
* The COMMENT ON TABLE statement.
*
diff --git a/jOOQ/src/main/java/org/jooq/impl/AlterViewImpl.java b/jOOQ/src/main/java/org/jooq/impl/AlterViewImpl.java
index 4f2082587c..67a0c64f0c 100644
--- a/jOOQ/src/main/java/org/jooq/impl/AlterViewImpl.java
+++ b/jOOQ/src/main/java/org/jooq/impl/AlterViewImpl.java
@@ -71,23 +71,27 @@ extends
implements
QOM.AlterView,
AlterViewStep,
+ AlterViewAsStep,
AlterViewFinalStep
{
- final Table> view;
- final boolean ifExists;
- Select> as;
- Comment comment;
- Table> renameTo;
+ final Table> view;
+ final QueryPartListView extends Field>> fields;
+ final boolean ifExists;
+ Comment comment;
+ Table> renameTo;
+ Select> as;
AlterViewImpl(
Configuration configuration,
Table> view,
+ Collection extends Field>> fields,
boolean ifExists
) {
this(
configuration,
view,
+ fields,
ifExists,
null,
null,
@@ -98,30 +102,39 @@ implements
AlterViewImpl(
Configuration configuration,
Table> view,
+ boolean ifExists
+ ) {
+ this(
+ configuration,
+ view,
+ null,
+ ifExists
+ );
+ }
+
+ AlterViewImpl(
+ Configuration configuration,
+ Table> view,
+ Collection extends Field>> fields,
boolean ifExists,
- Select> as,
Comment comment,
- Table> renameTo
+ Table> renameTo,
+ Select> as
) {
super(configuration);
this.view = view;
+ this.fields = new QueryPartList<>(fields);
this.ifExists = ifExists;
- this.as = as;
this.comment = comment;
this.renameTo = renameTo;
+ this.as = as;
}
// -------------------------------------------------------------------------
// XXX: DSL API
// -------------------------------------------------------------------------
- @Override
- public final AlterViewImpl as(Select> as) {
- this.as = as;
- return this;
- }
-
@Override
public final AlterViewImpl comment(String comment) {
return comment(DSL.comment(comment));
@@ -149,6 +162,12 @@ implements
return this;
}
+ @Override
+ public final AlterViewImpl as(Select> as) {
+ this.as = as;
+ return this;
+ }
+
// -------------------------------------------------------------------------
// XXX: QueryPart API
// -------------------------------------------------------------------------
@@ -204,11 +223,16 @@ implements
case POSTGRES:
case SQLITE:
case YUGABYTEDB:
- ctx.visit(begin(dropView(view), createView(view).as(as)));
+ ctx.visit(begin(dropView(view), createView(view, fields.toArray(Tools.EMPTY_FIELD)).as(as)));
break;
default:
- ctx.visit(K_ALTER).sql(' ').visit(K_VIEW).sql(' ').visit(view).sql(' ').visit(K_AS).sql(' ').visit(as);
+ ctx.visit(K_ALTER).sql(' ').visit(K_VIEW).sql(' ').visit(view);
+
+ if (!fields.isEmpty())
+ ctx.sql(" (").visit(QueryPartCollectionView.wrap(fields).qualify(false)).sql(')');
+
+ ctx.formatSeparator().visit(K_AS).formatSeparator().visit(as);
break;
}
@@ -329,13 +353,13 @@ implements
}
@Override
- public final boolean $ifExists() {
- return ifExists;
+ public final UnmodifiableList extends Field>> $fields() {
+ return QOM.unmodifiable(fields);
}
@Override
- public final Select> $as() {
- return as;
+ public final boolean $ifExists() {
+ return ifExists;
}
@Override
@@ -348,35 +372,47 @@ implements
return renameTo;
}
+ @Override
+ public final Select> $as() {
+ return as;
+ }
+
@Override
public final QOM.AlterView $view(Table> newValue) {
- return $constructor().apply(newValue, $ifExists(), $as(), $comment(), $renameTo());
+ return $constructor().apply(newValue, $fields(), $ifExists(), $comment(), $renameTo(), $as());
+ }
+
+ @Override
+ public final QOM.AlterView $fields(Collection extends Field>> newValue) {
+ return $constructor().apply($view(), newValue, $ifExists(), $comment(), $renameTo(), $as());
}
@Override
public final QOM.AlterView $ifExists(boolean newValue) {
- return $constructor().apply($view(), newValue, $as(), $comment(), $renameTo());
- }
-
- @Override
- public final QOM.AlterView $as(Select> newValue) {
- return $constructor().apply($view(), $ifExists(), newValue, $comment(), $renameTo());
+ return $constructor().apply($view(), $fields(), newValue, $comment(), $renameTo(), $as());
}
@Override
public final QOM.AlterView $comment(Comment newValue) {
- return $constructor().apply($view(), $ifExists(), $as(), newValue, $renameTo());
+ return $constructor().apply($view(), $fields(), $ifExists(), newValue, $renameTo(), $as());
}
@Override
public final QOM.AlterView $renameTo(Table> newValue) {
- return $constructor().apply($view(), $ifExists(), $as(), $comment(), newValue);
+ return $constructor().apply($view(), $fields(), $ifExists(), $comment(), newValue, $as());
}
- public final Function5 super Table>, ? super Boolean, ? super Select>, ? super Comment, ? super Table>, ? extends QOM.AlterView> $constructor() {
- return (a1, a2, a3, a4, a5) -> new AlterViewImpl(configuration(), a1, a2, a3, a4, a5);
+ @Override
+ public final QOM.AlterView $as(Select> newValue) {
+ return $constructor().apply($view(), $fields(), $ifExists(), $comment(), $renameTo(), newValue);
}
+ public final Function6 super Table>, ? super Collection extends Field>>, ? super Boolean, ? super Comment, ? super Table>, ? super Select>, ? extends QOM.AlterView> $constructor() {
+ return (a1, a2, a3, a4, a5, a6) -> new AlterViewImpl(configuration(), a1, (Collection extends Field>>) a2, a3, a4, a5, a6);
+ }
+
+
+
diff --git a/jOOQ/src/main/java/org/jooq/impl/DSL.java b/jOOQ/src/main/java/org/jooq/impl/DSL.java
index 94ddcb1298..5f12d4e541 100644
--- a/jOOQ/src/main/java/org/jooq/impl/DSL.java
+++ b/jOOQ/src/main/java/org/jooq/impl/DSL.java
@@ -7700,6 +7700,36 @@ public class DSL {
return dsl().alterViewIfExists(view);
}
+ /**
+ * The ALTER VIEW 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#alterView(Table, Field...)
+ */
+ @NotNull @CheckReturnValue
+ @Support({ FIREBIRD, H2, MARIADB, MYSQL, POSTGRES, YUGABYTEDB })
+ public static org.jooq.AlterViewAsStep alterView(Table> view, Field>... fields) {
+ return dsl().alterView(view, fields);
+ }
+
+ /**
+ * The ALTER VIEW 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#alterView(Table, Collection)
+ */
+ @NotNull @CheckReturnValue
+ @Support({ FIREBIRD, H2, MARIADB, MYSQL, POSTGRES, YUGABYTEDB })
+ public static org.jooq.AlterViewAsStep alterView(Table> view, Collection extends Field>> fields) {
+ return dsl().alterView(view, fields);
+ }
+
/**
* The COMMENT ON TABLE statement.
*
diff --git a/jOOQ/src/main/java/org/jooq/impl/DefaultDSLContext.java b/jOOQ/src/main/java/org/jooq/impl/DefaultDSLContext.java index 2cb454fb97..5edfa957fb 100644 --- a/jOOQ/src/main/java/org/jooq/impl/DefaultDSLContext.java +++ b/jOOQ/src/main/java/org/jooq/impl/DefaultDSLContext.java @@ -3046,32 +3046,42 @@ public class DefaultDSLContext extends AbstractScope implements DSLContext, Seri @Override public org.jooq.AlterViewStep alterView(@Stringly.Name String view) { - return new AlterViewImpl(configuration(), DSL.table(DSL.name(view)), false); + return new AlterViewImpl(configuration(), DSL.table(DSL.name(view)), null, false); } @Override public org.jooq.AlterViewStep alterView(Name view) { - return new AlterViewImpl(configuration(), DSL.table(view), false); + return new AlterViewImpl(configuration(), DSL.table(view), null, false); } @Override public org.jooq.AlterViewStep alterView(Table> view) { - return new AlterViewImpl(configuration(), view, false); + return new AlterViewImpl(configuration(), view, null, false); } @Override public org.jooq.AlterViewStep alterViewIfExists(@Stringly.Name String view) { - return new AlterViewImpl(configuration(), DSL.table(DSL.name(view)), true); + return new AlterViewImpl(configuration(), DSL.table(DSL.name(view)), null, true); } @Override public org.jooq.AlterViewStep alterViewIfExists(Name view) { - return new AlterViewImpl(configuration(), DSL.table(view), true); + return new AlterViewImpl(configuration(), DSL.table(view), null, true); } @Override public org.jooq.AlterViewStep alterViewIfExists(Table> view) { - return new AlterViewImpl(configuration(), view, true); + return new AlterViewImpl(configuration(), view, null, true); + } + + @Override + public org.jooq.AlterViewAsStep alterView(Table> view, Field>... fields) { + return new AlterViewImpl(configuration(), view, Arrays.asList(fields), false); + } + + @Override + public org.jooq.AlterViewAsStep alterView(Table> view, Collection extends Field>> fields) { + return new AlterViewImpl(configuration(), view, new QueryPartList<>(fields), false); } @Override diff --git a/jOOQ/src/main/java/org/jooq/impl/QOM.java b/jOOQ/src/main/java/org/jooq/impl/QOM.java index 49f7aa93ff..889b829337 100644 --- a/jOOQ/src/main/java/org/jooq/impl/QOM.java +++ b/jOOQ/src/main/java/org/jooq/impl/QOM.java @@ -1227,15 +1227,17 @@ public final class QOM { // AlterViewImpl { @NotNull Table> $view(); + @NotNull UnmodifiableList extends Field>> $fields(); boolean $ifExists(); - @Nullable Select> $as(); @Nullable Comment $comment(); @Nullable Table> $renameTo(); + @Nullable Select> $as(); @NotNull AlterView $view(Table> view); + @NotNull AlterView $fields(Collection extends Field>> fields); @NotNull AlterView $ifExists(boolean ifExists); - @NotNull AlterView $as(Select> as); @NotNull AlterView $comment(Comment comment); @NotNull AlterView $renameTo(Table> renameTo); + @NotNull AlterView $as(Select> as); } /**