diff --git a/jOOQ/src/main/java/org/jooq/AlterSchemaFinalStep.java b/jOOQ/src/main/java/org/jooq/AlterSchemaFinalStep.java new file mode 100644 index 0000000000..a3bb1b97bd --- /dev/null +++ b/jOOQ/src/main/java/org/jooq/AlterSchemaFinalStep.java @@ -0,0 +1,50 @@ +/** + * Copyright (c) 2009-2016, Data Geekery GmbH (http://www.datageekery.com) + * All rights reserved. + * + * 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; + +/** + * The final step in the DROP SCHEMA DSL. + * + * @author Lukas Eder + */ +public interface AlterSchemaFinalStep extends DDLQuery { + +} diff --git a/jOOQ/src/main/java/org/jooq/AlterSchemaStep.java b/jOOQ/src/main/java/org/jooq/AlterSchemaStep.java new file mode 100644 index 0000000000..29a50e9d51 --- /dev/null +++ b/jOOQ/src/main/java/org/jooq/AlterSchemaStep.java @@ -0,0 +1,74 @@ +/** + * Copyright (c) 2009-2016, Data Geekery GmbH (http://www.datageekery.com) + * All rights reserved. + * + * 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; + +/** + * The step in the ALTER SCHEMA DSL used to specify + * ALTER behaviour. + * + * @author Lukas Eder + */ +public interface AlterSchemaStep extends AlterSchemaFinalStep { + + /** + * Add a RENAME TO clause to the ALTER SCHEMA + * statement. + */ + @Support({ POSTGRES }) + AlterSchemaFinalStep renameTo(Schema newName); + + /** + * Add a RENAME TO clause to the ALTER SCHEMA + * statement. + */ + @Support({ POSTGRES }) + AlterSchemaFinalStep renameTo(Name newName); + + /** + * Add a RENAME TO clause to the ALTER SCHEMA + * statement. + */ + @Support({ POSTGRES }) + AlterSchemaFinalStep renameTo(String newName); + +} diff --git a/jOOQ/src/main/java/org/jooq/Clause.java b/jOOQ/src/main/java/org/jooq/Clause.java index 05a4aa4a3b..aec6005ae1 100644 --- a/jOOQ/src/main/java/org/jooq/Clause.java +++ b/jOOQ/src/main/java/org/jooq/Clause.java @@ -1069,6 +1069,33 @@ public enum Clause { */ ALTER_TABLE_DROP, + /** + * A complete ALTER SCHEMA statement. + */ + ALTER_SCHEMA, + + /** + * A SCHEMA clause within an {@link #ALTER_SCHEMA} statement. + *

+ * This clause surrounds + *

+ */ + ALTER_SCHEMA_SCHEMA, + + /** + * A RENAME TO clause within an {@link #ALTER_SCHEMA} statement. + *

+ * This clause surrounds + *

+ */ + ALTER_SCHEMA_RENAME, + /** * A complete ALTER VIEW statement. */ diff --git a/jOOQ/src/main/java/org/jooq/DSLContext.java b/jOOQ/src/main/java/org/jooq/DSLContext.java index bb4ee98ca9..75b3ffe00b 100644 --- a/jOOQ/src/main/java/org/jooq/DSLContext.java +++ b/jOOQ/src/main/java/org/jooq/DSLContext.java @@ -7329,6 +7329,54 @@ public interface DSLContext extends Scope , AutoCloseable { @Support AlterTableStep alterTableIfExists(Table table); + /** + * Create a new DSL ALTER SCHEMA statement. + * + * @see DSL#alterSchema(String) + */ + @Support({ POSTGRES }) + AlterSchemaStep alterSchema(String schema); + + /** + * Create a new DSL ALTER SCHEMA statement. + * + * @see DSL#alterSchema(Name) + */ + @Support({ POSTGRES }) + AlterSchemaStep alterSchema(Name schema); + + /** + * Create a new DSL ALTER SCHEMA statement. + * + * @see DSL#alterSchema(Schema) + */ + @Support({ POSTGRES }) + AlterSchemaStep alterSchema(Schema schema); + + /** + * Create a new DSL ALTER SCHEMA statement. + * + * @see DSL#alterSchemaIfExists(String) + */ + @Support({ POSTGRES }) + AlterSchemaStep alterSchemaIfExists(String schema); + + /** + * Create a new DSL ALTER SCHEMA statement. + * + * @see DSL#alterSchemaIfExists(Name) + */ + @Support({ POSTGRES }) + AlterSchemaStep alterSchemaIfExists(Name schema); + + /** + * Create a new DSL ALTER SCHEMA statement. + * + * @see DSL#alterSchemaIfExists(Schema) + */ + @Support({ POSTGRES }) + AlterSchemaStep alterSchemaIfExists(Schema schema); + /** * Create a new DSL ALTER VIEW statement. * diff --git a/jOOQ/src/main/java/org/jooq/impl/AlterSchemaImpl.java b/jOOQ/src/main/java/org/jooq/impl/AlterSchemaImpl.java new file mode 100644 index 0000000000..35906c17b2 --- /dev/null +++ b/jOOQ/src/main/java/org/jooq/impl/AlterSchemaImpl.java @@ -0,0 +1,138 @@ +/** + * Copyright (c) 2009-2016, Data Geekery GmbH (http://www.datageekery.com) + * All rights reserved. + * + * 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.Clause.ALTER_SCHEMA; +import static org.jooq.Clause.ALTER_SCHEMA_RENAME; +import static org.jooq.Clause.ALTER_SCHEMA_SCHEMA; +import static org.jooq.impl.DSL.name; + +import org.jooq.AlterSchemaStep; +import org.jooq.Clause; +import org.jooq.Configuration; +import org.jooq.Context; +import org.jooq.Name; +import org.jooq.Schema; + +/** + * @author Lukas Eder + */ +final class AlterSchemaImpl extends AbstractQuery implements + + // Cascading interface implementations for ALTER SCHEMA behaviour + AlterSchemaStep { + + /** + * Generated UID + */ + private static final long serialVersionUID = 8904572826501186329L; + private static final Clause[] CLAUSES = { ALTER_SCHEMA }; + + private final Schema schema; + private final boolean ifExists; + private Schema renameTo; + + AlterSchemaImpl(Configuration configuration, Schema schema) { + this(configuration, schema, false); + } + + AlterSchemaImpl(Configuration configuration, Schema schema, boolean ifExists) { + super(configuration); + + this.schema = schema; + this.ifExists = ifExists; + } + + // ------------------------------------------------------------------------ + // XXX: DSL API + // ------------------------------------------------------------------------ + + @Override + public final AlterSchemaImpl renameTo(Schema newName) { + this.renameTo = newName; + return this; + } + + @Override + public final AlterSchemaImpl renameTo(Name newName) { + return renameTo(DSL.schema(newName)); + } + + @Override + public final AlterSchemaImpl renameTo(String newName) { + return renameTo(name(newName)); + } + + // ------------------------------------------------------------------------ + // XXX: QueryPart API + // ------------------------------------------------------------------------ + + @Override + public final void accept(Context ctx) { + ctx.start(ALTER_SCHEMA_SCHEMA) + .keyword("alter schema"); + + if (ifExists) + ctx.sql(' ').keyword("if exists"); + + ctx.sql(' ').visit(schema) + .end(ALTER_SCHEMA_SCHEMA) + .formatIndentStart() + .formatSeparator(); + + if (renameTo != null) { + boolean qualify = ctx.qualify(); + + ctx.start(ALTER_SCHEMA_RENAME) + .qualify(false) + .keyword("rename to").sql(' ').visit(renameTo) + .qualify(qualify) + .end(ALTER_SCHEMA_RENAME); + } + + ctx.formatIndentEnd(); + } + + @Override + public final Clause[] clauses(Context ctx) { + return CLAUSES; + } +} diff --git a/jOOQ/src/main/java/org/jooq/impl/DSL.java b/jOOQ/src/main/java/org/jooq/impl/DSL.java index fe118df8c1..66b6239c51 100644 --- a/jOOQ/src/main/java/org/jooq/impl/DSL.java +++ b/jOOQ/src/main/java/org/jooq/impl/DSL.java @@ -100,6 +100,7 @@ import javax.sql.DataSource; import org.jooq.AggregateFunction; import org.jooq.AlterIndexStep; +import org.jooq.AlterSchemaStep; import org.jooq.AlterSequenceStep; import org.jooq.AlterTableStep; import org.jooq.AlterViewStep; @@ -5300,6 +5301,66 @@ public class DSL { return using(new DefaultConfiguration()).alterTableIfExists(table); } + /** + * Create a new DSL ALTER SCHEMA statement. + * + * @see DSLContext#alterSchema(String) + */ + @Support + public static AlterSchemaStep alterSchema(String schema) { + return using(new DefaultConfiguration()).alterSchema(schema); + } + + /** + * Create a new DSL ALTER SCHEMA statement. + * + * @see DSLContext#alterSchema(Name) + */ + @Support + public static AlterSchemaStep alterSchema(Name schema) { + return using(new DefaultConfiguration()).alterSchema(schema); + } + + /** + * Create a new DSL ALTER SCHEMA statement. + * + * @see DSLContext#alterSchema(Schema) + */ + @Support + public static AlterSchemaStep alterSchema(Schema schema) { + return using(new DefaultConfiguration()).alterSchema(schema); + } + + /** + * Create a new DSL ALTER SCHEMA statement. + * + * @see DSLContext#alterSchemaIfExists(String) + */ + @Support + public static AlterSchemaStep alterSchemaIfExists(String schema) { + return using(new DefaultConfiguration()).alterSchemaIfExists(schema); + } + + /** + * Create a new DSL ALTER SCHEMA statement. + * + * @see DSLContext#alterSchemaIfExists(Name) + */ + @Support + public static AlterSchemaStep alterSchemaIfExists(Name schema) { + return using(new DefaultConfiguration()).alterSchemaIfExists(schema); + } + + /** + * Create a new DSL ALTER SCHEMA statement. + * + * @see DSLContext#alterSchemaIfExists(Schema) + */ + @Support + public static AlterSchemaStep alterSchemaIfExists(Schema schema) { + return using(new DefaultConfiguration()).alterSchemaIfExists(schema); + } + /** * Create a new DSL ALTER VIEW statement. * diff --git a/jOOQ/src/main/java/org/jooq/impl/DefaultDSLContext.java b/jOOQ/src/main/java/org/jooq/impl/DefaultDSLContext.java index b747b71a8d..f0cceb539b 100644 --- a/jOOQ/src/main/java/org/jooq/impl/DefaultDSLContext.java +++ b/jOOQ/src/main/java/org/jooq/impl/DefaultDSLContext.java @@ -81,6 +81,7 @@ import javax.annotation.Generated; import javax.sql.DataSource; import org.jooq.AlterIndexStep; +import org.jooq.AlterSchemaStep; import org.jooq.AlterSequenceStep; import org.jooq.AlterTableStep; import org.jooq.AlterViewStep; @@ -2604,6 +2605,36 @@ public class DefaultDSLContext extends AbstractScope implements DSLContext, Seri return new AlterTableImpl(configuration(), table, true); } + @Override + public AlterSchemaStep alterSchema(String schema) { + return alterSchema(name(schema)); + } + + @Override + public AlterSchemaStep alterSchema(Name schema) { + return alterSchema(schema(schema)); + } + + @Override + public AlterSchemaStep alterSchema(Schema schema) { + return new AlterSchemaImpl(configuration(), schema); + } + + @Override + public AlterSchemaStep alterSchemaIfExists(String schema) { + return alterSchemaIfExists(name(schema)); + } + + @Override + public AlterSchemaStep alterSchemaIfExists(Name schema) { + return alterSchemaIfExists(schema(schema)); + } + + @Override + public AlterSchemaStep alterSchemaIfExists(Schema schema) { + return new AlterSchemaImpl(configuration(), schema, true); + } + @Override public AlterViewStep alterView(String table) { return alterView(name(table));