private Attraction extractAtraction(ResultSet rs) throws SQLException { Attraction attraction = new Attraction(); attraction.setId(rs.getInt(DbTables.Attraction.ID)); attraction.setTitle(rs.getString(DbTables.Attraction.TITLE)); attraction.setDescription(rs.getString(DbTables.Attraction.DESC)); attraction.setHeight(rs.getInt(DbTables.Attraction.HEIGHT)); attraction.setImage(rs.getString(DbTables.Attraction.PICTURE)); attraction.setAdultPrice(rs.getInt(DbTables.Attraction.ADULT_PRICE)); attraction.setChildPrice(rs.getInt(DbTables.Attraction.CHILD_PRICE)); return attraction; }
@Override public void deleteAttraction(Attraction attraction) { Connection con = MySQLConnection.getWebInstance(); try (PreparedStatement pstm = con.prepareStatement(DELETE_ATTRACTION)) { pstm.setInt(1, attraction.getId()); pstm.executeUpdate(); } catch (SQLException ex) { rollback(con); throw new DBLayerException("Failed to delete attraction" + attraction, ex); } finally { commit(con); } }
@Override public void addAttraction(Attraction attraction) { Connection con = MySQLConnection.getWebInstance(); try (PreparedStatement pstm = con.prepareStatement(ADD_ATTRACTION)) { int k = 1; pstm.setString(k++, attraction.getTitle()); pstm.setString(k++, attraction.getDescription()); pstm.setInt(k++, attraction.getHeight()); pstm.setString(k++, attraction.getImage()); pstm.setInt(k++, attraction.getAdultPrice()); pstm.setInt(k++, attraction.getChildPrice()); pstm.executeUpdate(); } catch (SQLException ex) { rollback(con); throw new DBLayerException("Failed to add attraction" + attraction, ex); } finally { commit(con); } }