From 8cc0de619428c5c834bdafc9ec9e4e7b8b30ba93 Mon Sep 17 00:00:00 2001 From: Lukas Eder Date: Fri, 8 Jan 2021 23:06:42 +0100 Subject: [PATCH] [jOOQ/jOOQ#9163] Standardise DROP INDEX --- jOOQ/src/main/java/org/jooq/DSLContext.java | 117 ++++++------- .../java/org/jooq/DropIndexCascadeStep.java | 24 ++- .../java/org/jooq/DropIndexFinalStep.java | 11 +- .../main/java/org/jooq/DropIndexOnStep.java | 83 +++------ .../java/org/jooq/impl/AlterIndexImpl.java | 2 +- jOOQ/src/main/java/org/jooq/impl/DSL.java | 141 +++++++-------- .../java/org/jooq/impl/DefaultDSLContext.java | 60 +++---- .../java/org/jooq/impl/DropIndexImpl.java | 165 +++++++++--------- 8 files changed, 279 insertions(+), 324 deletions(-) diff --git a/jOOQ/src/main/java/org/jooq/DSLContext.java b/jOOQ/src/main/java/org/jooq/DSLContext.java index 7df0963ab9..e3dd7c21c4 100644 --- a/jOOQ/src/main/java/org/jooq/DSLContext.java +++ b/jOOQ/src/main/java/org/jooq/DSLContext.java @@ -9787,6 +9787,60 @@ public interface DSLContext extends Scope { @Support({ FIREBIRD, H2, HSQLDB, POSTGRES }) DropDomainCascadeStep dropDomainIfExists(Domain domain); + /** + * The DROP INDEX statement. + * + * @see DSL#dropIndex(String) + */ + @NotNull + @Support + DropIndexOnStep dropIndex(String index); + + /** + * The DROP INDEX statement. + * + * @see DSL#dropIndex(Name) + */ + @NotNull + @Support + DropIndexOnStep dropIndex(Name index); + + /** + * The DROP INDEX statement. + * + * @see DSL#dropIndex(Index) + */ + @NotNull + @Support + DropIndexOnStep dropIndex(Index index); + + /** + * The DROP INDEX IF EXISTS statement. + * + * @see DSL#dropIndexIfExists(String) + */ + @NotNull + @Support({ CUBRID, DERBY, FIREBIRD, H2, HSQLDB, MARIADB, POSTGRES, SQLITE }) + DropIndexOnStep dropIndexIfExists(String index); + + /** + * The DROP INDEX IF EXISTS statement. + * + * @see DSL#dropIndexIfExists(Name) + */ + @NotNull + @Support({ CUBRID, DERBY, FIREBIRD, H2, HSQLDB, MARIADB, POSTGRES, SQLITE }) + DropIndexOnStep dropIndexIfExists(Name index); + + /** + * The DROP INDEX IF EXISTS statement. + * + * @see DSL#dropIndexIfExists(Index) + */ + @NotNull + @Support({ CUBRID, DERBY, FIREBIRD, H2, HSQLDB, MARIADB, POSTGRES, SQLITE }) + DropIndexOnStep dropIndexIfExists(Index index); + /** * The DROP SCHEMA statement. * @@ -11153,69 +11207,6 @@ public interface DSLContext extends Scope { @Support({ FIREBIRD, MARIADB, MYSQL, POSTGRES }) DropTableStep dropTemporaryTableIfExists(Table table); - /** - * Create a new DSL DROP INDEX statement. - * - * @see DSL#dropIndex(String) - */ - @NotNull - @Support - DropIndexOnStep dropIndex(String index); - - /** - * Create a new DSL DROP INDEX statement. - * - * @see DSL#dropIndex(Name) - */ - @NotNull - @Support - DropIndexOnStep dropIndex(Name index); - - /** - * Create a new DSL DROP INDEX statement. - * - * @see DSL#dropIndex(Name) - */ - @NotNull - @Support - DropIndexOnStep dropIndex(Index index); - - /** - * Create a new DSL DROP INDEX IF EXISTS statement. - *

- * If your database doesn't natively support IF EXISTS, this is - * emulated by catching (and ignoring) the relevant {@link SQLException}. - * - * @see DSL#dropIndexIfExists(String) - */ - @NotNull - @Support({ CUBRID, DERBY, FIREBIRD, H2, HSQLDB, MARIADB, POSTGRES, SQLITE }) - DropIndexOnStep dropIndexIfExists(String index); - - /** - * Create a new DSL DROP INDEX IF EXISTS statement. - *

- * If your database doesn't natively support IF EXISTS, this is - * emulated by catching (and ignoring) the relevant {@link SQLException}. - * - * @see DSL#dropIndexIfExists(Name) - */ - @NotNull - @Support({ CUBRID, DERBY, FIREBIRD, H2, HSQLDB, MARIADB, POSTGRES, SQLITE }) - DropIndexOnStep dropIndexIfExists(Name index); - - /** - * Create a new DSL DROP INDEX IF EXISTS statement. - *

- * If your database doesn't natively support IF EXISTS, this is - * emulated by catching (and ignoring) the relevant {@link SQLException}. - * - * @see DSL#dropIndexIfExists(Name) - */ - @NotNull - @Support({ CUBRID, DERBY, FIREBIRD, H2, HSQLDB, MARIADB, POSTGRES, SQLITE }) - DropIndexOnStep dropIndexIfExists(Index index); - /** * Create a new DSL truncate statement. *

diff --git a/jOOQ/src/main/java/org/jooq/DropIndexCascadeStep.java b/jOOQ/src/main/java/org/jooq/DropIndexCascadeStep.java index 767f62c862..f77e0c8d18 100644 --- a/jOOQ/src/main/java/org/jooq/DropIndexCascadeStep.java +++ b/jOOQ/src/main/java/org/jooq/DropIndexCascadeStep.java @@ -37,15 +37,14 @@ */ package org.jooq; +import static org.jooq.SQLDialect.*; + +import java.util.*; + import org.jetbrains.annotations.*; - -// ... -// ... -import static org.jooq.SQLDialect.POSTGRES; - /** - * A {@link Query} that can drop indexes. + * A step in the construction of the DROP INDEX statement. *

*

Referencing XYZ*Step types directly from client code

*

@@ -64,24 +63,21 @@ import static org.jooq.SQLDialect.POSTGRES; *

  • They're less readable
  • *
  • They might have binary incompatible changes between minor releases
  • * - * - * @author Lukas Eder */ +@SuppressWarnings({ "unused" }) public interface DropIndexCascadeStep extends DropIndexFinalStep { /** - * Add the CASCADE clause to the DROP INDEX - * statement. + * Add the CASCADE clause to the DROP INDEX statement. */ - @NotNull @Support({ POSTGRES }) + @NotNull DropIndexFinalStep cascade(); /** - * Add the RESTRICT clause to the DROP INDEX - * statement. + * Add the RESTRICT clause to the DROP INDEX statement. */ - @NotNull @Support({ POSTGRES }) + @NotNull DropIndexFinalStep restrict(); } diff --git a/jOOQ/src/main/java/org/jooq/DropIndexFinalStep.java b/jOOQ/src/main/java/org/jooq/DropIndexFinalStep.java index 798e640e3a..20cfe93fef 100644 --- a/jOOQ/src/main/java/org/jooq/DropIndexFinalStep.java +++ b/jOOQ/src/main/java/org/jooq/DropIndexFinalStep.java @@ -37,9 +37,14 @@ */ package org.jooq; +import static org.jooq.SQLDialect.*; + +import java.util.*; + +import org.jetbrains.annotations.*; /** - * A {@link Query} that can drop indexes. + * A step in the construction of the DROP INDEX statement. *

    *

    Referencing XYZ*Step types directly from client code

    *

    @@ -58,9 +63,7 @@ package org.jooq; *

  • They're less readable
  • *
  • They might have binary incompatible changes between minor releases
  • * - * - * @author Lukas Eder */ +@SuppressWarnings({ "unused" }) public interface DropIndexFinalStep extends DDLQuery { - } diff --git a/jOOQ/src/main/java/org/jooq/DropIndexOnStep.java b/jOOQ/src/main/java/org/jooq/DropIndexOnStep.java index 9e9b224849..0933ebeea2 100644 --- a/jOOQ/src/main/java/org/jooq/DropIndexOnStep.java +++ b/jOOQ/src/main/java/org/jooq/DropIndexOnStep.java @@ -37,36 +37,14 @@ */ package org.jooq; +import static org.jooq.SQLDialect.*; + +import java.util.*; + import org.jetbrains.annotations.*; - -// ... -// ... -// ... -// ... -// ... -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.MARIADB; -// ... -import static org.jooq.SQLDialect.MYSQL; -// ... -import static org.jooq.SQLDialect.POSTGRES; -// ... -import static org.jooq.SQLDialect.SQLITE; -// ... -// ... -// ... - /** - * A {@link Query} that can drop indexes. + * A step in the construction of the DROP INDEX statement. *

    *

    Referencing XYZ*Step types directly from client code

    *

    @@ -85,50 +63,43 @@ import static org.jooq.SQLDialect.SQLITE; *

  • They're less readable
  • *
  • They might have binary incompatible changes between minor releases
  • * - * - * @author Lukas Eder */ +@SuppressWarnings({ "unused" }) public interface DropIndexOnStep extends DropIndexCascadeStep { /** - * Specify the table expression on which to drop an index. + * Add the ON clause to the DROP INDEX statement. *

    - * {@link SQLDialect#MYSQL}, {@link SQLDialect#MARIADB}, and - * {@link SQLDialect#SQLSERVER} use table-scoped index names, not - * schema-scoped names. This means that in these databases, the - * ON clause is mandatory in order to unambiguously identify an - * index. In all other databases, the ON clause will simply be - * ignored for compatibility reasons. + * {@link SQLDialect#MYSQL}, {@link SQLDialect#MARIADB}, and {@link SQLDialect#SQLSERVER} + * use table-scoped index names, not schema-scoped names. This means that in these databases, + * the ON clause is mandatory in order to unambiguously identify an index. In all other + * databases, the ON clause will simply be ignored for compatibility reasons. */ - @NotNull @Support - DropIndexCascadeStep on(Table table); + @NotNull + DropIndexCascadeStep on(String on); /** - * Specify the table expression on which to drop an index. + * Add the ON clause to the DROP INDEX statement. *

    - * {@link SQLDialect#MYSQL}, {@link SQLDialect#MARIADB}, and - * {@link SQLDialect#SQLSERVER} use table-scoped index names, not - * schema-scoped names. This means that in these databases, the - * ON clause is mandatory in order to unambiguously identify an - * index. In all other databases, the ON clause will simply be - * ignored for compatibility reasons. + * {@link SQLDialect#MYSQL}, {@link SQLDialect#MARIADB}, and {@link SQLDialect#SQLSERVER} + * use table-scoped index names, not schema-scoped names. This means that in these databases, + * the ON clause is mandatory in order to unambiguously identify an index. In all other + * databases, the ON clause will simply be ignored for compatibility reasons. */ - @NotNull @Support - DropIndexCascadeStep on(String tableName); + @NotNull + DropIndexCascadeStep on(Name on); /** - * Specify the table expression on which to drop an index. + * Add the ON clause to the DROP INDEX statement. *

    - * {@link SQLDialect#MYSQL}, {@link SQLDialect#MARIADB}, and - * {@link SQLDialect#SQLSERVER} use table-scoped index names, not - * schema-scoped names. This means that in these databases, the - * ON clause is mandatory in order to unambiguously identify an - * index. In all other databases, the ON clause will simply be - * ignored for compatibility reasons. + * {@link SQLDialect#MYSQL}, {@link SQLDialect#MARIADB}, and {@link SQLDialect#SQLSERVER} + * use table-scoped index names, not schema-scoped names. This means that in these databases, + * the ON clause is mandatory in order to unambiguously identify an index. In all other + * databases, the ON clause will simply be ignored for compatibility reasons. */ - @NotNull @Support - DropIndexCascadeStep on(Name tableName); + @NotNull + DropIndexCascadeStep on(Table on); } diff --git a/jOOQ/src/main/java/org/jooq/impl/AlterIndexImpl.java b/jOOQ/src/main/java/org/jooq/impl/AlterIndexImpl.java index 43b309e374..ba05221f70 100644 --- a/jOOQ/src/main/java/org/jooq/impl/AlterIndexImpl.java +++ b/jOOQ/src/main/java/org/jooq/impl/AlterIndexImpl.java @@ -110,7 +110,7 @@ implements // ------------------------------------------------------------------------- // XXX: DSL API // ------------------------------------------------------------------------- - + @Override public final AlterIndexImpl on(String on) { return on(DSL.table(DSL.name(on))); diff --git a/jOOQ/src/main/java/org/jooq/impl/DSL.java b/jOOQ/src/main/java/org/jooq/impl/DSL.java index 660f754242..29ba76745d 100644 --- a/jOOQ/src/main/java/org/jooq/impl/DSL.java +++ b/jOOQ/src/main/java/org/jooq/impl/DSL.java @@ -7799,6 +7799,72 @@ public class DSL { return dsl().dropDomainIfExists(domain); } + /** + * The DROP INDEX statement. + * + * @see DSLContext#dropIndex(String) + */ + @NotNull + @Support + public static org.jooq.DropIndexOnStep dropIndex(String index) { + return dsl().dropIndex(index); + } + + /** + * The DROP INDEX statement. + * + * @see DSLContext#dropIndex(Name) + */ + @NotNull + @Support + public static org.jooq.DropIndexOnStep dropIndex(Name index) { + return dsl().dropIndex(index); + } + + /** + * The DROP INDEX statement. + * + * @see DSLContext#dropIndex(Index) + */ + @NotNull + @Support + public static org.jooq.DropIndexOnStep dropIndex(Index index) { + return dsl().dropIndex(index); + } + + /** + * The DROP INDEX IF EXISTS statement. + * + * @see DSLContext#dropIndexIfExists(String) + */ + @NotNull + @Support({ CUBRID, DERBY, FIREBIRD, H2, HSQLDB, MARIADB, POSTGRES, SQLITE }) + public static org.jooq.DropIndexOnStep dropIndexIfExists(String index) { + return dsl().dropIndexIfExists(index); + } + + /** + * The DROP INDEX IF EXISTS statement. + * + * @see DSLContext#dropIndexIfExists(Name) + */ + @NotNull + @Support({ CUBRID, DERBY, FIREBIRD, H2, HSQLDB, MARIADB, POSTGRES, SQLITE }) + public static org.jooq.DropIndexOnStep dropIndexIfExists(Name index) { + return dsl().dropIndexIfExists(index); + } + + /** + * The DROP INDEX IF EXISTS statement. + * + * @see DSLContext#dropIndexIfExists(Index) + */ + @NotNull + @Support({ CUBRID, DERBY, FIREBIRD, H2, HSQLDB, MARIADB, POSTGRES, SQLITE }) + public static org.jooq.DropIndexOnStep dropIndexIfExists(Index index) { + return dsl().dropIndexIfExists(index); + } + /** * The DROP SCHEMA statement. * @@ -9232,81 +9298,6 @@ public class DSL { return dsl().dropTableIfExists(table); } - /** - * Create a new DSL DROP INDEX statement. - * - * @see DSLContext#dropIndex(String) - */ - @NotNull - @Support - public static DropIndexOnStep dropIndex(String index) { - return dsl().dropIndex(index); - } - - /** - * Create a new DSL DROP INDEX statement. - * - * @see DSLContext#dropIndex(Name) - */ - @NotNull - @Support - public static DropIndexOnStep dropIndex(Name index) { - return dsl().dropIndex(index); - } - - /** - * Create a new DSL DROP INDEX statement. - * - * @see DSLContext#dropIndex(Index) - */ - @NotNull - @Support - public static DropIndexOnStep dropIndex(Index index) { - return dsl().dropIndex(index); - } - - /** - * Create a new DSL DROP INDEX IF EXISTS statement. - *

    - * If your database doesn't natively support IF EXISTS, this is - * emulated by catching (and ignoring) the relevant {@link SQLException}. - * - * @see DSLContext#dropIndexIfExists(String) - */ - @NotNull - @Support({ CUBRID, DERBY, FIREBIRD, H2, HSQLDB, MARIADB, POSTGRES, SQLITE }) - public static DropIndexOnStep dropIndexIfExists(String index) { - return dsl().dropIndexIfExists(index); - } - - /** - * Create a new DSL DROP INDEX IF EXISTS statement. - *

    - * If your database doesn't natively support IF EXISTS, this is - * emulated by catching (and ignoring) the relevant {@link SQLException}. - * - * @see DSLContext#dropIndexIfExists(Name) - */ - @NotNull - @Support({ CUBRID, DERBY, FIREBIRD, H2, HSQLDB, MARIADB, POSTGRES, SQLITE }) - public static DropIndexOnStep dropIndexIfExists(Name index) { - return dsl().dropIndexIfExists(index); - } - - /** - * Create a new DSL DROP INDEX IF EXISTS statement. - *

    - * If your database doesn't natively support IF EXISTS, this is - * emulated by catching (and ignoring) the relevant {@link SQLException}. - * - * @see DSLContext#dropIndexIfExists(Index) - */ - @NotNull - @Support({ CUBRID, DERBY, FIREBIRD, H2, HSQLDB, MARIADB, POSTGRES, SQLITE }) - public static DropIndexOnStep dropIndexIfExists(Index index) { - return dsl().dropIndexIfExists(index); - } - /** * 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 876fcb7ef0..f222c73178 100644 --- a/jOOQ/src/main/java/org/jooq/impl/DefaultDSLContext.java +++ b/jOOQ/src/main/java/org/jooq/impl/DefaultDSLContext.java @@ -3056,6 +3056,36 @@ public class DefaultDSLContext extends AbstractScope implements DSLContext, Seri return new DropDomainImpl(configuration(), domain, true); } + @Override + public org.jooq.DropIndexOnStep dropIndex(String index) { + return new DropIndexImpl(configuration(), DSL.index(DSL.name(index)), false); + } + + @Override + public org.jooq.DropIndexOnStep dropIndex(Name index) { + return new DropIndexImpl(configuration(), DSL.index(index), false); + } + + @Override + public org.jooq.DropIndexOnStep dropIndex(Index index) { + return new DropIndexImpl(configuration(), index, false); + } + + @Override + public org.jooq.DropIndexOnStep dropIndexIfExists(String index) { + return new DropIndexImpl(configuration(), DSL.index(DSL.name(index)), true); + } + + @Override + public org.jooq.DropIndexOnStep dropIndexIfExists(Name index) { + return new DropIndexImpl(configuration(), DSL.index(index), true); + } + + @Override + public org.jooq.DropIndexOnStep dropIndexIfExists(Index index) { + return new DropIndexImpl(configuration(), index, true); + } + @Override public org.jooq.DropSchemaStep dropSchema(String schema) { return new DropSchemaImpl(configuration(), DSL.schema(DSL.name(schema)), false); @@ -3777,36 +3807,6 @@ public class DefaultDSLContext extends AbstractScope implements DSLContext, Seri return new DropTableImpl(configuration(), table, true); } - @Override - public DropIndexOnStep dropIndex(String index) { - return dropIndex(name(index)); - } - - @Override - public DropIndexOnStep dropIndex(Name index) { - return dropIndex(index(index)); - } - - @Override - public DropIndexOnStep dropIndex(Index index) { - return new DropIndexImpl(configuration(), index); - } - - @Override - public DropIndexOnStep dropIndexIfExists(String index) { - return dropIndexIfExists(name(index)); - } - - @Override - public DropIndexOnStep dropIndexIfExists(Name index) { - return dropIndexIfExists(index(index)); - } - - @Override - public DropIndexOnStep dropIndexIfExists(Index index) { - return new DropIndexImpl(configuration(), index, true); - } - @Override public final TruncateIdentityStep truncate(String table) { return truncateTable(table); diff --git a/jOOQ/src/main/java/org/jooq/impl/DropIndexImpl.java b/jOOQ/src/main/java/org/jooq/impl/DropIndexImpl.java index b6652347cb..8f1d09f2c0 100644 --- a/jOOQ/src/main/java/org/jooq/impl/DropIndexImpl.java +++ b/jOOQ/src/main/java/org/jooq/impl/DropIndexImpl.java @@ -37,115 +37,117 @@ */ package org.jooq.impl; -import static org.jooq.Clause.DROP_INDEX; -// ... -// ... -// ... -import static org.jooq.SQLDialect.CUBRID; -// ... -import static org.jooq.SQLDialect.DERBY; -import static org.jooq.SQLDialect.FIREBIRD; -// ... -import static org.jooq.SQLDialect.MARIADB; -// ... -import static org.jooq.SQLDialect.MYSQL; -// ... -// ... -// ... -// ... -import static org.jooq.impl.DSL.name; -import static org.jooq.impl.DSL.table; -import static org.jooq.impl.Keywords.K_CASCADE; -import static org.jooq.impl.Keywords.K_DROP_INDEX; -import static org.jooq.impl.Keywords.K_IF_EXISTS; -import static org.jooq.impl.Keywords.K_ON; -import static org.jooq.impl.Keywords.K_RESTRICT; -import static org.jooq.impl.Tools.beginTryCatch; -import static org.jooq.impl.Tools.endTryCatch; +import static org.jooq.impl.DSL.*; +import static org.jooq.impl.Internal.*; +import static org.jooq.impl.Keywords.*; +import static org.jooq.impl.Names.*; +import static org.jooq.impl.SQLDataType.*; +import static org.jooq.impl.Tools.*; +import static org.jooq.impl.Tools.BooleanDataKey.*; +import static org.jooq.SQLDialect.*; -import java.util.Set; +import org.jooq.*; +import org.jooq.impl.*; +import org.jooq.tools.*; + +import java.util.*; -import org.jooq.Clause; -import org.jooq.Configuration; -import org.jooq.Context; -import org.jooq.DropIndexOnStep; -import org.jooq.Index; -import org.jooq.Name; -import org.jooq.SQLDialect; -import org.jooq.Table; /** - * @author Lukas Eder + * The DROP INDEX statement. */ -final class DropIndexImpl extends AbstractRowCountQuery implements +@SuppressWarnings({ "hiding", "rawtypes", "unused" }) +final class DropIndexImpl +extends + AbstractRowCountQuery +implements + DropIndexOnStep, + DropIndexCascadeStep, + DropIndexFinalStep +{ - // Cascading interface implementations for DROP INDEX behaviour - DropIndexOnStep { + private static final long serialVersionUID = 1L; - /** - * Generated UID - */ - private static final long serialVersionUID = 8904572826501186329L; - private static final Clause[] CLAUSES = { DROP_INDEX }; - private static final Set NO_SUPPORT_IF_EXISTS = SQLDialect.supportedBy(CUBRID, DERBY, FIREBIRD); - private static final Set REQUIRES_ON = SQLDialect.supportedBy(MARIADB, MYSQL); + private final Index index; + private final boolean dropIndexIfExists; + private Table on; + private Boolean cascade; - private final Index index; - private final boolean ifExists; - private Table on; - private Boolean cascade; - - DropIndexImpl(Configuration configuration, Index index) { - this(configuration, index, false); + DropIndexImpl( + Configuration configuration, + Index index, + boolean dropIndexIfExists + ) { + this( + configuration, + index, + dropIndexIfExists, + null, + null + ); } - DropIndexImpl(Configuration configuration, Index index, boolean ifExists) { + DropIndexImpl( + Configuration configuration, + Index index, + boolean dropIndexIfExists, + Table on, + Boolean cascade + ) { super(configuration); this.index = index; - this.ifExists = ifExists; - this.on = index.getTable(); + this.dropIndexIfExists = dropIndexIfExists; + this.on = on; + this.cascade = cascade; } - final Index $index() { return index; } - final boolean $ifExists() { return ifExists; } - final Table $on() { return on; } + final Index $index() { return index; } + final boolean $dropIndexIfExists() { return dropIndexIfExists; } + final Table $on() { return on; } + final Boolean $cascade() { return cascade; } - // ------------------------------------------------------------------------ - // XXX: DropIndex API - // ------------------------------------------------------------------------ + // ------------------------------------------------------------------------- + // XXX: DSL API + // ------------------------------------------------------------------------- @Override - public final DropIndexImpl on(Table table) { - this.on = table; + public final DropIndexImpl on(String on) { + return on(DSL.table(DSL.name(on))); + } + + @Override + public final DropIndexImpl on(Name on) { + return on(DSL.table(on)); + } + + @Override + public final DropIndexImpl on(Table on) { + this.on = on; return this; } - @Override - public final DropIndexImpl on(String tableName) { - return on(name(tableName)); - } - - @Override - public final DropIndexImpl on(Name tableName) { - return on(table(tableName)); - } - @Override public final DropIndexImpl cascade() { - cascade = true; + this.cascade = true; return this; } @Override public final DropIndexImpl restrict() { - cascade = false; + this.cascade = false; return this; } - // ------------------------------------------------------------------------ + // ------------------------------------------------------------------------- // XXX: QueryPart API - // ------------------------------------------------------------------------ + // ------------------------------------------------------------------------- + + + + private static final Clause[] CLAUSES = { Clause.DROP_INDEX }; + private static final Set NO_SUPPORT_IF_EXISTS = SQLDialect.supportedBy(CUBRID, DERBY, FIREBIRD); + private static final Set REQUIRES_ON = SQLDialect.supportedBy(MARIADB, MYSQL); private final boolean supportsIfExists(Context ctx) { return !NO_SUPPORT_IF_EXISTS.contains(ctx.dialect()); @@ -153,20 +155,19 @@ final class DropIndexImpl extends AbstractRowCountQuery implements @Override public final void accept(Context ctx) { - if (ifExists && !supportsIfExists(ctx)) { + if (dropIndexIfExists && !supportsIfExists(ctx)) { beginTryCatch(ctx, DDLStatementType.DROP_INDEX); accept0(ctx); endTryCatch(ctx, DDLStatementType.DROP_INDEX); } - else { + else accept0(ctx); - } } private void accept0(Context ctx) { ctx.visit(K_DROP_INDEX).sql(' '); - if (ifExists && supportsIfExists(ctx)) + if (dropIndexIfExists && supportsIfExists(ctx)) ctx.visit(K_IF_EXISTS).sql(' '); @@ -187,4 +188,6 @@ final class DropIndexImpl extends AbstractRowCountQuery implements public final Clause[] clauses(Context ctx) { return CLAUSES; } + + }