[jOOQ/jOOQ#9163] Standardise DROP TABLE

This commit is contained in:
Lukas Eder 2021-01-08 23:33:24 +01:00
parent d22c5c70d3
commit 4e460b756f
8 changed files with 404 additions and 409 deletions

View File

@ -9949,6 +9949,114 @@ public interface DSLContext extends Scope {
@Support({ CUBRID, FIREBIRD, H2, HSQLDB, MARIADB, POSTGRES })
DropSequenceFinalStep dropSequenceIfExists(Sequence<?> sequence);
/**
* The <code>DROP TABLE</code> statement.
*
* @see DSL#dropTable(String)
*/
@NotNull
@Support
DropTableStep dropTable(String table);
/**
* The <code>DROP TABLE</code> statement.
*
* @see DSL#dropTable(Name)
*/
@NotNull
@Support
DropTableStep dropTable(Name table);
/**
* The <code>DROP TABLE</code> statement.
*
* @see DSL#dropTable(Table)
*/
@NotNull
@Support
DropTableStep dropTable(Table<?> table);
/**
* The <code>DROP TABLE IF EXISTS</code> statement.
*
* @see DSL#dropTableIfExists(String)
*/
@NotNull
@Support
DropTableStep dropTableIfExists(String table);
/**
* The <code>DROP TABLE IF EXISTS</code> statement.
*
* @see DSL#dropTableIfExists(Name)
*/
@NotNull
@Support
DropTableStep dropTableIfExists(Name table);
/**
* The <code>DROP TABLE IF EXISTS</code> statement.
*
* @see DSL#dropTableIfExists(Table)
*/
@NotNull
@Support
DropTableStep dropTableIfExists(Table<?> table);
/**
* The <code>DROP TEMPORARY TABLE</code> statement.
*
* @see DSL#dropTemporaryTable(String)
*/
@NotNull
@Support({ FIREBIRD, MARIADB, MYSQL, POSTGRES })
DropTableStep dropTemporaryTable(String table);
/**
* The <code>DROP TEMPORARY TABLE</code> statement.
*
* @see DSL#dropTemporaryTable(Name)
*/
@NotNull
@Support({ FIREBIRD, MARIADB, MYSQL, POSTGRES })
DropTableStep dropTemporaryTable(Name table);
/**
* The <code>DROP TEMPORARY TABLE</code> statement.
*
* @see DSL#dropTemporaryTable(Table)
*/
@NotNull
@Support({ FIREBIRD, MARIADB, MYSQL, POSTGRES })
DropTableStep dropTemporaryTable(Table<?> table);
/**
* The <code>DROP TEMPORARY TABLE IF EXISTS</code> statement.
*
* @see DSL#dropTemporaryTableIfExists(String)
*/
@NotNull
@Support({ FIREBIRD, MARIADB, MYSQL, POSTGRES })
DropTableStep dropTemporaryTableIfExists(String table);
/**
* The <code>DROP TEMPORARY TABLE IF EXISTS</code> statement.
*
* @see DSL#dropTemporaryTableIfExists(Name)
*/
@NotNull
@Support({ FIREBIRD, MARIADB, MYSQL, POSTGRES })
DropTableStep dropTemporaryTableIfExists(Name table);
/**
* The <code>DROP TEMPORARY TABLE IF EXISTS</code> statement.
*
* @see DSL#dropTemporaryTableIfExists(Table)
*/
@NotNull
@Support({ FIREBIRD, MARIADB, MYSQL, POSTGRES })
DropTableStep dropTemporaryTableIfExists(Table<?> table);
/**
* The <code>DROP VIEW</code> statement.
*
@ -11081,123 +11189,6 @@ public interface DSLContext extends Scope {
@Support({ H2, MARIADB, POSTGRES })
AlterTableStep alterTableIfExists(Table<?> table);
/**
* Create a new DSL <code>DROP TABLE</code> statement.
*
* @see DSL#dropTable(String)
*/
@NotNull
@Support
DropTableStep dropTable(String table);
/**
* Create a new DSL <code>DROP TABLE</code> statement.
*
* @see DSL#dropTable(Name)
*/
@NotNull
@Support
DropTableStep dropTable(Name table);
/**
* Create a new DSL <code>DROP TABLE</code> statement.
*
* @see DSL#dropTable(Table)
*/
@NotNull
@Support
DropTableStep dropTable(Table<?> table);
/**
* Create a new DSL <code>DROP TABLE IF EXISTS</code> statement.
* <p>
* If your database doesn't natively support <code>IF EXISTS</code>, this is
* emulated by catching (and ignoring) the relevant {@link SQLException}.
*
* @see DSL#dropTableIfExists(String)
*/
@NotNull
@Support
DropTableStep dropTableIfExists(String table);
/**
* Create a new DSL <code>DROP TABLE IF EXISTS</code> statement.
* <p>
* If your database doesn't natively support <code>IF EXISTS</code>, this is
* emulated by catching (and ignoring) the relevant {@link SQLException}.
*
* @see DSL#dropTableIfExists(Name)
*/
@NotNull
@Support
DropTableStep dropTableIfExists(Name table);
/**
* Create a new DSL <code>DROP TABLE IF EXISTS</code> statement.
* <p>
* If your database doesn't natively support <code>IF EXISTS</code>, this is
* emulated by catching (and ignoring) the relevant {@link SQLException}.
*
* @see DSL#dropTableIfExists(Table)
*/
@NotNull
@Support
DropTableStep dropTableIfExists(Table<?> table);
/**
* Create a new DSL <code>DROP TEMPORARY TABLE</code> statement.
*
* @see DSL#dropTemporaryTable(String)
*/
@NotNull
@Support({ FIREBIRD, MARIADB, MYSQL, POSTGRES })
DropTableStep dropTemporaryTable(String table);
/**
* Create a new DSL <code>DROP TEMPORARY TABLE</code> statement.
*
* @see DSL#dropTemporaryTable(Name)
*/
@NotNull
@Support({ FIREBIRD, MARIADB, MYSQL, POSTGRES })
DropTableStep dropTemporaryTable(Name table);
/**
* Create a new DSL <code>DROP TEMPORARY TABLE</code> statement.
*
* @see DSL#dropTemporaryTable(Table)
*/
@NotNull
@Support({ FIREBIRD, MARIADB, MYSQL, POSTGRES })
DropTableStep dropTemporaryTable(Table<?> table);
/**
* Create a new DSL <code>DROP TEMPORARY TABLE IF EXISTS</code> statement.
*
* @see DSL#dropTemporaryTableIfExists(String)
*/
@NotNull
@Support({ FIREBIRD, MARIADB, MYSQL, POSTGRES })
DropTableStep dropTemporaryTableIfExists(String table);
/**
* Create a new DSL <code>DROP TEMPORARY TABLE IF EXISTS</code> statement.
*
* @see DSL#dropTemporaryTableIfExists(Name)
*/
@NotNull
@Support({ FIREBIRD, MARIADB, MYSQL, POSTGRES })
DropTableStep dropTemporaryTableIfExists(Name table);
/**
* Create a new DSL <code>DROP TEMPORARY TABLE IF EXISTS</code> statement.
*
* @see DSL#dropTemporaryTableIfExists(Table)
*/
@NotNull
@Support({ FIREBIRD, MARIADB, MYSQL, POSTGRES })
DropTableStep dropTemporaryTableIfExists(Table<?> table);
/**
* Create a new DSL truncate statement.
* <p>

View File

@ -37,9 +37,14 @@
*/
package org.jooq;
import static org.jooq.SQLDialect.*;
import java.util.*;
import org.jetbrains.annotations.*;
/**
* The final step in the <code>DROP TABLE</code> DSL.
* A step in the construction of the <code>DROP TABLE</code> statement.
* <p>
* <h3>Referencing <code>XYZ*Step</code> types directly from client code</h3>
* <p>
@ -58,9 +63,7 @@ package org.jooq;
* <li>They're less readable</li>
* <li>They might have binary incompatible changes between minor releases</li>
* </ul>
*
* @author Lukas Eder
*/
@SuppressWarnings({ "unused" })
public interface DropTableFinalStep extends DDLQuery {
}

View File

@ -37,13 +37,14 @@
*/
package org.jooq;
import static org.jooq.SQLDialect.*;
import java.util.*;
import org.jetbrains.annotations.*;
/**
* The step in the <code>DROP TABLE</code> DSL used to specify <code>DROP</code>
* behaviour.
* A step in the construction of the <code>DROP TABLE</code> statement.
* <p>
* <h3>Referencing <code>XYZ*Step</code> types directly from client code</h3>
* <p>
@ -62,24 +63,21 @@ import org.jetbrains.annotations.*;
* <li>They're less readable</li>
* <li>They might have binary incompatible changes between minor releases</li>
* </ul>
*
* @author Lukas Eder
*/
@SuppressWarnings({ "unused" })
public interface DropTableStep extends DropTableFinalStep {
/**
* Add a <code>CASCADE</code> clause to the <code>DROP TABLE</code>
* statement.
* Add the <code>CASCADE</code> clause to the <code>DROP TABLE</code> statement.
*/
@NotNull
@Support
@NotNull
DropTableFinalStep cascade();
/**
* Add a <code>RESTRICT</code> clause to the <code>DROP TABLE</code>
* statement.
* Add the <code>RESTRICT</code> clause to the <code>DROP TABLE</code> statement.
*/
@NotNull
@Support
@NotNull
DropTableFinalStep restrict();
}

View File

@ -42,5 +42,15 @@ package org.jooq.impl;
* @author Lukas Eder
*/
enum Cascade {
CASCADE, RESTRICT
CASCADE,
RESTRICT;
static Cascade of(Boolean b) {
if (b == null)
return null;
else if (b)
return CASCADE;
else
return RESTRICT;
}
}

View File

@ -7997,6 +7997,138 @@ public class DSL {
return dsl().dropSequenceIfExists(sequence);
}
/**
* The <code>DROP TABLE</code> statement.
*
* @see DSLContext#dropTable(String)
*/
@NotNull
@Support
public static org.jooq.DropTableStep dropTable(String table) {
return dsl().dropTable(table);
}
/**
* The <code>DROP TABLE</code> statement.
*
* @see DSLContext#dropTable(Name)
*/
@NotNull
@Support
public static org.jooq.DropTableStep dropTable(Name table) {
return dsl().dropTable(table);
}
/**
* The <code>DROP TABLE</code> statement.
*
* @see DSLContext#dropTable(Table)
*/
@NotNull
@Support
public static org.jooq.DropTableStep dropTable(Table<?> table) {
return dsl().dropTable(table);
}
/**
* The <code>DROP TABLE IF EXISTS</code> statement.
*
* @see DSLContext#dropTableIfExists(String)
*/
@NotNull
@Support
public static org.jooq.DropTableStep dropTableIfExists(String table) {
return dsl().dropTableIfExists(table);
}
/**
* The <code>DROP TABLE IF EXISTS</code> statement.
*
* @see DSLContext#dropTableIfExists(Name)
*/
@NotNull
@Support
public static org.jooq.DropTableStep dropTableIfExists(Name table) {
return dsl().dropTableIfExists(table);
}
/**
* The <code>DROP TABLE IF EXISTS</code> statement.
*
* @see DSLContext#dropTableIfExists(Table)
*/
@NotNull
@Support
public static org.jooq.DropTableStep dropTableIfExists(Table<?> table) {
return dsl().dropTableIfExists(table);
}
/**
* The <code>DROP TEMPORARY TABLE</code> statement.
*
* @see DSLContext#dropTemporaryTable(String)
*/
@NotNull
@Support({ FIREBIRD, MARIADB, MYSQL, POSTGRES })
public static org.jooq.DropTableStep dropTemporaryTable(String table) {
return dsl().dropTemporaryTable(table);
}
/**
* The <code>DROP TEMPORARY TABLE</code> statement.
*
* @see DSLContext#dropTemporaryTable(Name)
*/
@NotNull
@Support({ FIREBIRD, MARIADB, MYSQL, POSTGRES })
public static org.jooq.DropTableStep dropTemporaryTable(Name table) {
return dsl().dropTemporaryTable(table);
}
/**
* The <code>DROP TEMPORARY TABLE</code> statement.
*
* @see DSLContext#dropTemporaryTable(Table)
*/
@NotNull
@Support({ FIREBIRD, MARIADB, MYSQL, POSTGRES })
public static org.jooq.DropTableStep dropTemporaryTable(Table<?> table) {
return dsl().dropTemporaryTable(table);
}
/**
* The <code>DROP TEMPORARY TABLE IF EXISTS</code> statement.
*
* @see DSLContext#dropTemporaryTableIfExists(String)
*/
@NotNull
@Support({ FIREBIRD, MARIADB, MYSQL, POSTGRES })
public static org.jooq.DropTableStep dropTemporaryTableIfExists(String table) {
return dsl().dropTemporaryTableIfExists(table);
}
/**
* The <code>DROP TEMPORARY TABLE IF EXISTS</code> statement.
*
* @see DSLContext#dropTemporaryTableIfExists(Name)
*/
@NotNull
@Support({ FIREBIRD, MARIADB, MYSQL, POSTGRES })
public static org.jooq.DropTableStep dropTemporaryTableIfExists(Name table) {
return dsl().dropTemporaryTableIfExists(table);
}
/**
* The <code>DROP TEMPORARY TABLE IF EXISTS</code> statement.
*
* @see DSLContext#dropTemporaryTableIfExists(Table)
*/
@NotNull
@Support({ FIREBIRD, MARIADB, MYSQL, POSTGRES })
public static org.jooq.DropTableStep dropTemporaryTableIfExists(Table<?> table) {
return dsl().dropTemporaryTableIfExists(table);
}
/**
* The <code>DROP VIEW</code> statement.
*
@ -9148,147 +9280,6 @@ public class DSL {
return dsl().alterTableIfExists(table);
}
/**
* Create a new DSL <code>DROP TABLE</code> statement.
*
* @see DSLContext#dropTable(String)
*/
@NotNull
@Support
public static DropTableStep dropTable(String table) {
return dsl().dropTable(table);
}
/**
* Create a new DSL <code>DROP TABLE</code> statement.
*
* @see DSLContext#dropTable(Name)
*/
@NotNull
@Support
public static DropTableStep dropTable(Name table) {
return dsl().dropTable(table);
}
/**
* Create a new DSL <code>DROP TABLE</code> statement.
*
* @see DSLContext#dropTable(Table)
*/
@NotNull
@Support
public static DropTableStep dropTable(Table<?> table) {
return dsl().dropTable(table);
}
/**
* Create a new DSL <code>DROP TEMPORARY TABLE</code> statement.
*
* @see DSLContext#dropTemporaryTable(String)
*/
@NotNull
@Support({ FIREBIRD, MARIADB, MYSQL, POSTGRES })
public static DropTableStep dropTemporaryTable(String table) {
return dsl().dropTemporaryTable(table);
}
/**
* Create a new DSL <code>DROP TEMPORARY TABLE</code> statement.
*
* @see DSLContext#dropTemporaryTable(Name)
*/
@NotNull
@Support({ FIREBIRD, MARIADB, MYSQL, POSTGRES })
public static DropTableStep dropTemporaryTable(Name table) {
return dsl().dropTemporaryTable(table);
}
/**
* Create a new DSL <code>DROP TEMPORARY TABLE</code> statement.
*
* @see DSLContext#dropTemporaryTable(Table)
*/
@NotNull
@Support({ FIREBIRD, MARIADB, MYSQL, POSTGRES })
public static DropTableStep dropTemporaryTable(Table<?> table) {
return dsl().dropTemporaryTable(table);
}
/**
* Create a new DSL <code>DROP TEMPORARY TABLE IF EXISTS</code> statement.
*
* @see DSLContext#dropTemporaryTableIfExists(String)
*/
@NotNull
@Support({ FIREBIRD, MARIADB, MYSQL, POSTGRES })
public static DropTableStep dropTemporaryTableIfExists(String table) {
return dsl().dropTemporaryTableIfExists(table);
}
/**
* Create a new DSL <code>DROP TEMPORARY TABLE IF EXISTS</code> statement.
*
* @see DSLContext#dropTemporaryTableIfExists(Name)
*/
@NotNull
@Support({ FIREBIRD, MARIADB, MYSQL, POSTGRES })
public static DropTableStep dropTemporaryTableIfExists(Name table) {
return dsl().dropTemporaryTableIfExists(table);
}
/**
* Create a new DSL <code>DROP TEMPORARY TABLE IF EXISTS</code> statement.
*
* @see DSLContext#dropTemporaryTableIfExists(Table)
*/
@NotNull
@Support({ FIREBIRD, MARIADB, MYSQL, POSTGRES })
public static DropTableStep dropTemporaryTableIfExists(Table<?> table) {
return dsl().dropTemporaryTableIfExists(table);
}
/**
* Create a new DSL <code>DROP TABLE IF EXISTS</code> statement.
* <p>
* If your database doesn't natively support <code>IF EXISTS</code>, this is
* emulated by catching (and ignoring) the relevant {@link SQLException}.
*
* @see DSLContext#dropTableIfExists(String)
*/
@NotNull
@Support
public static DropTableStep dropTableIfExists(String table) {
return dsl().dropTableIfExists(table);
}
/**
* Create a new DSL <code>DROP TABLE IF EXISTS</code> statement.
* <p>
* If your database doesn't natively support <code>IF EXISTS</code>, this is
* emulated by catching (and ignoring) the relevant {@link SQLException}.
*
* @see DSLContext#dropTableIfExists(Name)
*/
@NotNull
@Support
public static DropTableStep dropTableIfExists(Name table) {
return dsl().dropTableIfExists(table);
}
/**
* Create a new DSL <code>DROP TABLE IF EXISTS</code> statement.
* <p>
* If your database doesn't natively support <code>IF EXISTS</code>, this is
* emulated by catching (and ignoring) the relevant {@link SQLException}.
*
* @see DSLContext#dropTableIfExists(Table)
*/
@NotNull
@Support
public static DropTableStep dropTableIfExists(Table<?> table) {
return dsl().dropTableIfExists(table);
}
/**
* Create a new DSL truncate statement.
* <p>

View File

@ -3146,6 +3146,66 @@ public class DefaultDSLContext extends AbstractScope implements DSLContext, Seri
return new DropSequenceImpl(configuration(), sequence, true);
}
@Override
public org.jooq.DropTableStep dropTable(String table) {
return new DropTableImpl(configuration(), false, DSL.table(DSL.name(table)), false);
}
@Override
public org.jooq.DropTableStep dropTable(Name table) {
return new DropTableImpl(configuration(), false, DSL.table(table), false);
}
@Override
public org.jooq.DropTableStep dropTable(Table<?> table) {
return new DropTableImpl(configuration(), false, table, false);
}
@Override
public org.jooq.DropTableStep dropTableIfExists(String table) {
return new DropTableImpl(configuration(), false, DSL.table(DSL.name(table)), true);
}
@Override
public org.jooq.DropTableStep dropTableIfExists(Name table) {
return new DropTableImpl(configuration(), false, DSL.table(table), true);
}
@Override
public org.jooq.DropTableStep dropTableIfExists(Table<?> table) {
return new DropTableImpl(configuration(), false, table, true);
}
@Override
public org.jooq.DropTableStep dropTemporaryTable(String table) {
return new DropTableImpl(configuration(), true, DSL.table(DSL.name(table)), false);
}
@Override
public org.jooq.DropTableStep dropTemporaryTable(Name table) {
return new DropTableImpl(configuration(), true, DSL.table(table), false);
}
@Override
public org.jooq.DropTableStep dropTemporaryTable(Table<?> table) {
return new DropTableImpl(configuration(), true, table, false);
}
@Override
public org.jooq.DropTableStep dropTemporaryTableIfExists(String table) {
return new DropTableImpl(configuration(), true, DSL.table(DSL.name(table)), true);
}
@Override
public org.jooq.DropTableStep dropTemporaryTableIfExists(Name table) {
return new DropTableImpl(configuration(), true, DSL.table(table), true);
}
@Override
public org.jooq.DropTableStep dropTemporaryTableIfExists(Table<?> table) {
return new DropTableImpl(configuration(), true, table, true);
}
@Override
public org.jooq.DropViewFinalStep dropView(String view) {
return new DropViewImpl(configuration(), DSL.table(DSL.name(view)), false);
@ -3747,66 +3807,6 @@ public class DefaultDSLContext extends AbstractScope implements DSLContext, Seri
return new AlterTableImpl(configuration(), table, true);
}
@Override
public DropTableStep dropTable(String table) {
return dropTable(name(table));
}
@Override
public DropTableStep dropTable(Name table) {
return dropTable(table(table));
}
@Override
public DropTableStep dropTable(Table<?> table) {
return new DropTableImpl(configuration(), table);
}
@Override
public DropTableStep dropTemporaryTable(String table) {
return dropTemporaryTable(name(table));
}
@Override
public DropTableStep dropTemporaryTable(Name table) {
return dropTemporaryTable(table(table));
}
@Override
public DropTableStep dropTemporaryTable(Table<?> table) {
return new DropTableImpl(configuration(), table, false, true);
}
@Override
public DropTableStep dropTemporaryTableIfExists(String table) {
return dropTemporaryTableIfExists(name(table));
}
@Override
public DropTableStep dropTemporaryTableIfExists(Name table) {
return dropTemporaryTableIfExists(table(table));
}
@Override
public DropTableStep dropTemporaryTableIfExists(Table<?> table) {
return new DropTableImpl(configuration(), table, true, true);
}
@Override
public DropTableStep dropTableIfExists(String table) {
return dropTableIfExists(name(table));
}
@Override
public DropTableStep dropTableIfExists(Name table) {
return dropTableIfExists(table(table));
}
@Override
public DropTableStep dropTableIfExists(Table<?> table) {
return new DropTableImpl(configuration(), table, true);
}
@Override
public final TruncateIdentityStep<Record> truncate(String table) {
return truncateTable(table);

View File

@ -37,100 +37,101 @@
*/
package org.jooq.impl;
import static org.jooq.Clause.DROP_TABLE;
import static org.jooq.Clause.DROP_TABLE_TABLE;
// ...
// ...
// ...
// ...
import static org.jooq.SQLDialect.DERBY;
import static org.jooq.SQLDialect.FIREBIRD;
// ...
import static org.jooq.SQLDialect.MYSQL;
// ...
// ...
// ...
import static org.jooq.impl.Cascade.CASCADE;
import static org.jooq.impl.Cascade.RESTRICT;
import static org.jooq.impl.Keywords.K_CASCADE;
import static org.jooq.impl.Keywords.K_DROP;
import static org.jooq.impl.Keywords.K_DROP_TABLE;
import static org.jooq.impl.Keywords.K_IF_EXISTS;
import static org.jooq.impl.Keywords.K_RESTRICT;
import static org.jooq.impl.Keywords.K_TABLE;
import static org.jooq.impl.Keywords.K_TEMPORARY;
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 org.jooq.Clause;
import org.jooq.Configuration;
import org.jooq.Context;
import org.jooq.DropTableStep;
import org.jooq.SQLDialect;
import org.jooq.Table;
import java.util.*;
/**
* @author Lukas Eder
* The <code>DROP TABLE</code> statement.
*/
final class DropTableImpl extends AbstractRowCountQuery implements
@SuppressWarnings({ "rawtypes", "unused" })
final class DropTableImpl
extends
AbstractRowCountQuery
implements
DropTableStep,
DropTableFinalStep
{
// Cascading interface implementations for DROP TABLE behaviour
DropTableStep {
private static final long serialVersionUID = 1L;
/**
* Generated UID
*/
private static final long serialVersionUID = 8904572826501186329L;
private static final Clause[] CLAUSES = { DROP_TABLE };
private static final Set<SQLDialect> NO_SUPPORT_IF_EXISTS = SQLDialect.supportedBy(DERBY, FIREBIRD);
private static final Set<SQLDialect> TEMPORARY_SEMANTIC = SQLDialect.supportedBy(MYSQL);
private final Boolean temporary;
private final Table<?> table;
private final boolean dropTableIfExists;
private Boolean cascade;
private final Table<?> table;
private final boolean temporary;
private final boolean ifExists;
private Cascade cascade;
DropTableImpl(Configuration configuration, Table<?> table) {
this(configuration, table, false, false);
DropTableImpl(
Configuration configuration,
Boolean temporary,
Table<?> table,
boolean dropTableIfExists
) {
this(
configuration,
temporary,
table,
dropTableIfExists,
null
);
}
DropTableImpl(Configuration configuration, Table<?> table, boolean ifExists) {
this(configuration, table, ifExists, false);
}
DropTableImpl(Configuration configuration, Table<?> table, boolean ifExists, boolean temporary) {
DropTableImpl(
Configuration configuration,
Boolean temporary,
Table<?> table,
boolean dropTableIfExists,
Boolean cascade
) {
super(configuration);
this.table = table;
this.ifExists = ifExists;
this.temporary = temporary;
this.table = table;
this.dropTableIfExists = dropTableIfExists;
this.cascade = cascade;
}
final Table<?> $table() { return table; }
final boolean $temporary() { return temporary; }
final boolean $ifExists() { return ifExists; }
final Cascade $cascade() { return cascade; }
final Boolean $temporary() { return temporary; }
final Table<?> $table() { return table; }
final boolean $dropTableIfExists() { return dropTableIfExists; }
final Boolean $cascade() { return cascade; }
// ------------------------------------------------------------------------
// -------------------------------------------------------------------------
// XXX: DSL API
// ------------------------------------------------------------------------
// -------------------------------------------------------------------------
@Override
public final DropTableImpl cascade() {
cascade = CASCADE;
this.cascade = true;
return this;
}
@Override
public final DropTableImpl restrict() {
cascade = RESTRICT;
this.cascade = false;
return this;
}
// ------------------------------------------------------------------------
// -------------------------------------------------------------------------
// XXX: QueryPart API
// ------------------------------------------------------------------------
// -------------------------------------------------------------------------
private static final Clause[] CLAUSES = { Clause.DROP_TABLE };
private static final Set<SQLDialect> NO_SUPPORT_IF_EXISTS = SQLDialect.supportedBy(DERBY, FIREBIRD);
private static final Set<SQLDialect> TEMPORARY_SEMANTIC = SQLDialect.supportedBy(MYSQL);
private final boolean supportsIfExists(Context<?> ctx) {
return !NO_SUPPORT_IF_EXISTS.contains(ctx.dialect());
@ -138,18 +139,17 @@ final class DropTableImpl extends AbstractRowCountQuery implements
@Override
public final void accept(Context<?> ctx) {
if (ifExists && !supportsIfExists(ctx)) {
if (dropTableIfExists && !supportsIfExists(ctx)) {
Tools.beginTryCatch(ctx, DDLStatementType.DROP_TABLE);
accept0(ctx);
Tools.endTryCatch(ctx, DDLStatementType.DROP_TABLE);
}
else {
else
accept0(ctx);
}
}
private void accept0(Context<?> ctx) {
ctx.start(DROP_TABLE_TABLE);
ctx.start(Clause.DROP_TABLE_TABLE);
// [#6371] [#9019] While many dialects do not require this keyword, in
// some dialects (e.g. MySQL), there is a semantic
@ -160,17 +160,17 @@ final class DropTableImpl extends AbstractRowCountQuery implements
ctx.visit(K_DROP_TABLE).sql(' ');
if (ifExists && supportsIfExists(ctx))
if (dropTableIfExists && supportsIfExists(ctx))
ctx.visit(K_IF_EXISTS).sql(' ');
ctx.visit(table);
if (cascade == CASCADE)
if (Boolean.TRUE.equals(cascade))
ctx.sql(' ').visit(K_CASCADE);
else if (cascade == RESTRICT)
else if (Boolean.FALSE.equals(cascade))
ctx.sql(' ').visit(K_RESTRICT);
ctx.end(DROP_TABLE_TABLE);
ctx.end(Clause.DROP_TABLE_TABLE);
}
@ -178,4 +178,6 @@ final class DropTableImpl extends AbstractRowCountQuery implements
public final Clause[] clauses(Context<?> ctx) {
return CLAUSES;
}
}

View File

@ -759,7 +759,7 @@ final class Interpreter {
MutableSchema schema = getSchema(table.getSchema());
MutableTable existing = schema.table(table);
if (existing == null) {
if (!query.$ifExists())
if (!query.$dropTableIfExists())
throw notExists(table);
return;
@ -769,7 +769,7 @@ final class Interpreter {
else if (query.$temporary() && existing.options.type() != TableType.TEMPORARY)
throw objectNotTemporaryTable(table);
drop(schema.tables, existing, query.$cascade());
drop(schema.tables, existing, Cascade.of(query.$cascade()));
}
private final void accept0(TruncateImpl<?> query) {