[#5278] Add support for ALTER SCHEMA [ IF EXISTS ] .. RENAME TO
This commit is contained in:
parent
caaf0fcedc
commit
e87ce6334f
50
jOOQ/src/main/java/org/jooq/AlterSchemaFinalStep.java
Normal file
50
jOOQ/src/main/java/org/jooq/AlterSchemaFinalStep.java
Normal file
@ -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 <code>DROP SCHEMA</code> DSL.
|
||||
*
|
||||
* @author Lukas Eder
|
||||
*/
|
||||
public interface AlterSchemaFinalStep extends DDLQuery {
|
||||
|
||||
}
|
||||
74
jOOQ/src/main/java/org/jooq/AlterSchemaStep.java
Normal file
74
jOOQ/src/main/java/org/jooq/AlterSchemaStep.java
Normal file
@ -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 <code>ALTER SCHEMA</code> DSL used to specify
|
||||
* <code>ALTER</code> behaviour.
|
||||
*
|
||||
* @author Lukas Eder
|
||||
*/
|
||||
public interface AlterSchemaStep extends AlterSchemaFinalStep {
|
||||
|
||||
/**
|
||||
* Add a <code>RENAME TO</code> clause to the <code>ALTER SCHEMA</code>
|
||||
* statement.
|
||||
*/
|
||||
@Support({ POSTGRES })
|
||||
AlterSchemaFinalStep renameTo(Schema newName);
|
||||
|
||||
/**
|
||||
* Add a <code>RENAME TO</code> clause to the <code>ALTER SCHEMA</code>
|
||||
* statement.
|
||||
*/
|
||||
@Support({ POSTGRES })
|
||||
AlterSchemaFinalStep renameTo(Name newName);
|
||||
|
||||
/**
|
||||
* Add a <code>RENAME TO</code> clause to the <code>ALTER SCHEMA</code>
|
||||
* statement.
|
||||
*/
|
||||
@Support({ POSTGRES })
|
||||
AlterSchemaFinalStep renameTo(String newName);
|
||||
|
||||
}
|
||||
@ -1069,6 +1069,33 @@ public enum Clause {
|
||||
*/
|
||||
ALTER_TABLE_DROP,
|
||||
|
||||
/**
|
||||
* A complete <code>ALTER SCHEMA</code> statement.
|
||||
*/
|
||||
ALTER_SCHEMA,
|
||||
|
||||
/**
|
||||
* A <code>SCHEMA</code> clause within an {@link #ALTER_SCHEMA} statement.
|
||||
* <p>
|
||||
* This clause surrounds
|
||||
* <ul>
|
||||
* <li>the <code>ALTER SCHEMA</code> keywords</li>
|
||||
* <li>the schema that is being altered</li>
|
||||
* </ul>
|
||||
*/
|
||||
ALTER_SCHEMA_SCHEMA,
|
||||
|
||||
/**
|
||||
* A <code>RENAME TO</code> clause within an {@link #ALTER_SCHEMA} statement.
|
||||
* <p>
|
||||
* This clause surrounds
|
||||
* <ul>
|
||||
* <li>the <code>RENAME TO</code> keywords</li>
|
||||
* <li>the new schema name</li>
|
||||
* </ul>
|
||||
*/
|
||||
ALTER_SCHEMA_RENAME,
|
||||
|
||||
/**
|
||||
* A complete <code>ALTER VIEW</code> statement.
|
||||
*/
|
||||
|
||||
@ -7329,6 +7329,54 @@ public interface DSLContext extends Scope , AutoCloseable {
|
||||
@Support
|
||||
AlterTableStep alterTableIfExists(Table<?> table);
|
||||
|
||||
/**
|
||||
* Create a new DSL <code>ALTER SCHEMA</code> statement.
|
||||
*
|
||||
* @see DSL#alterSchema(String)
|
||||
*/
|
||||
@Support({ POSTGRES })
|
||||
AlterSchemaStep alterSchema(String schema);
|
||||
|
||||
/**
|
||||
* Create a new DSL <code>ALTER SCHEMA</code> statement.
|
||||
*
|
||||
* @see DSL#alterSchema(Name)
|
||||
*/
|
||||
@Support({ POSTGRES })
|
||||
AlterSchemaStep alterSchema(Name schema);
|
||||
|
||||
/**
|
||||
* Create a new DSL <code>ALTER SCHEMA</code> statement.
|
||||
*
|
||||
* @see DSL#alterSchema(Schema)
|
||||
*/
|
||||
@Support({ POSTGRES })
|
||||
AlterSchemaStep alterSchema(Schema schema);
|
||||
|
||||
/**
|
||||
* Create a new DSL <code>ALTER SCHEMA</code> statement.
|
||||
*
|
||||
* @see DSL#alterSchemaIfExists(String)
|
||||
*/
|
||||
@Support({ POSTGRES })
|
||||
AlterSchemaStep alterSchemaIfExists(String schema);
|
||||
|
||||
/**
|
||||
* Create a new DSL <code>ALTER SCHEMA</code> statement.
|
||||
*
|
||||
* @see DSL#alterSchemaIfExists(Name)
|
||||
*/
|
||||
@Support({ POSTGRES })
|
||||
AlterSchemaStep alterSchemaIfExists(Name schema);
|
||||
|
||||
/**
|
||||
* Create a new DSL <code>ALTER SCHEMA</code> statement.
|
||||
*
|
||||
* @see DSL#alterSchemaIfExists(Schema)
|
||||
*/
|
||||
@Support({ POSTGRES })
|
||||
AlterSchemaStep alterSchemaIfExists(Schema schema);
|
||||
|
||||
/**
|
||||
* Create a new DSL <code>ALTER VIEW</code> statement.
|
||||
*
|
||||
|
||||
138
jOOQ/src/main/java/org/jooq/impl/AlterSchemaImpl.java
Normal file
138
jOOQ/src/main/java/org/jooq/impl/AlterSchemaImpl.java
Normal file
@ -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;
|
||||
}
|
||||
}
|
||||
@ -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 <code>ALTER SCHEMA</code> statement.
|
||||
*
|
||||
* @see DSLContext#alterSchema(String)
|
||||
*/
|
||||
@Support
|
||||
public static AlterSchemaStep alterSchema(String schema) {
|
||||
return using(new DefaultConfiguration()).alterSchema(schema);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new DSL <code>ALTER SCHEMA</code> statement.
|
||||
*
|
||||
* @see DSLContext#alterSchema(Name)
|
||||
*/
|
||||
@Support
|
||||
public static AlterSchemaStep alterSchema(Name schema) {
|
||||
return using(new DefaultConfiguration()).alterSchema(schema);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new DSL <code>ALTER SCHEMA</code> statement.
|
||||
*
|
||||
* @see DSLContext#alterSchema(Schema)
|
||||
*/
|
||||
@Support
|
||||
public static AlterSchemaStep alterSchema(Schema schema) {
|
||||
return using(new DefaultConfiguration()).alterSchema(schema);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new DSL <code>ALTER SCHEMA</code> statement.
|
||||
*
|
||||
* @see DSLContext#alterSchemaIfExists(String)
|
||||
*/
|
||||
@Support
|
||||
public static AlterSchemaStep alterSchemaIfExists(String schema) {
|
||||
return using(new DefaultConfiguration()).alterSchemaIfExists(schema);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new DSL <code>ALTER SCHEMA</code> statement.
|
||||
*
|
||||
* @see DSLContext#alterSchemaIfExists(Name)
|
||||
*/
|
||||
@Support
|
||||
public static AlterSchemaStep alterSchemaIfExists(Name schema) {
|
||||
return using(new DefaultConfiguration()).alterSchemaIfExists(schema);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new DSL <code>ALTER SCHEMA</code> statement.
|
||||
*
|
||||
* @see DSLContext#alterSchemaIfExists(Schema)
|
||||
*/
|
||||
@Support
|
||||
public static AlterSchemaStep alterSchemaIfExists(Schema schema) {
|
||||
return using(new DefaultConfiguration()).alterSchemaIfExists(schema);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new DSL <code>ALTER VIEW</code> statement.
|
||||
*
|
||||
|
||||
@ -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));
|
||||
|
||||
Loading…
Reference in New Issue
Block a user