[jOOQ/jOOQ#9533] Add support for DROP INDEX .. [ CASCADE | RESTRICT ]
This commit is contained in:
parent
70f761117e
commit
efa847cb5f
82
jOOQ/src/main/java/org/jooq/DropIndexCascadeStep.java
Normal file
82
jOOQ/src/main/java/org/jooq/DropIndexCascadeStep.java
Normal file
@ -0,0 +1,82 @@
|
||||
/*
|
||||
* 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.POSTGRES;
|
||||
|
||||
/**
|
||||
* A {@link Query} that can drop indexes.
|
||||
* <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>
|
||||
*
|
||||
* @author Lukas Eder
|
||||
*/
|
||||
public interface DropIndexCascadeStep extends DropIndexFinalStep {
|
||||
|
||||
/**
|
||||
* Add the <code>CASCADE</code> clause to the <code>DROP INDEX</code>
|
||||
* statement.
|
||||
*/
|
||||
@Support({ POSTGRES })
|
||||
DropIndexFinalStep cascade();
|
||||
|
||||
/**
|
||||
* Add the <code>RESTRICT</code> clause to the <code>DROP INDEX</code>
|
||||
* statement.
|
||||
*/
|
||||
@Support({ POSTGRES })
|
||||
DropIndexFinalStep restrict();
|
||||
}
|
||||
@ -85,7 +85,7 @@ import static org.jooq.SQLDialect.SQLITE;
|
||||
*
|
||||
* @author Lukas Eder
|
||||
*/
|
||||
public interface DropIndexOnStep extends DropIndexFinalStep {
|
||||
public interface DropIndexOnStep extends DropIndexCascadeStep {
|
||||
|
||||
/**
|
||||
* Specify the table expression on which to drop an index.
|
||||
@ -98,7 +98,7 @@ public interface DropIndexOnStep extends DropIndexFinalStep {
|
||||
* ignored for compatibility reasons.
|
||||
*/
|
||||
@Support
|
||||
DropIndexFinalStep on(Table<?> table);
|
||||
DropIndexCascadeStep on(Table<?> table);
|
||||
|
||||
/**
|
||||
* Specify the table expression on which to drop an index.
|
||||
@ -111,7 +111,7 @@ public interface DropIndexOnStep extends DropIndexFinalStep {
|
||||
* ignored for compatibility reasons.
|
||||
*/
|
||||
@Support
|
||||
DropIndexFinalStep on(String tableName);
|
||||
DropIndexCascadeStep on(String tableName);
|
||||
|
||||
/**
|
||||
* Specify the table expression on which to drop an index.
|
||||
@ -124,5 +124,5 @@ public interface DropIndexOnStep extends DropIndexFinalStep {
|
||||
* ignored for compatibility reasons.
|
||||
*/
|
||||
@Support
|
||||
DropIndexFinalStep on(Name tableName);
|
||||
DropIndexCascadeStep on(Name tableName);
|
||||
}
|
||||
|
||||
@ -54,9 +54,11 @@ import static org.jooq.SQLDialect.MYSQL;
|
||||
// ...
|
||||
import static org.jooq.impl.DSL.name;
|
||||
import static org.jooq.impl.DSL.table;
|
||||
import static org.jooq.impl.Keywords.K_CASCADE;
|
||||
import static org.jooq.impl.Keywords.K_DROP_INDEX;
|
||||
import static org.jooq.impl.Keywords.K_IF_EXISTS;
|
||||
import static org.jooq.impl.Keywords.K_ON;
|
||||
import static org.jooq.impl.Keywords.K_RESTRICT;
|
||||
import static org.jooq.impl.Tools.beginTryCatch;
|
||||
import static org.jooq.impl.Tools.endTryCatch;
|
||||
|
||||
@ -65,7 +67,6 @@ import java.util.Set;
|
||||
import org.jooq.Clause;
|
||||
import org.jooq.Configuration;
|
||||
import org.jooq.Context;
|
||||
import org.jooq.DropIndexFinalStep;
|
||||
import org.jooq.DropIndexOnStep;
|
||||
import org.jooq.Index;
|
||||
import org.jooq.Name;
|
||||
@ -91,6 +92,7 @@ final class DropIndexImpl extends AbstractRowCountQuery implements
|
||||
private final Index index;
|
||||
private final boolean ifExists;
|
||||
private Table<?> on;
|
||||
private Boolean cascade;
|
||||
|
||||
DropIndexImpl(Configuration configuration, Index index) {
|
||||
this(configuration, index, false);
|
||||
@ -113,21 +115,33 @@ final class DropIndexImpl extends AbstractRowCountQuery implements
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
@Override
|
||||
public final DropIndexFinalStep on(Table<?> table) {
|
||||
public final DropIndexImpl on(Table<?> table) {
|
||||
this.on = table;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final DropIndexFinalStep on(String tableName) {
|
||||
public final DropIndexImpl on(String tableName) {
|
||||
return on(name(tableName));
|
||||
}
|
||||
|
||||
@Override
|
||||
public final DropIndexFinalStep on(Name tableName) {
|
||||
public final DropIndexImpl on(Name tableName) {
|
||||
return on(table(tableName));
|
||||
}
|
||||
|
||||
@Override
|
||||
public final DropIndexImpl cascade() {
|
||||
cascade = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final DropIndexImpl restrict() {
|
||||
cascade = false;
|
||||
return this;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// XXX: QueryPart API
|
||||
// ------------------------------------------------------------------------
|
||||
@ -163,6 +177,9 @@ final class DropIndexImpl extends AbstractRowCountQuery implements
|
||||
|
||||
if (on != null && REQUIRES_ON.contains(ctx.family()))
|
||||
ctx.sql(' ').visit(K_ON).sql(' ').visit(on);
|
||||
|
||||
if (cascade != null)
|
||||
ctx.visit(cascade ? K_CASCADE : K_RESTRICT);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Loading…
Reference in New Issue
Block a user