SecretSeriesDAO { public void deleteSecretSeriesByName(String name) { long now = OffsetDateTime.now().toEpochSecond(); dslContext.transaction(configuration -> { SecretsRecord r = DSL.using(configuration) .select() .from(SECRETS) .where(SECRETS.NAME.eq(name).and(SECRETS.CURRENT.isNotNull())) .forUpdate() .fetchOneInto(SECRETS); if (r != null) { DSL.using(configuration) .update(SECRETS) .set(SECRETS.NAME, transformNameForDeletion(name)) .set(SECRETS.CURRENT, (Long) null) .set(SECRETS.UPDATEDAT, now) .where(SECRETS.ID.eq(r.getId())) .execute(); DSL.using(configuration) .delete(ACCESSGRANTS) .where(ACCESSGRANTS.SECRETID.eq(r.getId())) .execute(); } }); } private  SecretSeriesDAO(DSLContext dslContext, ObjectMapper mapper,
      SecretSeriesMapper secretSeriesMapper, RowHmacGenerator rowHmacGenerator); int setExpiration(long secretContentId, Instant expiration); int setHmac(long secretContentId, String hmac); int setCurrentVersion(long secretId, long secretContentId, String updater, long now); Optional<SecretSeries> getSecretSeriesById(long id); Optional<SecretSeries> getSecretSeriesByName(String name); List<SecretSeries> getMultipleSecretSeriesByName(List<String> names); ImmutableList<SecretSeries> getSecretSeries(@Nullable Long expireMaxTime,
      @Nullable Group group, @Nullable Long expireMinTime, @Nullable String minName,
      @Nullable Integer limit); ImmutableList<SecretSeries> getSecretSeriesBatched(int idx, int num, boolean newestFirst); void deleteSecretSeriesByName(String name); void deleteSecretSeriesById(long id); int countDeletedSecretSeries(); List<Long> getIdsForSecretSeriesDeletedBeforeDate(DateTime deleteBefore); long dangerPermanentlyRemoveRecordsForGivenIDs(List<Long> ids);  }
@Test public void deleteSecretSeriesByName() { long now = OffsetDateTime.now().toEpochSecond(); long id = secretSeriesDAO.createSecretSeries("toBeDeleted_deleteSecretSeriesByName", "creator", "", null, null, now); long contentId = secretContentDAO.createSecretContent(id, "blah", "checksum", "creator", null, 0, now); secretSeriesDAO.setCurrentVersion(id, contentId, "creator", now); assertThat(secretSeriesDAO.getSecretSeriesByName("toBeDeleted_deleteSecretSeriesByName") .get() .currentVersion()) .isPresent(); secretSeriesDAO.deleteSecretSeriesByName("toBeDeleted_deleteSecretSeriesByName"); assertThat( secretSeriesDAO.getSecretSeriesByName("toBeDeleted_deleteSecretSeriesByName")).isEmpty(); assertThat(secretSeriesDAO.getSecretSeriesById(id)).isEmpty(); }