[jOOQ/jOOQ#14077] Add parser support
This commit is contained in:
parent
2f91c57b81
commit
8f5399bc82
@ -1,79 +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
|
||||
*
|
||||
* https://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: https://www.jooq.org/legal/licensing
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
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,7 +68,7 @@ import org.jetbrains.annotations.*;
|
||||
* </ul>
|
||||
*/
|
||||
@SuppressWarnings({ "unused" })
|
||||
public interface AlterViewStep extends AlterViewAsStep {
|
||||
public interface AlterViewStep {
|
||||
|
||||
/**
|
||||
* Add the <code>COMMENT</code> clause to the <code>ALTER VIEW</code> statement.
|
||||
@ -104,4 +104,11 @@ public interface AlterViewStep extends AlterViewAsStep {
|
||||
@Support({ H2, HSQLDB, POSTGRES, YUGABYTEDB })
|
||||
@NotNull @CheckReturnValue
|
||||
AlterViewFinalStep renameTo(Table<?> renameTo);
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
|
||||
@ -9633,7 +9633,7 @@ public interface DSLContext extends Scope {
|
||||
*/
|
||||
@NotNull @CheckReturnValue
|
||||
@Support({ FIREBIRD, H2, MARIADB, MYSQL, POSTGRES, YUGABYTEDB })
|
||||
AlterViewAsStep alterView(Table<?> view, Field<?>... fields);
|
||||
AlterViewStep alterView(Table<?> view, Field<?>... fields);
|
||||
|
||||
/**
|
||||
* The <code>ALTER VIEW</code> statement.
|
||||
@ -9642,7 +9642,7 @@ public interface DSLContext extends Scope {
|
||||
*/
|
||||
@NotNull @CheckReturnValue
|
||||
@Support({ FIREBIRD, H2, MARIADB, MYSQL, POSTGRES, YUGABYTEDB })
|
||||
AlterViewAsStep alterView(Table<?> view, Collection<? extends Field<?>> fields);
|
||||
AlterViewStep alterView(Table<?> view, Collection<? extends Field<?>> fields);
|
||||
|
||||
/**
|
||||
* The <code>COMMENT ON TABLE</code> statement.
|
||||
|
||||
@ -71,7 +71,6 @@ extends
|
||||
implements
|
||||
QOM.AlterView,
|
||||
AlterViewStep,
|
||||
AlterViewAsStep,
|
||||
AlterViewFinalStep
|
||||
{
|
||||
|
||||
|
||||
@ -7714,7 +7714,7 @@ public class DSL {
|
||||
*/
|
||||
@NotNull @CheckReturnValue
|
||||
@Support({ FIREBIRD, H2, MARIADB, MYSQL, POSTGRES, YUGABYTEDB })
|
||||
public static org.jooq.AlterViewAsStep alterView(Table<?> view, Field<?>... fields) {
|
||||
public static org.jooq.AlterViewStep alterView(Table<?> view, Field<?>... fields) {
|
||||
return dsl().alterView(view, fields);
|
||||
}
|
||||
|
||||
@ -7729,7 +7729,7 @@ public class DSL {
|
||||
*/
|
||||
@NotNull @CheckReturnValue
|
||||
@Support({ FIREBIRD, H2, MARIADB, MYSQL, POSTGRES, YUGABYTEDB })
|
||||
public static org.jooq.AlterViewAsStep alterView(Table<?> view, Collection<? extends Field<?>> fields) {
|
||||
public static org.jooq.AlterViewStep alterView(Table<?> view, Collection<? extends Field<?>> fields) {
|
||||
return dsl().alterView(view, fields);
|
||||
}
|
||||
|
||||
|
||||
@ -3054,12 +3054,12 @@ public class DefaultDSLContext extends AbstractScope implements DSLContext, Seri
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.jooq.AlterViewAsStep alterView(Table<?> view, Field<?>... fields) {
|
||||
public org.jooq.AlterViewStep 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) {
|
||||
public org.jooq.AlterViewStep alterView(Table<?> view, Collection<? extends Field<?>> fields) {
|
||||
return new AlterViewImpl(configuration(), view, new QueryPartList<>(fields), false);
|
||||
}
|
||||
|
||||
|
||||
@ -4219,8 +4219,28 @@ final class DefaultParseContext extends AbstractScope implements ParseContext {
|
||||
private final DDLQuery parseAlterView() {
|
||||
boolean ifExists = parseKeywordIf("IF EXISTS");
|
||||
Table<?> oldName = parseTableName();
|
||||
Field<?>[] fields = EMPTY_FIELD;
|
||||
|
||||
if (parseKeywordIf("RENAME")) {
|
||||
if (parseIf('(')) {
|
||||
fields = parseList(',', c -> parseFieldName()).toArray(fields);
|
||||
parse(')');
|
||||
}
|
||||
|
||||
if (parseKeywordIf("AS")) {
|
||||
Select<?> select = parseWithOrSelect();
|
||||
int degree = Tools.degree(select);
|
||||
|
||||
if (fields.length > 0 && fields.length != degree)
|
||||
throw exception("Select list size (" + degree + ") must match declared field size (" + fields.length + ")");
|
||||
|
||||
if (fields.length == 0)
|
||||
return dsl.alterView(oldName).as(select);
|
||||
else
|
||||
return dsl.alterView(oldName, fields).as(select);
|
||||
}
|
||||
else if (fields.length > 0)
|
||||
throw expected("AS");
|
||||
else if (parseKeywordIf("RENAME")) {
|
||||
parseKeyword("AS", "TO");
|
||||
Table<?> newName = parseTableName();
|
||||
|
||||
@ -4233,7 +4253,7 @@ final class DefaultParseContext extends AbstractScope implements ParseContext {
|
||||
else if (parseKeywordIf("SET"))
|
||||
return dsl.alterView(oldName).comment(parseOptionsDescription());
|
||||
else
|
||||
throw expected("OWNER TO", "RENAME", "SET");
|
||||
throw expected("AS", "OWNER TO", "RENAME", "SET");
|
||||
}
|
||||
|
||||
private final Comment parseOptionsDescription() {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user