[#5085] Add support for ALTER INDEX .. RENAME TO ..

This commit is contained in:
lukaseder 2016-05-16 09:13:18 +02:00
parent f7b78093b1
commit 822ceedccf
9 changed files with 318 additions and 4 deletions

View File

@ -0,0 +1,51 @@
/**
* 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>ALTER INDEX</code> DSL.
*
* @author Lukas Eder
*/
public interface AlterIndexFinalStep extends DDLQuery {
}

View File

@ -0,0 +1,65 @@
/**
* 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 INDEX</code> where the action can be decided.
*
* @author Lukas Eder
*/
public interface AlterIndexStep {
/**
* Add a <code>RENAME TO</code> clause to the <code>ALTER INDEX</code>
* statement.
*/
@Support({ POSTGRES })
AlterIndexFinalStep renameTo(Name newName);
/**
* Add a <code>RENAME TO</code> clause to the <code>ALTER INDEX</code>
* statement.
*/
@Support({ POSTGRES })
AlterIndexFinalStep renameTo(String newName);
}

View File

@ -50,21 +50,21 @@ import static org.jooq.SQLDialect.POSTGRES;
public interface AlterViewStep {
/**
* Add a <code>RENAME TO</code> clause to the <code>ALTER TABLE</code>
* Add a <code>RENAME TO</code> clause to the <code>ALTER VIEW</code>
* statement.
*/
@Support({ POSTGRES })
AlterViewFinalStep renameTo(Table<?> newName);
/**
* Add a <code>RENAME TO</code> clause to the <code>ALTER TABLE</code>
* Add a <code>RENAME TO</code> clause to the <code>ALTER VIEW</code>
* statement.
*/
@Support({ POSTGRES })
AlterViewFinalStep renameTo(Name newName);
/**
* Add a <code>RENAME TO</code> clause to the <code>ALTER TABLE</code>
* Add a <code>RENAME TO</code> clause to the <code>ALTER VIEW</code>
* statement.
*/
@Support({ POSTGRES })

View File

@ -1081,6 +1081,33 @@ public enum Clause {
*/
ALTER_VIEW_RENAME,
/**
* A complete <code>ALTER INDEX</code> statement.
*/
ALTER_INDEX,
/**
* An <code>INDEX</code> clause within an {@link #ALTER_INDEX} statement.
* <p>
* This clause surrounds
* <ul>
* <li>the <code>ALTER INDEX</code> keywords</li>
* <li>the index that is being altered</li>
* </ul>
*/
ALTER_INDEX_INDEX,
/**
* A <code>RENAME TO</code> clause within an {@link #ALTER_INDEX} statement.
* <p>
* This clause surrounds
* <ul>
* <li>the <code>RENAME TO</code> keywords</li>
* <li>the new index name</li>
* </ul>
*/
ALTER_INDEX_RENAME,
/**
* A complete <code>DROP VIEW</code> statement.
*/

View File

@ -7257,6 +7257,22 @@ public interface DSLContext extends Scope , AutoCloseable {
@Support
AlterViewStep alterView(Table<?> view);
/**
* Create a new DSL <code>ALTER INDEX</code> statement.
*
* @see DSL#alterIndex(String)
*/
@Support
AlterIndexStep alterIndex(String index);
/**
* Create a new DSL <code>ALTER INDEX</code> statement.
*
* @see DSL#alterIndex(Name)
*/
@Support
AlterIndexStep alterIndex(Name index);
/**
* Create a new DSL <code>DROP VIEW</code> statement.
*

View File

@ -0,0 +1,123 @@
/**
* 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_INDEX;
import static org.jooq.Clause.ALTER_INDEX_INDEX;
import static org.jooq.Clause.ALTER_INDEX_RENAME;
import static org.jooq.impl.DSL.name;
import org.jooq.AlterIndexFinalStep;
import org.jooq.AlterIndexStep;
import org.jooq.Clause;
import org.jooq.Configuration;
import org.jooq.Context;
import org.jooq.Name;
/**
* @author Lukas Eder
*/
final class AlterIndexImpl extends AbstractQuery implements
// Cascading interface implementations for ALTER INDEX behaviour
AlterIndexStep,
AlterIndexFinalStep {
/**
* Generated UID
*/
private static final long serialVersionUID = 8904572826501186329L;
private static final Clause[] CLAUSES = { ALTER_INDEX };
private final Name index;
private Name renameTo;
AlterIndexImpl(Configuration configuration, Name index) {
super(configuration);
this.index = index;
}
// ------------------------------------------------------------------------
// XXX: DSL API
// ------------------------------------------------------------------------
@Override
public final AlterIndexImpl renameTo(Name newName) {
this.renameTo = newName;
return this;
}
@Override
public final AlterIndexImpl renameTo(String newName) {
return renameTo(name(newName));
}
// ------------------------------------------------------------------------
// XXX: QueryPart API
// ------------------------------------------------------------------------
@Override
public final void accept(Context<?> ctx) {
ctx.start(ALTER_INDEX_INDEX)
.keyword("alter index").sql(' ').visit(index)
.end(ALTER_INDEX_INDEX)
.formatIndentStart()
.formatSeparator();
if (renameTo != null) {
boolean qualify = ctx.qualify();
ctx.start(ALTER_INDEX_RENAME)
.qualify(false)
.keyword("rename to").sql(' ').visit(renameTo)
.qualify(qualify)
.end(ALTER_INDEX_RENAME);
}
ctx.formatIndentEnd();
}
@Override
public final Clause[] clauses(Context<?> ctx) {
return CLAUSES;
}
}

View File

@ -58,7 +58,7 @@ import org.jooq.Table;
*/
final class AlterViewImpl extends AbstractQuery implements
// Cascading interface implementations for ALTER TABLE behaviour
// Cascading interface implementations for ALTER VIEW behaviour
AlterViewStep,
AlterViewFinalStep {

View File

@ -99,6 +99,7 @@ import javax.annotation.Generated;
import javax.sql.DataSource;
import org.jooq.AggregateFunction;
import org.jooq.AlterIndexStep;
import org.jooq.AlterSequenceStep;
import org.jooq.AlterTableStep;
import org.jooq.AlterViewStep;
@ -5206,6 +5207,26 @@ public class DSL {
return using(new DefaultConfiguration()).alterView(view);
}
/**
* Create a new DSL <code>ALTER INDEX</code> statement.
*
* @see DSLContext#alterIndex(String)
*/
@Support
public static AlterIndexStep alterIndex(String index) {
return using(new DefaultConfiguration()).alterIndex(index);
}
/**
* Create a new DSL <code>ALTER INDEX</code> statement.
*
* @see DSLContext#alterIndex(Name)
*/
@Support
public static AlterIndexStep alterIndex(Name index) {
return using(new DefaultConfiguration()).alterIndex(index);
}
/**
* Create a new DSL <code>DROP VIEW</code> statement.
*

View File

@ -79,6 +79,7 @@ import java.util.stream.Stream;
import javax.annotation.Generated;
import javax.sql.DataSource;
import org.jooq.AlterIndexStep;
import org.jooq.AlterSequenceStep;
import org.jooq.AlterTableStep;
import org.jooq.AlterViewStep;
@ -2555,6 +2556,16 @@ public class DefaultDSLContext extends AbstractScope implements DSLContext, Seri
return new AlterViewImpl(configuration(), table);
}
@Override
public AlterIndexStep alterIndex(String index) {
return alterIndex(name(index));
}
@Override
public AlterIndexStep alterIndex(Name index) {
return new AlterIndexImpl(configuration(), index);
}
@Override
public DropViewFinalStep dropView(String view) {
return dropView(name(view));