[jOOQ/jOOQ#14077] Support fields lists (WIP)
This syntax is possible in SQL Server: ALTER VIEW v (x, y) AS SELECT 1, 2 We can support it too. Currently, only a Table<?>, Field<?>... overload is available. The QOM API generator can't generate the other overloads (yet). Will look into that, soon.
This commit is contained in:
parent
5becdccc59
commit
28dd12ac2f
79
jOOQ/src/main/java/org/jooq/AlterViewAsStep.java
Normal file
79
jOOQ/src/main/java/org/jooq/AlterViewAsStep.java
Normal file
@ -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 <code>ALTER VIEW</code> statement.
|
||||
* <p>
|
||||
* <h3>Referencing <code>XYZ*Step</code> types directly from client code</h3>
|
||||
* <p>
|
||||
* It is usually not recommended to reference any <code>XYZ*Step</code> 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: <a href=
|
||||
* "https://www.jooq.org/doc/latest/manual/sql-building/dynamic-sql">https://www.jooq.org/doc/latest/manual/sql-building/dynamic-sql</a>.
|
||||
* <p>
|
||||
* Drawbacks of referencing the <code>XYZ*Step</code> types directly:
|
||||
* <ul>
|
||||
* <li>They're operating on mutable implementations (as of jOOQ 3.x)</li>
|
||||
* <li>They're less composable and not easy to get right when dynamic SQL gets
|
||||
* complex</li>
|
||||
* <li>They're less readable</li>
|
||||
* <li>They might have binary incompatible changes between minor releases</li>
|
||||
* </ul>
|
||||
*/
|
||||
@SuppressWarnings({ "unused" })
|
||||
public interface AlterViewAsStep {
|
||||
|
||||
/**
|
||||
* Add the <code>AS</code> clause to the <code>ALTER VIEW</code> statement.
|
||||
*/
|
||||
@Support({ FIREBIRD, H2, MARIADB, MYSQL, POSTGRES, YUGABYTEDB })
|
||||
@NotNull @CheckReturnValue
|
||||
AlterViewFinalStep as(Select<?> as);
|
||||
}
|
||||
@ -68,14 +68,7 @@ import org.jetbrains.annotations.*;
|
||||
* </ul>
|
||||
*/
|
||||
@SuppressWarnings({ "unused" })
|
||||
public interface AlterViewStep {
|
||||
|
||||
/**
|
||||
* Add the <code>AS</code> clause to the <code>ALTER VIEW</code> statement.
|
||||
*/
|
||||
@Support({ FIREBIRD, H2, MARIADB, MYSQL, POSTGRES, YUGABYTEDB })
|
||||
@NotNull @CheckReturnValue
|
||||
AlterViewFinalStep as(Select<?> as);
|
||||
public interface AlterViewStep extends AlterViewAsStep {
|
||||
|
||||
/**
|
||||
* Add the <code>COMMENT</code> clause to the <code>ALTER VIEW</code> statement.
|
||||
|
||||
@ -9666,6 +9666,24 @@ public interface DSLContext extends Scope {
|
||||
@Support({ H2, POSTGRES, YUGABYTEDB })
|
||||
AlterViewStep alterViewIfExists(Table<?> view);
|
||||
|
||||
/**
|
||||
* The <code>ALTER VIEW</code> statement.
|
||||
*
|
||||
* @see DSL#alterView(Table, Field...)
|
||||
*/
|
||||
@NotNull @CheckReturnValue
|
||||
@Support({ FIREBIRD, H2, MARIADB, MYSQL, POSTGRES, YUGABYTEDB })
|
||||
AlterViewAsStep alterView(Table<?> view, Field<?>... fields);
|
||||
|
||||
/**
|
||||
* The <code>ALTER VIEW</code> statement.
|
||||
*
|
||||
* @see DSL#alterView(Table, Collection)
|
||||
*/
|
||||
@NotNull @CheckReturnValue
|
||||
@Support({ FIREBIRD, H2, MARIADB, MYSQL, POSTGRES, YUGABYTEDB })
|
||||
AlterViewAsStep alterView(Table<?> view, Collection<? extends Field<?>> fields);
|
||||
|
||||
/**
|
||||
* The <code>COMMENT ON TABLE</code> statement.
|
||||
*
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -7700,6 +7700,36 @@ public class DSL {
|
||||
return dsl().alterViewIfExists(view);
|
||||
}
|
||||
|
||||
/**
|
||||
* The <code>ALTER VIEW</code> statement.
|
||||
* <p>
|
||||
* 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 <code>ALTER VIEW</code> statement.
|
||||
* <p>
|
||||
* 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 <code>COMMENT ON TABLE</code> statement.
|
||||
* <p>
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Loading…
Reference in New Issue
Block a user