From 0884090495b314e72d400ffb8fdd92809b87e0ab Mon Sep 17 00:00:00 2001 From: Lukas Eder Date: Fri, 17 Aug 2018 15:01:40 +0200 Subject: [PATCH] [#7774] Add support for DROP TYPE --- .../main/java/org/jooq/DropTypeFinalStep.java | 65 ++++++++++ jOOQ/src/main/java/org/jooq/DropTypeStep.java | 79 ++++++++++++ .../main/java/org/jooq/impl/DropTypeImpl.java | 115 ++++++++++++++++++ 3 files changed, 259 insertions(+) create mode 100644 jOOQ/src/main/java/org/jooq/DropTypeFinalStep.java create mode 100644 jOOQ/src/main/java/org/jooq/DropTypeStep.java create mode 100644 jOOQ/src/main/java/org/jooq/impl/DropTypeImpl.java diff --git a/jOOQ/src/main/java/org/jooq/DropTypeFinalStep.java b/jOOQ/src/main/java/org/jooq/DropTypeFinalStep.java new file mode 100644 index 0000000000..5de902bb30 --- /dev/null +++ b/jOOQ/src/main/java/org/jooq/DropTypeFinalStep.java @@ -0,0 +1,65 @@ +/* + * 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; + +/** + * A {@link Query} that can drop types. + *

+ *

Referencing 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: + *

+ * + * @author Lukas Eder + */ +public interface DropTypeFinalStep extends DDLQuery { + +} diff --git a/jOOQ/src/main/java/org/jooq/DropTypeStep.java b/jOOQ/src/main/java/org/jooq/DropTypeStep.java new file mode 100644 index 0000000000..e8c784bd1e --- /dev/null +++ b/jOOQ/src/main/java/org/jooq/DropTypeStep.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.H2; +import static org.jooq.SQLDialect.POSTGRES; + +/** + * A {@link Query} that can drop types. + *

+ *

Referencing 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: + *

+ * + * @author Lukas Eder + */ +public interface DropTypeStep extends DropTypeFinalStep { + + /** + * Add the CASCADE clause to the DROP TYPE statement. + */ + @Support({ H2, POSTGRES }) + DropTypeFinalStep cascade(); + + /** + * Add the RESTRICT clause to the DROP TYPE statement. + */ + @Support({ H2, POSTGRES }) + DropTypeFinalStep restrict(); +} diff --git a/jOOQ/src/main/java/org/jooq/impl/DropTypeImpl.java b/jOOQ/src/main/java/org/jooq/impl/DropTypeImpl.java new file mode 100644 index 0000000000..472540ffa7 --- /dev/null +++ b/jOOQ/src/main/java/org/jooq/impl/DropTypeImpl.java @@ -0,0 +1,115 @@ +/* + * 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.impl; + +import static org.jooq.impl.Keywords.K_CASCADE; +import static org.jooq.impl.Keywords.K_DROP; +import static org.jooq.impl.Keywords.K_IF_EXISTS; +import static org.jooq.impl.Keywords.K_RESTRICT; +import static org.jooq.impl.Keywords.K_TYPE; + +import java.util.Collection; + +import org.jooq.Clause; +import org.jooq.Configuration; +import org.jooq.Context; +import org.jooq.DropTypeFinalStep; +import org.jooq.DropTypeStep; +import org.jooq.Name; + +/** + * @author Lukas Eder + */ +final class DropTypeImpl extends AbstractQuery implements + + // Cascading interface implementations for CREATE TYPE behaviour + DropTypeStep { + + private static final long serialVersionUID = -5018375056147329888L; + private final QueryPartList type; + private final boolean ifExists; + private boolean cascade; + private boolean restrict; + + DropTypeImpl(Configuration configuration, Collection type, boolean ifExists) { + super(configuration); + + this.type = new QueryPartList(Tools.names(type)); + this.ifExists = ifExists; + } + + // ------------------------------------------------------------------------ + // XXX: DSL API + // ------------------------------------------------------------------------ + + @Override + public final DropTypeFinalStep cascade() { + this.cascade = true; + return this; + } + + @Override + public final DropTypeFinalStep restrict() { + this.restrict = true; + return this; + } + + // ------------------------------------------------------------------------ + // XXX: QueryPart API + // ------------------------------------------------------------------------ + + @Override + public final void accept(Context ctx) { + ctx.visit(K_DROP).sql(' ').visit(K_TYPE); + + if (ifExists) + ctx.sql(' ').visit(K_IF_EXISTS); + + ctx.sql(' ').visit(type); + + if (cascade) + ctx.sql(' ').visit(K_CASCADE); + else if (restrict) + ctx.sql(' ').visit(K_RESTRICT); + } + + @Override + public final Clause[] clauses(Context ctx) { + return null; + } +}