@Override public void truncateTables(final Set<TableReference> tableRefs) throws InsufficientConsistencyException { if (tableRefs.isEmpty()) { return; } run((Function<DSLContext, Void>) ctx -> { for (TableReference tableRef : tableRefs) { ctx.truncate(tableName(tableRef)).execute(); } return null; }); }
private static final Truncate<?> parseTruncate(ParserContext ctx) { parseKeyword(ctx, "TRUNCATE"); parseKeyword(ctx, "TABLE"); Table<?> table = parseTableName(ctx); boolean continueIdentity = parseKeywordIf(ctx, "CONTINUE IDENTITY"); boolean restartIdentity = !continueIdentity && parseKeywordIf(ctx, "RESTART IDENTITY"); boolean cascade = parseKeywordIf(ctx, "CASCADE"); boolean restrict = !cascade && parseKeywordIf(ctx, "RESTRICT"); TruncateIdentityStep<?> step1 = ctx.dsl.truncate(table); TruncateCascadeStep<?> step2 = continueIdentity ? step1.continueIdentity() : restartIdentity ? step1.restartIdentity() : step1; TruncateFinalStep<?> step3 = cascade ? step2.cascade() : restrict ? step2.restrict() : step2; return step3; }
/** Visible for testing */ void clear() { try (Connection conn = datasource.getConnection()) { context.get(conn).truncate(ZIPKIN_SPANS).execute(); context.get(conn).truncate(ZIPKIN_ANNOTATIONS).execute(); context.get(conn).truncate(ZIPKIN_DEPENDENCIES).execute(); } catch (SQLException | RuntimeException e) { throw new AssertionError(e); } } }