Example #1
0
  /** {@inheritDoc} */
  @Override
  public void update(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 updatePreparedStatement =
        connexion.getConnection().prepareStatement(PretDAO.UPDATE_REQUEST)) {

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

      updatePreparedStatement.executeUpdate();
    } catch (final SQLException sqlException) {
      throw new DAOException(sqlException);
    }
  }
Example #2
0
  /** {@inheritDoc} */
  @Override
  public void delete(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 deletePreparedStatement =
        connexion.getConnection().prepareStatement(PretDAO.DELETE_REQUEST)) {

      deletePreparedStatement.setString(1, pretDTO.getIdPret());

      deletePreparedStatement.executeUpdate();
    } catch (final SQLException sqlException) {
      throw new DAOException(sqlException);
    }
  }
 /** {@inheritDoc} */
 @Override
 public void delete(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 statementRead =
       (connexion.getConnection().prepareStatement(PretDAO.DELETE_REQUEST))) {
     statementRead.setString(1, pretDTO.getIdPret());
     statementRead.executeUpdate();
   } catch (SQLException sqlException) {
     throw new DAOException(
         Integer.toString(sqlException.getErrorCode()) + " " + sqlException.getMessage(),
         sqlException);
   }
 }
Example #4
0
  /**
   * Supprime un pret.
   *
   * @param pretDTO Le pret à supprimer
   * @throws DAOException S'il y a une erreur dans la base de données
   */
  public void delete(PretDTO pretDTO) throws DAOException {
    try (PreparedStatement deletePreparedStatement =
        getConnection().prepareStatement(PretDAO.DELETE_REQUEST)) {

      deletePreparedStatement.setInt(1, pretDTO.getIdPret());

      deletePreparedStatement.executeUpdate();
    } catch (final SQLException sqlException) {
      throw new DAOException(sqlException);
    }
  }
 /** {@inheritDoc} */
 @Override
 public boolean equals(Object obj) {
   boolean equals = this == obj;
   if (!equals) {
     equals = obj != null && obj instanceof PretDTO;
     if (equals) {
       PretDTO pretDTO = (PretDTO) obj;
       EqualsBuilder equalsBuilder = new EqualsBuilder();
       equalsBuilder.appendSuper(super.equals(pretDTO));
       equalsBuilder.append(getIdPret(), pretDTO.getIdPret());
       equals = equalsBuilder.isEquals();
     }
   }
   return equals;
 }
Example #6
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;
  }