Ejemplo n.º 1
0
  /** {@inheritDoc} */
  @Override
  public void add(Connexion connexion, DTO dto)
      throws InvalidHibernateSessionException, InvalidDTOException, InvalidDTOClassException,
          DAOException {

    if (connexion == null) {
      throw new InvalidHibernateSessionException("La connexion ne peut être null");
    }
    if (dto == null) {
      throw new InvalidDTOException("Le DTO ne peut être null");
    }
    if (!dto.getClass().equals(getDtoClass())) {
      throw new InvalidDTOClassException("Le DTO doit être un " + getDtoClass().getName());
    }
    final PretDTO pretDTO = (PretDTO) dto;
    try (PreparedStatement addPreparedStatement =
        connexion.getConnection().prepareStatement(PretDAO.ADD_REQUEST)) {

      addPreparedStatement.setString(1, pretDTO.getMembreDTO().getIdMembre());
      addPreparedStatement.setString(2, pretDTO.getLivreDTO().getIdLivre());
      addPreparedStatement.setTimestamp(3, pretDTO.getDatePret());
      addPreparedStatement.setTimestamp(4, pretDTO.getDateRetour());

      addPreparedStatement.executeUpdate();
    } catch (final SQLException sqlException) {
      throw new DAOException(sqlException);
    }
  }
Ejemplo n.º 2
0
  /** {@inheritDoc} */
  @Override
  public void add(Connexion connexion, DTO dto)
      throws DAOException, InvalidHibernateSessionException, InvalidDTOException,
          InvalidDTOClassException {
    if (connexion == null) {
      throw new InvalidHibernateSessionException("La connexion ne peut être null");
    }
    if (dto == null) {
      throw new InvalidDTOException("Le DTO ne peut être null");
    }
    if (!dto.getClass().equals(getDtoClass())) {
      throw new InvalidDTOClassException(
          "Le DTO doit être de la classe " + getDtoClass().getName());
    }
    PretDTO pretDTO = (PretDTO) dto;

    try (PreparedStatement statementAdd =
        (connexion.getConnection().prepareStatement(PretDAO.ADD_REQUEST))) {

      statementAdd.setString(1, pretDTO.getMembreDTO().getIdMembre());
      statementAdd.setString(2, pretDTO.getLivreDTO().getIdLivre());
      statementAdd.setTimestamp(3, pretDTO.getDatePret());
      statementAdd.executeUpdate();

    } catch (SQLException sqlException) {
      throw new DAOException(
          Integer.toString(sqlException.getErrorCode()) + " " + sqlException.getMessage(),
          sqlException);
    }
  }
Ejemplo n.º 3
0
  /**
   * Ajoute un nouveau pret.
   *
   * @param pretDTO Le pret à ajouter
   * @throws DAOException S'il y a une erreur avec la base de données
   */
  public void add(PretDTO pretDTO) throws DAOException {
    try (PreparedStatement addPreparedStatement =
        getConnection().prepareStatement(PretDAO.ADD_REQUEST)) {

      addPreparedStatement.setInt(1, pretDTO.getMembreDTO().getIdMembre());
      addPreparedStatement.setInt(2, pretDTO.getLivreDTO().getIdLivre());
      addPreparedStatement.setTimestamp(3, pretDTO.getDatePret());
      addPreparedStatement.setTimestamp(4, pretDTO.getDateRetour());

      addPreparedStatement.executeUpdate();
    } catch (final SQLException sqlException) {
      throw new DAOException(sqlException);
    }
  }
Ejemplo n.º 4
0
  /**
   * Met à jour un pret.
   *
   * @param pretDTO Le pret à mettre à jour
   * @return Le nombre de lignes affectées par la modification
   * @throws DAOException S'il y a une erreur dans la base de données
   */
  public int update(PretDTO pretDTO) throws DAOException {
    int result = 0;
    try (PreparedStatement updatePreparedStatement =
        getConnection().prepareStatement(PretDAO.UPDATE_REQUEST)) {

      updatePreparedStatement.setInt(1, pretDTO.getMembreDTO().getIdMembre());
      updatePreparedStatement.setInt(2, pretDTO.getLivreDTO().getIdLivre());
      updatePreparedStatement.setTimestamp(3, pretDTO.getDatePret());
      updatePreparedStatement.setTimestamp(4, pretDTO.getDateRetour());
      updatePreparedStatement.setInt(5, pretDTO.getIdPret());

      result = updatePreparedStatement.executeUpdate();
    } catch (final SQLException sqlException) {
      throw new DAOException(sqlException);
    }

    return result;
  }