SecretDAO { public Optional<SecretSeriesAndContent> getSecretByName(String name) { checkArgument(!name.isEmpty()); SecretContentDAO secretContentDAO = secretContentDAOFactory.using(dslContext.configuration()); SecretSeriesDAO secretSeriesDAO = secretSeriesDAOFactory.using(dslContext.configuration()); Optional<SecretSeries> series = secretSeriesDAO.getSecretSeriesByName(name); if (series.isPresent() && series.get().currentVersion().isPresent()) { long secretContentId = series.get().currentVersion().get(); Optional<SecretContent> secretContent = secretContentDAO.getSecretContentById(secretContentId); if (!secretContent.isPresent()) { return Optional.empty(); } return Optional.of(SecretSeriesAndContent.of(series.get(), secretContent.get())); } return Optional.empty(); } SecretDAO(DSLContext dslContext, SecretContentDAOFactory secretContentDAOFactory,
      SecretSeriesDAOFactory secretSeriesDAOFactory, ContentCryptographer cryptographer); @VisibleForTesting long createSecret(String name, String encryptedSecret, String hmac,
      String creator, Map<String, String> metadata, long expiry, String description,
      @Nullable String type, @Nullable Map<String, String> generationOptions); @VisibleForTesting long createOrUpdateSecret(String name, String encryptedSecret, String hmac, String creator,
      Map<String, String> metadata, long expiry, String description, @Nullable String type,
      @Nullable Map<String, String> generationOptions); @VisibleForTesting long partialUpdateSecret(String name, String creator,
      PartialUpdateSecretRequestV2 request); boolean setExpiration(String name, Instant expiration); Optional<SecretSeriesAndContent> getSecretById(long secretId); Optional<SecretSeriesAndContent> getSecretByName(String name); List<SecretSeriesAndContent> getSecretsByName(List<String> names); ImmutableList<SecretSeriesAndContent> getSecrets(@Nullable Long expireMaxTime,
      @Nullable Group group, @Nullable Long expireMinTime, @Nullable String minName,
      @Nullable Integer limit); ImmutableList<SimpleEntry<Long, String>> getSecretsNameOnly(); ImmutableList<SecretSeriesAndContent> getSecretsBatched(int idx, int num,
      boolean newestFirst); Optional<ImmutableList<SanitizedSecret>> getSecretVersionsByName(String name,
      int versionIdx, int numVersions); void setCurrentSecretVersionByName(String name, long versionId, String updater); void deleteSecretsByName(String name); int countDeletedSecrets(); int countSecretsDeletedBeforeDate(DateTime deleteBefore); void dangerPermanentlyRemoveSecretsDeletedBeforeDate(DateTime deletedBefore,
      int sleepMillis);  }
@Test public void getSecretByName() { String name = secret2b.series().name(); assertThat(secretDAO.getSecretByName(name)).contains(secret2b); }
@Test public void getSecretByNameOneReturnsEmptyWhenCurrentVersionIsNull() { String name = secret1.series().name(); jooqContext.update(SECRETS) .set(SECRETS.CURRENT, (Long) null) .where(SECRETS.ID.eq(series1.id())) .execute(); assertThat(secretDAO.getSecretByName(name)).isEmpty(); }