[jOOQ/jOOQ#9163] Standardise TRUNCATE

This commit is contained in:
Lukas Eder 2021-01-13 12:42:24 +01:00
parent a1b08de279
commit 28d7c22e17
10 changed files with 274 additions and 456 deletions

View File

@ -10431,6 +10431,60 @@ public interface DSLContext extends Scope {
@Support({ DERBY, H2, HSQLDB, MARIADB, MYSQL, POSTGRES })
RowCountQuery setSchema(Schema schema);
/**
* The <code>TRUNCATE</code> statement.
*
* @see DSL#truncate(String)
*/
@NotNull
@Support
TruncateIdentityStep<Record> truncate(String table);
/**
* The <code>TRUNCATE</code> statement.
*
* @see DSL#truncate(Name)
*/
@NotNull
@Support
TruncateIdentityStep<Record> truncate(Name table);
/**
* The <code>TRUNCATE</code> statement.
*
* @see DSL#truncate(Table)
*/
@NotNull
@Support
<R extends Record> TruncateIdentityStep<R> truncate(Table<R> table);
/**
* The <code>TRUNCATE TABLE</code> statement.
*
* @see DSL#truncateTable(String)
*/
@NotNull
@Support
TruncateIdentityStep<Record> truncateTable(String table);
/**
* The <code>TRUNCATE TABLE</code> statement.
*
* @see DSL#truncateTable(Name)
*/
@NotNull
@Support
TruncateIdentityStep<Record> truncateTable(Name table);
/**
* The <code>TRUNCATE TABLE</code> statement.
*
* @see DSL#truncateTable(Table)
*/
@NotNull
@Support
<R extends Record> TruncateIdentityStep<R> truncateTable(Table<R> table);
/**
@ -11208,157 +11262,6 @@ public interface DSLContext extends Scope {
@Support({ H2, MARIADB, POSTGRES })
AlterTableStep alterTableIfExists(Table<?> table);
/**
* Create a new DSL truncate statement.
* <p>
* Synonym for {@link #truncateTable(String)}
*/
@NotNull
@Support
TruncateIdentityStep<Record> truncate(String table);
/**
* Create a new DSL truncate statement.
* <p>
* Synonym for {@link #truncateTable(Name)}
*/
@NotNull
@Support
TruncateIdentityStep<Record> truncate(Name table);
/**
* Create a new DSL truncate statement.
* <p>
* Synonym for {@link #truncateTable(Table)}
*/
@NotNull
@Support
<R extends Record> TruncateIdentityStep<R> truncate(Table<R> table);
/**
* Create a new DSL truncate statement.
* <p>
* Example:
* <p>
* <code><pre>
* DSLContext create = DSL.using(configuration);
*
* create.truncate(table)
* .execute();
* </pre></code>
* <h3>Emulation of <code>TRUNCATE</code></h3>
* <p>
* Most dialects implement the <code>TRUNCATE</code> statement. If it is not
* supported, it is emulated using an equivalent <code>DELETE</code>
* statement. This is particularly true for these dialects:
* <ul>
* <li> {@link SQLDialect#FIREBIRD}</li>
* <li> {@link SQLDialect#INGRES}</li>
* <li> {@link SQLDialect#SQLITE}</li>
* </ul>
* <h3>Vendor-specific extensions of <code>TRUNCATE</code></h3>
* <p>
* Some statements also support extensions of the <code>TRUNCATE</code>
* statement, such as Postgres:
* <p>
* <code><pre>
* create.truncate(table)
* .restartIdentity()
* .cascade()
* .execute();
* </pre></code>
* <p>
* These vendor-specific extensions are currently not emulated for those
* dialects that do not support them natively.
*
* @see #truncate(Table)
*/
@NotNull
@Support
TruncateIdentityStep<Record> truncateTable(String table);
/**
* Create a new DSL truncate statement.
* <p>
* Example:
* <p>
* <code><pre>
* DSLContext create = DSL.using(configuration);
*
* create.truncate(table)
* .execute();
* </pre></code>
* <h3>Emulation of <code>TRUNCATE</code></h3>
* <p>
* Most dialects implement the <code>TRUNCATE</code> statement. If it is not
* supported, it is emulated using an equivalent <code>DELETE</code>
* statement. This is particularly true for these dialects:
* <ul>
* <li> {@link SQLDialect#FIREBIRD}</li>
* <li> {@link SQLDialect#INGRES}</li>
* <li> {@link SQLDialect#SQLITE}</li>
* </ul>
* <h3>Vendor-specific extensions of <code>TRUNCATE</code></h3>
* <p>
* Some statements also support extensions of the <code>TRUNCATE</code>
* statement, such as Postgres:
* <p>
* <code><pre>
* create.truncate(table)
* .restartIdentity()
* .cascade()
* .execute();
* </pre></code>
* <p>
* These vendor-specific extensions are currently not emulated for those
* dialects that do not support them natively.
*
* @see #truncate(Name)
*/
@NotNull
@Support
TruncateIdentityStep<Record> truncateTable(Name table);
/**
* Create a new DSL truncate statement.
* <p>
* Example:
* <p>
* <code><pre>
* DSLContext create = DSL.using(configuration);
*
* create.truncate(table)
* .execute();
* </pre></code>
* <h3>Emulation of <code>TRUNCATE</code></h3>
* <p>
* Most dialects implement the <code>TRUNCATE</code> statement. If it is not
* supported, it is emulated using an equivalent <code>DELETE</code>
* statement. This is particularly true for these dialects:
* <ul>
* <li> {@link SQLDialect#FIREBIRD}</li>
* <li> {@link SQLDialect#INGRES}</li>
* <li> {@link SQLDialect#SQLITE}</li>
* </ul>
* <h3>Vendor-specific extensions of <code>TRUNCATE</code></h3>
* <p>
* Some statements also support extensions of the <code>TRUNCATE</code>
* statement, such as Postgres:
* <p>
* <code><pre>
* create.truncate(table)
* .restartIdentity()
* .cascade()
* .execute();
* </pre></code>
* <p>
* These vendor-specific extensions are currently not emulated for those
* dialects that do not support them natively.
*/
@NotNull
@Support
<R extends Record> TruncateIdentityStep<R> truncateTable(Table<R> table);
// -------------------------------------------------------------------------
// XXX Other queries for identites and sequences
// -------------------------------------------------------------------------

View File

@ -37,24 +37,33 @@
*/
package org.jooq;
import org.jooq.impl.DSL;
import static org.jooq.SQLDialect.*;
import java.util.*;
import org.jetbrains.annotations.*;
/**
* A <code>TRUNCATE</code> statement.
* A step in the construction of the <code>TRUNCATE</code> statement.
* <p>
* <strong>Example:</strong>
* <h3>Referencing <code>XYZ*Step</code> types directly from client code</h3>
* <p>
* <code><pre>
* // Assuming import static org.jooq.impl.DSL.*;
*
* using(configuration).truncate(ACTOR).execute();
* </pre></code>
* It is usually not recommended to reference any <code>XYZ*Step</code> types
* directly from client code, or assign them to local variables. When writing
* dynamic SQL, creating a statement's components dynamically, and passing them
* to the DSL API statically is usually a better choice. See the manual's
* section about dynamic SQL for details: <a href=
* "https://www.jooq.org/doc/latest/manual/sql-building/dynamic-sql">https://www.jooq.org/doc/latest/manual/sql-building/dynamic-sql</a>.
* <p>
* Instances can be created using {@link DSL#truncate(Table)}, or
* {@link DSLContext#truncate(Table)} and overloads.
*
* @author Lukas Eder
* Drawbacks of referencing the <code>XYZ*Step</code> types directly:
* <ul>
* <li>They're operating on mutable implementations (as of jOOQ 3.x)</li>
* <li>They're less composable and not easy to get right when dynamic SQL gets
* complex</li>
* <li>They're less readable</li>
* <li>They might have binary incompatible changes between minor releases</li>
* </ul>
*/
@SuppressWarnings({ "unused" })
public interface Truncate<R extends Record> extends DDLQuery {
}

View File

@ -37,16 +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 truncate a table in the database.
* A step in the construction of the <code>TRUNCATE</code> statement.
* <p>
* <h3>Referencing <code>XYZ*Step</code> types directly from client code</h3>
* <p>
@ -65,24 +63,21 @@ import static org.jooq.SQLDialect.POSTGRES;
* <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 TruncateCascadeStep<R extends Record> extends TruncateFinalStep<R> {
/**
* Add the <code>CASCADE</code> clause to the <code>TRUNCATE</code>
* statement.
* Add the <code>CASCADE</code> clause to the <code>TRUNCATE</code> statement.
*/
@NotNull
@Support({ POSTGRES })
@NotNull
TruncateFinalStep<R> cascade();
/**
* Add the <code>RESTRICT</code> clause to the <code>TRUNCATE</code>
* statement.
* Add the <code>RESTRICT</code> clause to the <code>TRUNCATE</code> statement.
*/
@NotNull
@Support({ POSTGRES })
@NotNull
TruncateFinalStep<R> restrict();
}

View File

@ -37,10 +37,14 @@
*/
package org.jooq;
import static org.jooq.SQLDialect.*;
import java.util.*;
import org.jetbrains.annotations.*;
/**
* A {@link Query} that can truncate a table in the database.
* A step in the construction of the <code>TRUNCATE</code> statement.
* <p>
* <h3>Referencing <code>XYZ*Step</code> types directly from client code</h3>
* <p>
@ -59,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 TruncateFinalStep<R extends Record> extends Truncate<R> {
}

View File

@ -37,15 +37,14 @@
*/
package org.jooq;
import static org.jooq.SQLDialect.*;
import java.util.*;
import org.jetbrains.annotations.*;
// ...
import static org.jooq.SQLDialect.HSQLDB;
import static org.jooq.SQLDialect.POSTGRES;
/**
* A {@link Query} that can truncate a table in the database.
* A step in the construction of the <code>TRUNCATE</code> statement.
* <p>
* <h3>Referencing <code>XYZ*Step</code> types directly from client code</h3>
* <p>
@ -64,24 +63,21 @@ import static org.jooq.SQLDialect.POSTGRES;
* <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 TruncateIdentityStep<R extends Record> extends TruncateCascadeStep<R> {
/**
* Add the <code>RESTART IDENTITY</code> clause to the <code>TRUNCATE</code>
* statement.
* Add the <code>RESTART IDENTITY</code> clause to the <code>TRUNCATE</code> statement.
*/
@NotNull
@Support({ HSQLDB, POSTGRES })
@NotNull
TruncateCascadeStep<R> restartIdentity();
/**
* Add the <code>CONTINUE IDENTITY</code> clause to the
* <code>TRUNCATE</code> statement.
* Add the <code>CONTINUE IDENTITY</code> clause to the <code>TRUNCATE</code> statement.
*/
@NotNull
@Support({ HSQLDB, POSTGRES })
@NotNull
TruncateCascadeStep<R> continueIdentity();
}

View File

@ -8583,6 +8583,72 @@ public class DSL {
return dsl().setSchema(schema);
}
/**
* The <code>TRUNCATE</code> statement.
*
* @see DSLContext#truncate(String)
*/
@NotNull
@Support
public static org.jooq.TruncateIdentityStep<Record> truncate(String table) {
return dsl().truncate(table);
}
/**
* The <code>TRUNCATE</code> statement.
*
* @see DSLContext#truncate(Name)
*/
@NotNull
@Support
public static org.jooq.TruncateIdentityStep<Record> truncate(Name table) {
return dsl().truncate(table);
}
/**
* The <code>TRUNCATE</code> statement.
*
* @see DSLContext#truncate(Table)
*/
@NotNull
@Support
public static <R extends Record> org.jooq.TruncateIdentityStep<R> truncate(Table<R> table) {
return dsl().truncate(table);
}
/**
* The <code>TRUNCATE TABLE</code> statement.
*
* @see DSLContext#truncateTable(String)
*/
@NotNull
@Support
public static org.jooq.TruncateIdentityStep<Record> truncateTable(String table) {
return dsl().truncateTable(table);
}
/**
* The <code>TRUNCATE TABLE</code> statement.
*
* @see DSLContext#truncateTable(Name)
*/
@NotNull
@Support
public static org.jooq.TruncateIdentityStep<Record> truncateTable(Name table) {
return dsl().truncateTable(table);
}
/**
* The <code>TRUNCATE TABLE</code> statement.
*
* @see DSLContext#truncateTable(Table)
*/
@NotNull
@Support
public static <R extends Record> org.jooq.TruncateIdentityStep<R> truncateTable(Table<R> table) {
return dsl().truncateTable(table);
}
/**
@ -9302,183 +9368,6 @@ public class DSL {
return dsl().alterTableIfExists(table);
}
/**
* Create a new DSL truncate statement.
* <p>
* Synonym for {@link #truncateTable(String)}
*/
@NotNull
@Support
public static TruncateIdentityStep<Record> truncate(String table) {
return truncateTable(table);
}
/**
* Create a new DSL truncate statement.
* <p>
* Synonym for {@link #truncateTable(Name)}
*/
@NotNull
@Support
public static TruncateIdentityStep<Record> truncate(Name table) {
return truncateTable(table);
}
/**
* Create a new DSL truncate statement.
* <p>
* Synonym for {@link #truncateTable(Table)}
*/
@NotNull
@Support
public static <R extends Record> TruncateIdentityStep<R> truncate(Table<R> table) {
return truncateTable(table);
}
/**
* Create a new DSL truncate statement.
* <p>
* Unlike {@link Delete} factory methods in the {@link DSLContext} API, this
* creates an unattached, and thus not directly renderable or executable
* <code>DELETE</code> statement.
* <p>
* Example:
* <p>
* <code><pre>
* import static org.jooq.impl.DSL.*;
*
* // [...]
*
* truncate(table);
* </pre></code>
* <h3>Simulation of <code>TRUNCATE</code></h3>
* <p>
* Most dialects implement the <code>TRUNCATE</code> statement. If it is not
* supported, it is emulated using an equivalent <code>DELETE</code>
* statement. This is particularly true for these dialects:
* <ul>
* <li> {@link SQLDialect#FIREBIRD}</li>
* <li> {@link SQLDialect#INGRES}</li>
* <li> {@link SQLDialect#SQLITE}</li>
* </ul>
* <h3>Vendor-specific extensions of <code>TRUNCATE</code></h3>
* <p>
* Some statements also support extensions of the <code>TRUNCATE</code>
* statement, such as Postgres:
* <p>
* <code><pre>
* truncate(table)
* .restartIdentity()
* .cascade()
* </pre></code>
* <p>
* These vendor-specific extensions are currently not emulated for those
* dialects that do not support them natively.
*
* @see DSLContext#truncate(String)
*/
@NotNull
@Support
public static TruncateIdentityStep<Record> truncateTable(String table) {
return dsl().truncateTable(table);
}
/**
* Create a new DSL truncate statement.
* <p>
* Unlike {@link Delete} factory methods in the {@link DSLContext} API, this
* creates an unattached, and thus not directly renderable or executable
* <code>DELETE</code> statement.
* <p>
* Example:
* <p>
* <code><pre>
* import static org.jooq.impl.DSL.*;
*
* // [...]
*
* truncate(table);
* </pre></code>
* <h3>Simulation of <code>TRUNCATE</code></h3>
* <p>
* Most dialects implement the <code>TRUNCATE</code> statement. If it is not
* supported, it is emulated using an equivalent <code>DELETE</code>
* statement. This is particularly true for these dialects:
* <ul>
* <li> {@link SQLDialect#FIREBIRD}</li>
* <li> {@link SQLDialect#INGRES}</li>
* <li> {@link SQLDialect#SQLITE}</li>
* </ul>
* <h3>Vendor-specific extensions of <code>TRUNCATE</code></h3>
* <p>
* Some statements also support extensions of the <code>TRUNCATE</code>
* statement, such as Postgres:
* <p>
* <code><pre>
* truncate(table)
* .restartIdentity()
* .cascade()
* </pre></code>
* <p>
* These vendor-specific extensions are currently not emulated for those
* dialects that do not support them natively.
*
* @see DSLContext#truncate(Name)
*/
@NotNull
@Support
public static TruncateIdentityStep<Record> truncateTable(Name table) {
return dsl().truncateTable(table);
}
/**
* Create a new DSL truncate statement.
* <p>
* Unlike {@link Delete} factory methods in the {@link DSLContext} API, this
* creates an unattached, and thus not directly renderable or executable
* <code>DELETE</code> statement.
* <p>
* Example:
* <p>
* <code><pre>
* import static org.jooq.impl.DSL.*;
*
* // [...]
*
* truncate(table);
* </pre></code>
* <h3>Simulation of <code>TRUNCATE</code></h3>
* <p>
* Most dialects implement the <code>TRUNCATE</code> statement. If it is not
* supported, it is emulated using an equivalent <code>DELETE</code>
* statement. This is particularly true for these dialects:
* <ul>
* <li> {@link SQLDialect#FIREBIRD}</li>
* <li> {@link SQLDialect#INGRES}</li>
* <li> {@link SQLDialect#SQLITE}</li>
* </ul>
* <h3>Vendor-specific extensions of <code>TRUNCATE</code></h3>
* <p>
* Some statements also support extensions of the <code>TRUNCATE</code>
* statement, such as Postgres:
* <p>
* <code><pre>
* truncate(table)
* .restartIdentity()
* .cascade()
* </pre></code>
* <p>
* These vendor-specific extensions are currently not emulated for those
* dialects that do not support them natively.
*
* @see DSLContext#truncate(Table)
*/
@NotNull
@Support
public static <R extends Record> TruncateIdentityStep<R> truncateTable(Table<R> table) {
return dsl().truncateTable(table);
}
// -------------------------------------------------------------------------
// XXX Quantified comparison predicate expressions
// -------------------------------------------------------------------------

View File

@ -3406,6 +3406,36 @@ public class DefaultDSLContext extends AbstractScope implements DSLContext, Seri
return new SetSchema(configuration(), schema);
}
@Override
public org.jooq.TruncateIdentityStep<Record> truncate(String table) {
return new TruncateImpl(configuration(), DSL.table(DSL.name(table)));
}
@Override
public org.jooq.TruncateIdentityStep<Record> truncate(Name table) {
return new TruncateImpl(configuration(), DSL.table(table));
}
@Override
public <R extends Record> org.jooq.TruncateIdentityStep<R> truncate(Table<R> table) {
return new TruncateImpl(configuration(), table);
}
@Override
public org.jooq.TruncateIdentityStep<Record> truncateTable(String table) {
return truncate(DSL.table(DSL.name(table)));
}
@Override
public org.jooq.TruncateIdentityStep<Record> truncateTable(Name table) {
return truncate(DSL.table(table));
}
@Override
public <R extends Record> org.jooq.TruncateIdentityStep<R> truncateTable(Table<R> table) {
return truncate(table);
}
@Override
@ -3817,36 +3847,6 @@ public class DefaultDSLContext extends AbstractScope implements DSLContext, Seri
return new AlterTableImpl(configuration(), table, true);
}
@Override
public final TruncateIdentityStep<Record> truncate(String table) {
return truncateTable(table);
}
@Override
public final TruncateIdentityStep<Record> truncate(Name table) {
return truncateTable(table);
}
@Override
public <R extends Record> TruncateIdentityStep<R> truncate(Table<R> table) {
return truncateTable(table);
}
@Override
public final TruncateIdentityStep<Record> truncateTable(String table) {
return truncateTable(name(table));
}
@Override
public final TruncateIdentityStep<Record> truncateTable(Name table) {
return truncateTable(table(table));
}
@Override
public <R extends Record> TruncateIdentityStep<R> truncateTable(Table<R> table) {
return new TruncateImpl<>(configuration(), table);
}
// -------------------------------------------------------------------------
// XXX Other queries for identites and sequences
// -------------------------------------------------------------------------

