/**
   * Returns the ReplicaStoreState of a given file in a specific replica.
   *
   * @param filename The name of the file for the ReplicaStoreState.
   * @param replicaChannelName The name of the identification channel for uniquely identifying the
   *     replica of for the ReplicaStoreState.
   * @return The ReplicaStoreState of a given file in a specific replica.
   * @throws ArgumentNotValid If the filename or the replica id is null or the empty string.
   */
  @Override
  public ReplicaStoreState getState(String filename, String replicaChannelName)
      throws ArgumentNotValid {
    ArgumentNotValid.checkNotNullOrEmpty(filename, "String filename");
    ArgumentNotValid.checkNotNullOrEmpty(replicaChannelName, "String replicaChannelName");

    Replica rep = Channels.retrieveReplicaFromIdentifierChannel(replicaChannelName);

    // retrieve the ReplicaStoreState from the database.
    return database.getReplicaStoreState(filename, rep.getId());
  }
  /**
   * Sets the store state of an entry to a specific value.
   *
   * @param filename The name of the file for the entry.
   * @param repChannelId The identification channel of the replica for the entry.
   * @param state The new state for the entry.
   * @throws ArgumentNotValid If the ReplicaStoreState is null, or if either the filename or the
   *     replica identification channel is either null or the empty string.
   */
  @Override
  public void setState(String filename, String repChannelId, ReplicaStoreState state)
      throws ArgumentNotValid {
    ArgumentNotValid.checkNotNull(state, "ReplicaStoreState state");
    ArgumentNotValid.checkNotNullOrEmpty(filename, "String filename");
    ArgumentNotValid.checkNotNullOrEmpty(repChannelId, "String repChannelId");

    // retrieve the replica
    Replica rep = Channels.retrieveReplicaFromIdentifierChannel(repChannelId);

    // update the database.
    database.setReplicaStoreState(filename, rep.getId(), state);
  }
  /**
   * Determines whether a given file in a specific replica has a valid replica store state. By valid
   * means a replica store state other that UNKNOWN_UPLOAD_STATE.
   *
   * <p>TODO Find out if the assumption that all upload states besides UNKNOWN_UPLOAD_STATE are
   * acceptable!
   *
   * @param filename The name of the file for the ReplicaStoreState.
   * @param repChannelId The identification channel of the replica for the ReplicaStoreState.
   * @return Whether a given file in a specific replica has a valid store state.
   * @throws ArgumentNotValid If either the filenames or the replica identification channel is null
   *     or the empty string.
   */
  @Override
  public boolean hasState(String filename, String repChannelId) throws ArgumentNotValid {
    ArgumentNotValid.checkNotNullOrEmpty(filename, "String filename");
    ArgumentNotValid.checkNotNullOrEmpty(repChannelId, "String repChannelId");

    // retrieve the replica
    Replica rep = Channels.retrieveReplicaFromIdentifierChannel(repChannelId);

    // retrieve the state for the entry for the replica and filename
    ReplicaStoreState state = database.getReplicaStoreState(filename, rep.getId());

    // return whether the entry has a known upload state
    return state != ReplicaStoreState.UNKNOWN_UPLOAD_STATE;
  }