From 72de4aa3038a2d45e3957eff9fc321293024f3a3 Mon Sep 17 00:00:00 2001 From: lukaseder Date: Fri, 13 Feb 2015 17:58:06 +0100 Subject: [PATCH] [#4063] Add DSLContext.truncate(String) convenience method --- jOOQ/src/main/java/org/jooq/DSLContext.java | 41 ++++++++++++++++ jOOQ/src/main/java/org/jooq/impl/DSL.java | 47 +++++++++++++++++++ .../java/org/jooq/impl/DefaultDSLContext.java | 5 ++ 3 files changed, 93 insertions(+) diff --git a/jOOQ/src/main/java/org/jooq/DSLContext.java b/jOOQ/src/main/java/org/jooq/DSLContext.java index eea4a99021..88b85759ce 100644 --- a/jOOQ/src/main/java/org/jooq/DSLContext.java +++ b/jOOQ/src/main/java/org/jooq/DSLContext.java @@ -5133,6 +5133,47 @@ public interface DSLContext extends Scope { @Support TruncateIdentityStep truncate(Table table); + /** + * Create a new DSL truncate statement. + *

+ * Example: + *

+ *

+     * DSLContext create = DSL.using(configuration);
+     *
+     * create.truncate(table)
+     *       .execute();
+     * 
+ *

Simulation of TRUNCATE

+ *

+ * Most dialects implement the TRUNCATE statement. If it is not + * supported, it is simulated using an equivalent DELETE + * statement. This is particularly true for these dialects: + *

    + *
  • {@link SQLDialect#FIREBIRD}
  • + *
  • {@link SQLDialect#INGRES}
  • + *
  • {@link SQLDialect#SQLITE}
  • + *
+ *

Vendor-specific extensions of TRUNCATE

+ *

+ * Some statements also support extensions of the TRUNCATE + * statement, such as Postgres: + *

+ *

+     * create.truncate(table)
+     *       .restartIdentity()
+     *       .cascade()
+     *       .execute();
+     * 
+ *

+ * These vendor-specific extensions are currently not simulated for those + * dialects that do not support them natively. + * + * @see #truncate(Table) + */ + @Support + TruncateIdentityStep truncate(String table); + // ------------------------------------------------------------------------- // XXX Other queries for identites and sequences // ------------------------------------------------------------------------- diff --git a/jOOQ/src/main/java/org/jooq/impl/DSL.java b/jOOQ/src/main/java/org/jooq/impl/DSL.java index 3b05e5e38a..3aca221d3d 100644 --- a/jOOQ/src/main/java/org/jooq/impl/DSL.java +++ b/jOOQ/src/main/java/org/jooq/impl/DSL.java @@ -4603,6 +4603,53 @@ public class DSL { return using(new DefaultConfiguration()).truncate(table); } + /** + * Create a new DSL truncate statement. + *

+ * Unlike {@link Delete} factory methods in the {@link DSLContext} API, this + * creates an unattached, and thus not directly renderable or executable + * DELETE statement. + *

+ * Example: + *

+ *

+     * import static org.jooq.impl.DSL.*;
+     *
+     * // [...]
+     *
+     * truncate(table);
+     * 
+ *

Simulation of TRUNCATE

+ *

+ * Most dialects implement the TRUNCATE statement. If it is not + * supported, it is simulated using an equivalent DELETE + * statement. This is particularly true for these dialects: + *

    + *
  • {@link SQLDialect#FIREBIRD}
  • + *
  • {@link SQLDialect#INGRES}
  • + *
  • {@link SQLDialect#SQLITE}
  • + *
+ *

Vendor-specific extensions of TRUNCATE

+ *

+ * Some statements also support extensions of the TRUNCATE + * statement, such as Postgres: + *

+ *

+     * truncate(table)
+     *   .restartIdentity()
+     *   .cascade()
+     * 
+ *

+ * 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 truncate(String table) { + return using(new DefaultConfiguration()).truncate(table); + } + // ------------------------------------------------------------------------- // XXX Quantified comparison predicate expressions // ------------------------------------------------------------------------- diff --git a/jOOQ/src/main/java/org/jooq/impl/DefaultDSLContext.java b/jOOQ/src/main/java/org/jooq/impl/DefaultDSLContext.java index 4b75e13621..869f8317c0 100644 --- a/jOOQ/src/main/java/org/jooq/impl/DefaultDSLContext.java +++ b/jOOQ/src/main/java/org/jooq/impl/DefaultDSLContext.java @@ -1743,6 +1743,11 @@ public class DefaultDSLContext extends AbstractScope implements DSLContext, Seri return new TruncateImpl(configuration(), table); } + @Override + public final TruncateIdentityStep truncate(String table) { + return truncate(table(name(table))); + } + // ------------------------------------------------------------------------- // XXX Other queries for identites and sequences // -------------------------------------------------------------------------