[#4063] Add DSLContext.truncate(String) convenience method

This commit is contained in:
lukaseder 2015-02-13 17:58:06 +01:00
parent cd6e6a0c6a
commit 72de4aa303
3 changed files with 93 additions and 0 deletions

View File

@ -5133,6 +5133,47 @@ public interface DSLContext extends Scope {
@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>Simulation of <code>TRUNCATE</code></h3>
* <p>
* Most dialects implement the <code>TRUNCATE</code> statement. If it is not
* supported, it is simulated 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 simulated for those
* dialects that do not support them natively.
*
* @see #truncate(Table)
*/
@Support
TruncateIdentityStep<Record> truncate(String table);
// -------------------------------------------------------------------------
// XXX Other queries for identites and sequences
// -------------------------------------------------------------------------

View File

@ -4603,6 +4603,53 @@ public class DSL {
return using(new DefaultConfiguration()).truncate(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 simulated 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 simulated for those
* dialects that do not support them natively.
*
* @see DSLContext#truncate(String)
*/
@Support
public static TruncateIdentityStep<Record> truncate(String table) {
return using(new DefaultConfiguration()).truncate(table);
}
// -------------------------------------------------------------------------
// XXX Quantified comparison predicate expressions
// -------------------------------------------------------------------------

View File

@ -1743,6 +1743,11 @@ public class DefaultDSLContext extends AbstractScope implements DSLContext, Seri
return new TruncateImpl<R>(configuration(), table);
}
@Override
public final TruncateIdentityStep<Record> truncate(String table) {
return truncate(table(name(table)));
}
// -------------------------------------------------------------------------
// XXX Other queries for identites and sequences
// -------------------------------------------------------------------------