diff --git a/jOOQ/src/main/java/org/jooq/DropIndexCascadeStep.java b/jOOQ/src/main/java/org/jooq/DropIndexCascadeStep.java new file mode 100644 index 0000000000..d1fb641926 --- /dev/null +++ b/jOOQ/src/main/java/org/jooq/DropIndexCascadeStep.java @@ -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. + *
+ *
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:
+ *
CASCADE clause to the DROP INDEX
+ * statement.
+ */
+ @Support({ POSTGRES })
+ DropIndexFinalStep cascade();
+
+ /**
+ * Add the RESTRICT clause to the DROP INDEX
+ * statement.
+ */
+ @Support({ POSTGRES })
+ DropIndexFinalStep restrict();
+}
diff --git a/jOOQ/src/main/java/org/jooq/DropIndexOnStep.java b/jOOQ/src/main/java/org/jooq/DropIndexOnStep.java
index 512552157e..32dda0d3a1 100644
--- a/jOOQ/src/main/java/org/jooq/DropIndexOnStep.java
+++ b/jOOQ/src/main/java/org/jooq/DropIndexOnStep.java
@@ -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);
}
diff --git a/jOOQ/src/main/java/org/jooq/impl/DropIndexImpl.java b/jOOQ/src/main/java/org/jooq/impl/DropIndexImpl.java
index c3be7992eb..59b0ee4b16 100644
--- a/jOOQ/src/main/java/org/jooq/impl/DropIndexImpl.java
+++ b/jOOQ/src/main/java/org/jooq/impl/DropIndexImpl.java
@@ -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