private DatasetVersionRecord executeGetLatestVersionStatementForDownload(PreparedStatement statement, int accountId,
      int containerId, String datasetName, Dataset.VersionSchema versionSchema)
      throws SQLException, AccountServiceException {
    ResultSet resultSet = null;
    String version;
    Timestamp deletionTime;
    String renameFrom;
    try {
      statement.setInt(1, accountId);
      statement.setInt(2, containerId);
      statement.setString(3, datasetName);
      statement.setInt(4, DatasetVersionState.READY.ordinal());
      resultSet = statement.executeQuery();
      if (!resultSet.next()) {
        throw new AccountServiceException(
            "Latest version not found for account: " + accountId + " container: " + containerId + " dataset: "
                + datasetName, AccountServiceErrorCode.NotFound);
      }
      long versionValue = resultSet.getLong(VERSION);
      version = convertVersionValueToVersion(versionValue, versionSchema);
      renameFrom = resultSet.getString(RENAME_FROM);
      deletionTime = resultSet.getTimestamp(DELETED_TS);
    } finally {
      closeQuietly(resultSet);
    }
    return new DatasetVersionRecord(accountId, containerId, datasetName, version, timestampToMs(deletionTime),
        renameFrom);
  }
Execute the getLatestVersionSqlForDownload statement.
@param statement the statement to list the latest version.
@param accountId the id for the parent account.
@param containerId the id of the container.
@param datasetName the name of the dataset.
@return the latest version of the dataset.
@throws SQLException
ambry-account/src/main/java/com/github/ambry/account/mysql/DatasetDao.java