Example #1
0
 private ServicePrice constructPriceEntity(ResultSet rs) throws SQLException {
   ServicePrice servicePrice = new ServicePrice();
   servicePrice.setPrice(rs.getBigDecimal("price"));
   servicePrice.setServiceId(rs.getInt("service_id"));
   servicePrice.setDate(rs.getDate("date").toLocalDate());
   return servicePrice;
 }
Example #2
0
  public void deleteServicePrice(ServicePrice servicePrice) {
    try {
      PreparedStatement preparedStatement =
          getConnection()
              .prepareStatement(
                  "DELETE FROM  \"service_price\" where \"service_id\" = ? AND \"date\" = ?");
      preparedStatement.setInt(1, servicePrice.getServiceId());
      preparedStatement.setDate(2, Date.valueOf(servicePrice.getDate()));
      preparedStatement.executeUpdate();

    } catch (SQLException ex) {
      ex.printStackTrace();
      throw new DAOException();
    }
  }
Example #3
0
  public void saveServicePrice(ServicePrice servicePrice) {
    try {
      PreparedStatement preparedStatement =
          getConnection()
              .prepareStatement(
                  "INSERT INTO \"service_price\" (\"service_id\", \"date\", \"price\") VALUES(?, ?, ?)");
      preparedStatement.setInt(1, servicePrice.getServiceId());
      preparedStatement.setDate(2, Date.valueOf(servicePrice.getDate()));
      preparedStatement.setBigDecimal(3, servicePrice.getPrice());
      preparedStatement.executeUpdate();

    } catch (SQLException ex) {
      ex.printStackTrace();
      throw new DAOException();
    }
  }
Example #4
0
  public List<ServicePrice> getServicePricesByServiceId(int serviceId) {
    List<ServicePrice> servicePrices = new ArrayList<>();
    try {
      PreparedStatement preparedStatement =
          getConnection()
              .prepareStatement("SELECT * FROM \"service_price\" where \"service_id\" = ?");
      preparedStatement.setInt(1, serviceId);
      ResultSet rs = preparedStatement.executeQuery();
      while (rs.next()) {
        ServicePrice servicePrice = new ServicePrice();
        servicePrice.setServiceId(rs.getInt("service_id"));
        servicePrice.setPrice(rs.getBigDecimal("price"));
        servicePrice.setDate(rs.getDate("date").toLocalDate());
        servicePrices.add(servicePrice);
      }

    } catch (SQLException ex) {
      ex.printStackTrace();
      throw new DAOException();
    }

    return servicePrices;
  }