[#4179] Add support for MySQL's mandatory ON clause in the DROP INDEX statement

This commit is contained in:
lukaseder 2015-04-08 17:11:13 +02:00
parent ae9e07a8ed
commit 8bb77b426f
6 changed files with 133 additions and 18 deletions

View File

@ -40,6 +40,23 @@
*/
package org.jooq;
// ...
// ...
import static org.jooq.SQLDialect.CUBRID;
// ...
import static org.jooq.SQLDialect.DERBY;
import static org.jooq.SQLDialect.FIREBIRD;
import static org.jooq.SQLDialect.H2;
// ...
import static org.jooq.SQLDialect.HSQLDB;
// ...
// ...
// ...
import static org.jooq.SQLDialect.POSTGRES;
import static org.jooq.SQLDialect.SQLITE;
// ...
// ...
import javax.annotation.Generated;
/**
@ -401,6 +418,6 @@ public interface ConstraintTypeStep extends ConstraintFinalStep {
/**
* Create a <code>CHECK</code> constraint.
*/
@Support
@Support({ CUBRID, DERBY, FIREBIRD, H2, HSQLDB, POSTGRES, SQLITE })
ConstraintFinalStep check(Condition condition);
}

View File

@ -5146,7 +5146,7 @@ public interface DSLContext extends Scope {
* @see DSL#dropIndex(String)
*/
@Support
DropIndexFinalStep dropIndex(String index);
DropIndexOnStep dropIndex(String index);
/**
* Create a new DSL <code>DROP INDEX</code> statement.
@ -5154,7 +5154,7 @@ public interface DSLContext extends Scope {
* @see DSL#dropIndex(Name)
*/
@Support
DropIndexFinalStep dropIndex(Name index);
DropIndexOnStep dropIndex(Name index);
/**
* Create a new DSL <code>DROP INDEX IF EXISTS</code> statement.
@ -5165,7 +5165,7 @@ public interface DSLContext extends Scope {
* @see DSL#dropIndexIfExists(String)
*/
@Support({ CUBRID, DERBY, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE })
DropIndexFinalStep dropIndexIfExists(String index);
DropIndexOnStep dropIndexIfExists(String index);
/**
* Create a new DSL <code>DROP INDEX IF EXISTS</code> statement.
@ -5176,7 +5176,7 @@ public interface DSLContext extends Scope {
* @see DSL#dropIndexIfExists(Name)
*/
@Support({ CUBRID, DERBY, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE })
DropIndexFinalStep dropIndexIfExists(Name index);
DropIndexOnStep dropIndexIfExists(Name index);
/**
* Create a new DSL <code>DROP SEQUENCE</code> statement.

View File

@ -0,0 +1,70 @@
/**
* Copyright (c) 2009-2015, 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 static org.jooq.SQLDialect.MARIADB;
import static org.jooq.SQLDialect.MYSQL;
/**
* A {@link Query} that can create indexes.
*
* @author Lukas Eder
*/
public interface DropIndexOnStep extends DropIndexFinalStep {
/**
* Specify the table and column expressions on which to drop an index.
*/
@Support({ MARIADB, MYSQL })
DropIndexFinalStep on(Table<?> table);
/**
* Specify the table and column expressions on which to drop an index.
*/
@Support({ MARIADB, MYSQL })
DropIndexFinalStep on(String tableName);
/**
* Specify the table and column expressions on which to drop an index.
*/
@Support({ MARIADB, MYSQL })
DropIndexFinalStep on(Name tableName);
}

View File

@ -111,7 +111,7 @@ import org.jooq.DatePart;
import org.jooq.Delete;
import org.jooq.DeleteWhereStep;
import org.jooq.DerivedColumnList;
import org.jooq.DropIndexFinalStep;
import org.jooq.DropIndexOnStep;
import org.jooq.DropSequenceFinalStep;
import org.jooq.DropTableStep;
import org.jooq.DropViewFinalStep;
@ -4619,7 +4619,7 @@ public class DSL {
* @see DSLContext#dropIndex(String)
*/
@Support
public static DropIndexFinalStep dropIndex(String index) {
public static DropIndexOnStep dropIndex(String index) {
return using(new DefaultConfiguration()).dropIndex(index);
}
@ -4629,7 +4629,7 @@ public class DSL {
* @see DSLContext#dropIndex(Name)
*/
@Support
public static DropIndexFinalStep dropIndex(Name index) {
public static DropIndexOnStep dropIndex(Name index) {
return using(new DefaultConfiguration()).dropIndex(index);
}
@ -4642,7 +4642,7 @@ public class DSL {
* @see DSLContext#dropIndexIfExists(String)
*/
@Support({ CUBRID, DERBY, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE })
public static DropIndexFinalStep dropIndexIfExists(String index) {
public static DropIndexOnStep dropIndexIfExists(String index) {
return using(new DefaultConfiguration()).dropIndexIfExists(index);
}
@ -4655,7 +4655,7 @@ public class DSL {
* @see DSLContext#dropIndexIfExists(String)
*/
@Support({ CUBRID, DERBY, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE })
public static DropIndexFinalStep dropIndexIfExists(Name index) {
public static DropIndexOnStep dropIndexIfExists(Name index) {
return using(new DefaultConfiguration()).dropIndexIfExists(index);
}

View File

@ -92,7 +92,7 @@ import org.jooq.DSLContext;
import org.jooq.DataType;
import org.jooq.DeleteQuery;
import org.jooq.DeleteWhereStep;
import org.jooq.DropIndexFinalStep;
import org.jooq.DropIndexOnStep;
import org.jooq.DropSequenceFinalStep;
import org.jooq.DropTableStep;
import org.jooq.DropViewFinalStep;
@ -1804,22 +1804,22 @@ public class DefaultDSLContext extends AbstractScope implements DSLContext, Seri
}
@Override
public DropIndexFinalStep dropIndex(String index) {
public DropIndexOnStep dropIndex(String index) {
return dropIndex(name(index));
}
@Override
public DropIndexFinalStep dropIndex(Name index) {
public DropIndexOnStep dropIndex(Name index) {
return new DropIndexImpl(configuration(), index);
}
@Override
public DropIndexFinalStep dropIndexIfExists(String index) {
public DropIndexOnStep dropIndexIfExists(String index) {
return dropIndexIfExists(name(index));
}
@Override
public DropIndexFinalStep dropIndexIfExists(Name index) {
public DropIndexOnStep dropIndexIfExists(Name index) {
return new DropIndexImpl(configuration(), index, true);
}

View File

@ -50,13 +50,17 @@ import static org.jooq.SQLDialect.DERBY;
import static org.jooq.SQLDialect.FIREBIRD;
// ...
// ...
import static org.jooq.impl.DSL.name;
import static org.jooq.impl.DSL.table;
import static org.jooq.impl.DropStatementType.INDEX;
import org.jooq.Clause;
import org.jooq.Configuration;
import org.jooq.Context;
import org.jooq.DropIndexFinalStep;
import org.jooq.DropIndexOnStep;
import org.jooq.Name;
import org.jooq.Table;
/**
* @author Lukas Eder
@ -64,7 +68,7 @@ import org.jooq.Name;
class DropIndexImpl extends AbstractQuery implements
// Cascading interface implementations for DROP INDEX behaviour
DropIndexFinalStep {
DropIndexOnStep {
/**
* Generated UID
@ -72,8 +76,9 @@ class DropIndexImpl extends AbstractQuery implements
private static final long serialVersionUID = 8904572826501186329L;
private static final Clause[] CLAUSES = { DROP_INDEX };
private final Name index;
private final boolean ifExists;
private final Name index;
private final boolean ifExists;
private Table<?> on;
DropIndexImpl(Configuration configuration, Name index) {
this(configuration, index, false);
@ -86,6 +91,26 @@ class DropIndexImpl extends AbstractQuery implements
this.ifExists = ifExists;
}
// ------------------------------------------------------------------------
// XXX: DropIndex API
// ------------------------------------------------------------------------
@Override
public final DropIndexFinalStep on(Table<?> table) {
this.on = table;
return this;
}
@Override
public final DropIndexFinalStep on(String tableName) {
return on(name(tableName));
}
@Override
public final DropIndexFinalStep on(Name tableName) {
return on(table(tableName));
}
// ------------------------------------------------------------------------
// XXX: QueryPart API
// ------------------------------------------------------------------------
@ -113,6 +138,9 @@ class DropIndexImpl extends AbstractQuery implements
ctx.keyword("if exists").sql(' ');
ctx.visit(index);
if (on != null)
ctx.sql(' ').keyword("on").sql(' ').visit(on);
}
@Override