/**
   * Trouve tous les livres.
   *
   * @return La liste des livres; une liste vide sinon
   * @throws DAOException S'il y a une erreur avec la base de données
   */
  public List<LivreDTO> getAll() throws DAOException {

    List<LivreDTO> listeDTO = Collections.EMPTY_LIST;

    LivreDTO livreDTO = null;
    try (PreparedStatement getAllPreparedStatement =
            getConnection().prepareStatement(LivreDAO.GET_ALL_REQUEST);
        ResultSet resultSet = getAllPreparedStatement.executeQuery(); ) {

      if (resultSet.next()) {
        listeDTO = new ArrayList<>();
        do {
          livreDTO = new LivreDTO();
          livreDTO.setIdLivre(resultSet.getInt(1));
          livreDTO.setTitre(resultSet.getString(2));
          livreDTO.setAuteur(resultSet.getString(3));
          livreDTO.setDateAcquisition(resultSet.getTimestamp(4));
          listeDTO.add(livreDTO);
        } while (resultSet.next());
      }

    } catch (final SQLException sqlException) {
      throw new DAOException(sqlException);
    }
    return listeDTO;
  }
  /**
   * Trouve les livres à partir d'un titre.
   *
   * @param livreDTO Le livre qui a le titre à utiliser
   * @return La liste des livres correspondants; une liste vide sinon
   * @throws DAOException S'il y a une erreur avec la base de données
   */
  public List<LivreDTO> findByTitre(LivreDTO livreDTO) throws DAOException {

    List<LivreDTO> listeLivres = Collections.EMPTY_LIST;
    LivreDTO livreAvecTitre = null;

    try (PreparedStatement findByTitrePreparedStatement =
        getConnection().prepareStatement(LivreDAO.FIND_BY_TITRE_REQUEST); ) {
      findByTitrePreparedStatement.setString(1, "%" + livreDTO.getTitre() + "%");
      try (ResultSet rset = findByTitrePreparedStatement.executeQuery(); ) {
        if (rset.next()) {
          listeLivres = new ArrayList<>();
          do {
            livreAvecTitre = new LivreDTO();
            livreAvecTitre.setIdLivre(rset.getInt(1));
            livreAvecTitre.setTitre(rset.getString(2));
            livreAvecTitre.setAuteur(rset.getString(3));
            livreAvecTitre.setDateAcquisition(rset.getTimestamp(4));
            listeLivres.add(livreAvecTitre);
          } while (rset.next());
        }
      }
    } catch (final SQLException sqlException) {
      throw new DAOException(sqlException);
    }
    return listeLivres;
  }
  /**
   * Lit un livre.
   *
   * @param idLivre L'ID du livre à lire
   * @return Le livre lu
   * @throws DAOException S'il y a une erreur dans la base de données
   */
  public LivreDTO read(int idLivre) throws DAOException {

    LivreDTO livreDTO = null;

    try (PreparedStatement readPreparedStatement =
        getConnection().prepareStatement(LivreDAO.READ_REQUEST)) {
      readPreparedStatement.setInt(1, idLivre);
      try (ResultSet resultSet = readPreparedStatement.executeQuery()) {
        if (resultSet.next()) {
          livreDTO = new LivreDTO();
          livreDTO.setIdLivre(resultSet.getInt(1));
          livreDTO.setTitre(resultSet.getString(2));
          livreDTO.setAuteur(resultSet.getString(3));
          livreDTO.setDateAcquisition(resultSet.getTimestamp(4));
        }
      }

    } catch (final SQLException sqlException) {
      throw new DAOException(sqlException);
    }
    return livreDTO;
  }