View File

@ -783,7 +783,7 @@ final class Interpreter {
throw notExists(table);
else if (!existing.options.type().isTable())
throw objectNotTable(table);
else if (!query.$cascade() && existing.hasReferencingKeys())
else if (!TRUE.equals(query.$cascade()) && existing.hasReferencingKeys())
throw new DataDefinitionException("Cannot truncate table referenced by other tables. Use CASCADE: " + table);
}

View File

@ -68,6 +68,7 @@ import static org.jooq.Operator.OR;
import static org.jooq.SQLDialect.CUBRID;
// ...
// ...
import static org.jooq.SQLDialect.DEFAULT;
import static org.jooq.SQLDialect.DERBY;
import static org.jooq.SQLDialect.FIREBIRD;
import static org.jooq.SQLDialect.H2;
@ -269,7 +270,7 @@ final class SelectQueryImpl<R extends Record> extends AbstractResultQuery<R> imp
static final Set<SQLDialect> SUPPORT_WINDOW_CLAUSE = SQLDialect.supportedBy(H2, MYSQL, POSTGRES, SQLITE);
private static final Set<SQLDialect> OPTIONAL_FROM_CLAUSE = SQLDialect.supportedBy(H2, MARIADB, MYSQL, POSTGRES, SQLITE);
private static final Set<SQLDialect> OPTIONAL_FROM_CLAUSE = SQLDialect.supportedBy(DEFAULT, H2, MARIADB, MYSQL, POSTGRES, SQLITE);
private static final Set<SQLDialect> REQUIRES_DERIVED_TABLE_DML = SQLDialect.supportedBy(MARIADB, MYSQL);
private static final Set<SQLDialect> EMULATE_EMPTY_GROUP_BY_CONSTANT = SQLDialect.supportedUntil(DERBY, HSQLDB);
private static final Set<SQLDialect> EMULATE_EMPTY_GROUP_BY_OTHER = SQLDialect.supportedUntil(FIREBIRD, MARIADB, MYSQL, SQLITE);

