diff --git a/jOOQ-test/src/test/java/org/jooq/test/_/testcases/DDLTests.java b/jOOQ-test/src/test/java/org/jooq/test/_/testcases/DDLTests.java index 86a1559293..d3d91844cf 100644 --- a/jOOQ-test/src/test/java/org/jooq/test/_/testcases/DDLTests.java +++ b/jOOQ-test/src/test/java/org/jooq/test/_/testcases/DDLTests.java @@ -166,8 +166,7 @@ extends BaseTestALTER ALTER_TABLE statement. + * A complete ALTER TABLE statement. */ ALTER_TABLE, @@ -848,6 +848,22 @@ public enum Clause { */ ALTER_TABLE_DROP, + /** + * A complete DROP TABLE statement. + */ + DROP_TABLE, + + /** + * A TABLE clause within an {@link #DROP_TABLE} statement. + *

+ * This clause surrounds + *

+ */ + DROP_TABLE_TABLE, + // ------------------------------------------------------------------------- // Other clauses // ------------------------------------------------------------------------- diff --git a/jOOQ/src/main/java/org/jooq/DSLContext.java b/jOOQ/src/main/java/org/jooq/DSLContext.java index 7ca5fd8f60..fc8ef4d4a1 100644 --- a/jOOQ/src/main/java/org/jooq/DSLContext.java +++ b/jOOQ/src/main/java/org/jooq/DSLContext.java @@ -4770,7 +4770,7 @@ public interface DSLContext { /** * Create a new DSL ALTER SEQUENCE statement. * - * @see DSL#alterSequence(Sequence) + * @see DSL#alterSequence(String) */ @Support({ FIREBIRD, H2, HSQLDB, POSTGRES }) @Transition( @@ -4794,7 +4794,7 @@ public interface DSLContext { /** * Create a new DSL ALTER TABLE statement. * - * @see DSL#alterTable(Table) + * @see DSL#alterTable(String) */ @Support @Transition( @@ -4803,6 +4803,30 @@ public interface DSLContext { ) AlterTableStep alterTable(String table); + /** + * Create a new DSL DROP TABLE statement. + * + * @see DSL#dropTable(Table) + */ + @Support + @Transition( + name = "DROP TABLE", + args = "Table" + ) + DropTableStep dropTable(Table table); + + /** + * Create a new DSL ALTER TABLE statement. + * + * @see DSL#dropTable(String) + */ + @Support + @Transition( + name = "DROP TABLE", + args = "Table" + ) + DropTableStep dropTable(String table); + /** * Create a new DSL truncate statement. *

diff --git a/jOOQ/src/main/java/org/jooq/DropTableFinalStep.java b/jOOQ/src/main/java/org/jooq/DropTableFinalStep.java new file mode 100644 index 0000000000..1af9c9071e --- /dev/null +++ b/jOOQ/src/main/java/org/jooq/DropTableFinalStep.java @@ -0,0 +1,50 @@ +/** + * Copyright (c) 2009-2014, Data Geekery GmbH (http://www.datageekery.com) + * All rights reserved. + * + * This work is dual-licensed + * - under the Apache Software License 2.0 (the "ASL") + * - under the jOOQ License and Maintenance Agreement (the "jOOQ License") + * ============================================================================= + * You may choose which license applies to you: + * + * - If you're using this work with Open Source databases, you may choose + * either ASL or jOOQ License. + * - If you're using this work with at least one commercial database, you must + * choose jOOQ License + * + * For more information, please visit http://www.jooq.org/licenses + * + * Apache Software License 2.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 + * + * 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. + * + * jOOQ License and Maintenance Agreement: + * ----------------------------------------------------------------------------- + * Data Geekery grants the Customer the non-exclusive, timely limited and + * non-transferable license to install and use the Software under the terms of + * the jOOQ License and Maintenance Agreement. + * + * This library is distributed with a LIMITED WARRANTY. See the jOOQ License + * and Maintenance Agreement for more details: http://www.jooq.org/licensing + */ +package org.jooq; + +/** + * The final step in the DROP TABLE DSL. + * + * @author Lukas Eder + */ +public interface DropTableFinalStep extends Query { + +} diff --git a/jOOQ/src/main/java/org/jooq/DropTableStep.java b/jOOQ/src/main/java/org/jooq/DropTableStep.java new file mode 100644 index 0000000000..839aaf0021 --- /dev/null +++ b/jOOQ/src/main/java/org/jooq/DropTableStep.java @@ -0,0 +1,65 @@ +/** + * Copyright (c) 2009-2014, Data Geekery GmbH (http://www.datageekery.com) + * All rights reserved. + * + * This work is dual-licensed + * - under the Apache Software License 2.0 (the "ASL") + * - under the jOOQ License and Maintenance Agreement (the "jOOQ License") + * ============================================================================= + * You may choose which license applies to you: + * + * - If you're using this work with Open Source databases, you may choose + * either ASL or jOOQ License. + * - If you're using this work with at least one commercial database, you must + * choose jOOQ License + * + * For more information, please visit http://www.jooq.org/licenses + * + * Apache Software License 2.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 + * + * 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. + * + * jOOQ License and Maintenance Agreement: + * ----------------------------------------------------------------------------- + * Data Geekery grants the Customer the non-exclusive, timely limited and + * non-transferable license to install and use the Software under the terms of + * the jOOQ License and Maintenance Agreement. + * + * This library is distributed with a LIMITED WARRANTY. See the jOOQ License + * and Maintenance Agreement for more details: http://www.jooq.org/licensing + */ +package org.jooq; + +import org.jooq.api.annotation.State; + +/** + * The step in the DROP TABLE DSL used to specify DROP + * behaviour. + * + * @author Lukas Eder + */ +@State +public interface DropTableStep extends DropTableFinalStep { + + /** + * Add a CASCADE clause to the DROP TABLE + * statement. + */ + DropTableFinalStep cascade(); + + /** + * Add a RESTRICT clause to the DROP TABLE + * statement. + */ + DropTableFinalStep restrict(); +} diff --git a/jOOQ/src/main/java/org/jooq/impl/AlterTableImpl.java b/jOOQ/src/main/java/org/jooq/impl/AlterTableImpl.java index 9091417553..aeb4998819 100644 --- a/jOOQ/src/main/java/org/jooq/impl/AlterTableImpl.java +++ b/jOOQ/src/main/java/org/jooq/impl/AlterTableImpl.java @@ -65,7 +65,7 @@ import org.jooq.Table; @SuppressWarnings({ "rawtypes", "unchecked" }) class AlterTableImpl extends AbstractQuery implements - // Cascading interface implementations for AlterSequence behaviour + // Cascading interface implementations for ALTER TABLE behaviour AlterTableStep, AlterTableDropStep, AlterTableAlterStep { diff --git a/jOOQ/src/main/java/org/jooq/impl/DSL.java b/jOOQ/src/main/java/org/jooq/impl/DSL.java index ea3f147bdf..8daf89ccc7 100644 --- a/jOOQ/src/main/java/org/jooq/impl/DSL.java +++ b/jOOQ/src/main/java/org/jooq/impl/DSL.java @@ -92,6 +92,7 @@ import org.jooq.DatePart; import org.jooq.Delete; import org.jooq.DeleteWhereStep; import org.jooq.DerivedColumnList; +import org.jooq.DropTableStep; import org.jooq.Field; import org.jooq.GroupConcatOrderByStep; import org.jooq.GroupField; @@ -4383,7 +4384,7 @@ public class DSL { /** * Create a new DSL ALTER SEQUENCE statement. * - * @see DSLContext#alterSequence(Sequence) + * @see DSLContext#alterSequence(String) */ @Support({ FIREBIRD, H2, HSQLDB, POSTGRES }) @Transition( @@ -4397,7 +4398,7 @@ public class DSL { /** * Create a new DSL ALTER TABLE statement. * - * @see DSL#alterTable(Table) + * @see DSLContext#alterTable(Table) */ @Support @Transition( @@ -4411,7 +4412,7 @@ public class DSL { /** * Create a new DSL ALTER TABLE statement. * - * @see DSL#alterTable(Table) + * @see DSLContext#alterTable(String) */ @Support @Transition( @@ -4422,6 +4423,34 @@ public class DSL { return using(new DefaultConfiguration()).alterTable(table); } + /** + * Create a new DSL DROP TABLE statement. + * + * @see DSLContext#dropTable(Table) + */ + @Support + @Transition( + name = "ALTER TABLE", + args = "Table" + ) + public static DropTableStep dropTable(Table table) { + return using(new DefaultConfiguration()).dropTable(table); + } + + /** + * Create a new DSL DROP TABLE statement. + * + * @see DSLContext#dropTable(String) + */ + @Support + @Transition( + name = "ALTER TABLE", + args = "Table" + ) + public static DropTableStep dropTable(String table) { + return using(new DefaultConfiguration()).dropTable(table); + } + /** * Create a new DSL truncate statement. *

diff --git a/jOOQ/src/main/java/org/jooq/impl/DefaultDSLContext.java b/jOOQ/src/main/java/org/jooq/impl/DefaultDSLContext.java index a5c404a15d..10206c3d4e 100644 --- a/jOOQ/src/main/java/org/jooq/impl/DefaultDSLContext.java +++ b/jOOQ/src/main/java/org/jooq/impl/DefaultDSLContext.java @@ -86,6 +86,7 @@ import org.jooq.DSLContext; import org.jooq.DataType; import org.jooq.DeleteQuery; import org.jooq.DeleteWhereStep; +import org.jooq.DropTableStep; import org.jooq.ExecuteContext; import org.jooq.ExecuteListener; import org.jooq.Field; @@ -1576,6 +1577,16 @@ public class DefaultDSLContext implements DSLContext, Serializable { return alterTable(table(table)); } + @Override + public DropTableStep dropTable(Table table) { + return new DropTableImpl(configuration, table); + } + + @Override + public DropTableStep dropTable(String table) { + return dropTable(table(table)); + } + @Override public TruncateIdentityStep truncate(Table table) { return new TruncateImpl(configuration, table); diff --git a/jOOQ/src/main/java/org/jooq/impl/DropTableImpl.java b/jOOQ/src/main/java/org/jooq/impl/DropTableImpl.java new file mode 100644 index 0000000000..9b032eef07 --- /dev/null +++ b/jOOQ/src/main/java/org/jooq/impl/DropTableImpl.java @@ -0,0 +1,114 @@ +/** + * Copyright (c) 2009-2014, Data Geekery GmbH (http://www.datageekery.com) + * All rights reserved. + * + * This work is dual-licensed + * - under the Apache Software License 2.0 (the "ASL") + * - under the jOOQ License and Maintenance Agreement (the "jOOQ License") + * ============================================================================= + * You may choose which license applies to you: + * + * - If you're using this work with Open Source databases, you may choose + * either ASL or jOOQ License. + * - If you're using this work with at least one commercial database, you must + * choose jOOQ License + * + * For more information, please visit http://www.jooq.org/licenses + * + * Apache Software License 2.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 + * + * 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. + * + * jOOQ License and Maintenance Agreement: + * ----------------------------------------------------------------------------- + * Data Geekery grants the Customer the non-exclusive, timely limited and + * non-transferable license to install and use the Software under the terms of + * the jOOQ License and Maintenance Agreement. + * + * This library is distributed with a LIMITED WARRANTY. See the jOOQ License + * and Maintenance Agreement for more details: http://www.jooq.org/licensing + */ +package org.jooq.impl; + +import static org.jooq.Clause.DROP_TABLE; +import static org.jooq.Clause.DROP_TABLE_TABLE; + +import org.jooq.Clause; +import org.jooq.Configuration; +import org.jooq.Context; +import org.jooq.DropTableStep; +import org.jooq.Table; + + +/** + * @author Lukas Eder + */ +class DropTableImpl extends AbstractQuery implements + + // Cascading interface implementations for DROP TABLE behaviour + DropTableStep { + + /** + * Generated UID + */ + private static final long serialVersionUID = 8904572826501186329L; + private static final Clause[] CLAUSES = { DROP_TABLE }; + + private final Table table; + private boolean cascade; + + DropTableImpl(Configuration configuration, Table table) { + super(configuration); + + this.table = table; + } + + // ------------------------------------------------------------------------ + // XXX: DSL API + // ------------------------------------------------------------------------ + + @Override + public final DropTableImpl cascade() { + cascade = true; + return this; + } + + @Override + public final DropTableImpl restrict() { + cascade = false; + return this; + } + + // ------------------------------------------------------------------------ + // XXX: QueryPart API + // ------------------------------------------------------------------------ + + @Override + public final void accept(Context ctx) { + ctx.start(DROP_TABLE_TABLE) + .keyword("drop table").sql(" ") + .visit(table); + + if (cascade) { + ctx.sql(" ").keyword("cascade"); + } + + ctx.end(DROP_TABLE_TABLE); + } + + + @Override + public final Clause[] clauses(Context ctx) { + return CLAUSES; + } +} diff --git a/jOOQ/src/test/java/org/jooq/test/VisitContextTest.java b/jOOQ/src/test/java/org/jooq/test/VisitContextTest.java index 4b1a068299..4e0a8eef21 100644 --- a/jOOQ/src/test/java/org/jooq/test/VisitContextTest.java +++ b/jOOQ/src/test/java/org/jooq/test/VisitContextTest.java @@ -67,6 +67,8 @@ import static org.jooq.Clause.CONDITION_OR; import static org.jooq.Clause.DELETE; import static org.jooq.Clause.DELETE_DELETE; import static org.jooq.Clause.DELETE_WHERE; +import static org.jooq.Clause.DROP_TABLE; +import static org.jooq.Clause.DROP_TABLE_TABLE; import static org.jooq.Clause.FIELD; import static org.jooq.Clause.FIELD_ALIAS; import static org.jooq.Clause.FIELD_REFERENCE; @@ -805,6 +807,17 @@ public class VisitContextTest extends AbstractTest { ctx.alterTable(TABLE1).drop(FIELD_NAME1)); } + @Test + public void test_DROP_TABLE() { + assertEvents(asList( + asList(DROP_TABLE), + asList(DROP_TABLE, DROP_TABLE_TABLE), + asList(DROP_TABLE, DROP_TABLE_TABLE, TABLE), + asList(DROP_TABLE, DROP_TABLE_TABLE, TABLE, TABLE_REFERENCE) + ), + ctx.dropTable(TABLE1)); + } + @Test public void test_CONDITION_simple() { assertEvents(asList(