View File

@ -37,86 +37,107 @@
*/
package org.jooq.impl;
import static java.lang.Boolean.TRUE;
import static org.jooq.Clause.TRUNCATE;
import static org.jooq.Clause.TRUNCATE_TRUNCATE;
// ...
import static org.jooq.impl.DSL.delete;
import static org.jooq.impl.Keywords.K_CASCADE;
import static org.jooq.impl.Keywords.K_CONTINUE_IDENTITY;
import static org.jooq.impl.Keywords.K_IMMEDIATE;
import static org.jooq.impl.Keywords.K_RESTART_IDENTITY;
import static org.jooq.impl.Keywords.K_RESTRICT;
import static org.jooq.impl.Keywords.K_TRUNCATE_TABLE;
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 org.jooq.*;
import org.jooq.conf.*;
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.Record;
import org.jooq.SQLDialect;
import org.jooq.Table;
import org.jooq.TruncateCascadeStep;
import org.jooq.TruncateFinalStep;
import org.jooq.TruncateIdentityStep;
/**
* @author Lukas Eder
* The <code>TRUNCATE</code> statement.
*/
final class TruncateImpl<R extends Record> extends AbstractRowCountQuery implements
@SuppressWarnings({ "rawtypes", "unchecked", "unused" })
final class TruncateImpl<R extends Record>
extends
AbstractRowCountQuery
implements
TruncateIdentityStep<R>,
TruncateCascadeStep<R>,
TruncateFinalStep<R>,
Truncate<R>
{
// Cascading interface implementations for Truncate behaviour
TruncateIdentityStep<R> {
private static final long serialVersionUID = 1L;
/**
* Generated UID
*/
private static final long serialVersionUID = 8904572826501186329L;
private static final Clause[] CLAUSES = { TRUNCATE };
private final Table<R> table;
private Boolean restartIdentity;
private Boolean cascade;
private final Table<R> table;
private Boolean cascade;
private Boolean restartIdentity;
TruncateImpl(
Configuration configuration,
Table<R> table
) {
this(
configuration,
table,
null,
null
);
}
public TruncateImpl(Configuration configuration, Table<R> table) {
TruncateImpl(
Configuration configuration,
Table<R> table,
Boolean restartIdentity,
Boolean cascade
) {
super(configuration);
this.table = table;
this.restartIdentity = restartIdentity;
this.cascade = cascade;
}
final Table<?> $table() { return table; }
final boolean $cascade() { return TRUE.equals(cascade); }
final Table<R> $table() { return table; }
final Boolean $restartIdentity() { return restartIdentity; }
final Boolean $cascade() { return cascade; }
// ------------------------------------------------------------------------
// -------------------------------------------------------------------------
// XXX: DSL API
// ------------------------------------------------------------------------
// -------------------------------------------------------------------------
@Override
public final TruncateFinalStep<R> cascade() {
cascade = true;
public final TruncateImpl<R> restartIdentity() {
this.restartIdentity = true;
return this;
}
@Override
public final TruncateFinalStep<R> restrict() {
cascade = false;
public final TruncateImpl<R> continueIdentity() {
this.restartIdentity = false;
return this;
}
@Override
public final TruncateCascadeStep<R> restartIdentity() {
restartIdentity = true;
public final TruncateImpl<R> cascade() {
this.cascade = true;
return this;
}
@Override
public final TruncateCascadeStep<R> continueIdentity() {
restartIdentity = false;
public final TruncateImpl<R> restrict() {
this.cascade = false;
return this;
}
// ------------------------------------------------------------------------
// -------------------------------------------------------------------------
// XXX: QueryPart API
// ------------------------------------------------------------------------
// -------------------------------------------------------------------------
private static final Clause[] CLAUSES = { Clause.TRUNCATE };
@Override
public final void accept(Context<?> ctx) {
@ -136,7 +157,7 @@ final class TruncateImpl<R extends Record> extends AbstractRowCountQuery impleme
// All other dialects do
default: {
ctx.start(TRUNCATE_TRUNCATE)
ctx.start(Clause.TRUNCATE_TRUNCATE)
.visit(K_TRUNCATE_TABLE).sql(' ')
.visit(table);
@ -162,7 +183,7 @@ final class TruncateImpl<R extends Record> extends AbstractRowCountQuery impleme
ctx.formatSeparator()
.visit(cascade ? K_CASCADE : K_RESTRICT);
ctx.end(TRUNCATE_TRUNCATE);
ctx.end(Clause.TRUNCATE_TRUNCATE);
break;
}
}
@ -172,4 +193,6 @@ final class TruncateImpl<R extends Record> extends AbstractRowCountQuery impleme
public final Clause[] clauses(Context<?> ctx) {
return CLAUSES;
}
}