| 1 | package model.misura; | |
| 2 | ||
| 3 | import model.DBConnection; | |
| 4 | import model.acquisto.AcquistoBean; | |
| 5 | import javax.sql.DataSource; | |
| 6 | import java.sql.Connection; | |
| 7 | import java.sql.PreparedStatement; | |
| 8 | import java.sql.ResultSet; | |
| 9 | import java.sql.SQLException; | |
| 10 | import java.util.ArrayList; | |
| 11 | import java.util.Collection; | |
| 12 | ||
| 13 | public class MisuraDAO { | |
| 14 | private static final String TABLE_NAME = "Misura"; | |
| 15 | private static DataSource ds; | |
| 16 | ||
| 17 | public MisuraDAO() { | |
| 18 | ds = DBConnection.getDataSource(); | |
| 19 | } | |
| 20 | ||
| 21 | public MisuraDAO(DataSource ds) { | |
| 22 | MisuraDAO.ds = ds; | |
| 23 | } | |
| 24 | ||
| 25 | public void doSave(MisuraBean product) throws SQLException { | |
| 26 | String query = "INSERT INTO " + TABLE_NAME + " (IDMaglietta, taglia, quantita)" + " VALUES (?, ?, ?)"; | |
| 27 | ||
| 28 | try (Connection connection = ds.getConnection(); PreparedStatement preparedStatement = connection.prepareStatement(query)) { | |
| 29 |
1
1. doSave : removed call to java/sql/PreparedStatement::setInt → KILLED |
preparedStatement.setInt(1, product.getIDMaglietta()); |
| 30 |
1
1. doSave : removed call to java/sql/PreparedStatement::setString → KILLED |
preparedStatement.setString(2, product.getTaglia()); |
| 31 |
1
1. doSave : removed call to java/sql/PreparedStatement::setInt → KILLED |
preparedStatement.setInt(3, product.getQuantita()); |
| 32 | ||
| 33 | preparedStatement.executeUpdate(); | |
| 34 | } | |
| 35 | } | |
| 36 | ||
| 37 | public void doUpdate(MisuraBean misuraBean) throws SQLException { | |
| 38 | String query = "UPDATE " + TABLE_NAME + | |
| 39 | " SET quantita = ?" + | |
| 40 | " WHERE IDMaglietta = ? AND taglia = ?"; | |
| 41 | ||
| 42 | try (Connection connection = ds.getConnection(); PreparedStatement preparedStatement = connection.prepareStatement(query)) { | |
| 43 |
1
1. doUpdate : removed call to java/sql/PreparedStatement::setInt → KILLED |
preparedStatement.setInt(1, misuraBean.getQuantita()); |
| 44 |
1
1. doUpdate : removed call to java/sql/PreparedStatement::setInt → KILLED |
preparedStatement.setInt(2, misuraBean.getIDMaglietta()); |
| 45 |
1
1. doUpdate : removed call to java/sql/PreparedStatement::setString → KILLED |
preparedStatement.setString(3, misuraBean.getTaglia()); |
| 46 | ||
| 47 | preparedStatement.executeUpdate(); | |
| 48 | } | |
| 49 | } | |
| 50 | ||
| 51 | public void doUpdateUtente(AcquistoBean product, String taglia) throws SQLException { | |
| 52 | String query = "UPDATE " + TABLE_NAME + | |
| 53 | " SET quantita = quantita - ? " + | |
| 54 | "WHERE IDMaglietta = ? AND taglia = ?"; | |
| 55 | ||
| 56 | try (Connection connection = ds.getConnection(); PreparedStatement preparedStatement = connection.prepareStatement(query)) { | |
| 57 |
1
1. doUpdateUtente : removed call to java/sql/PreparedStatement::setInt → KILLED |
preparedStatement.setInt(1, product.getQuantita()); |
| 58 |
1
1. doUpdateUtente : removed call to java/sql/PreparedStatement::setInt → KILLED |
preparedStatement.setInt(2, product.getIDMaglietta()); |
| 59 |
1
1. doUpdateUtente : removed call to java/sql/PreparedStatement::setString → KILLED |
preparedStatement.setString(3, taglia); |
| 60 | ||
| 61 | preparedStatement.executeUpdate(); | |
| 62 | } | |
| 63 | } | |
| 64 | ||
| 65 | public Collection<MisuraBean> doRetrieveAll(int idMaglietta) throws SQLException { | |
| 66 | Collection<MisuraBean> misure = new ArrayList<>(); | |
| 67 | ||
| 68 | String query = "SELECT * FROM " + TABLE_NAME + " WHERE idMaglietta = ?"; | |
| 69 | ||
| 70 | try (Connection connection = ds.getConnection(); | |
| 71 | PreparedStatement preparedStatement = connection.prepareStatement(query)) { | |
| 72 | ||
| 73 |
1
1. doRetrieveAll : removed call to java/sql/PreparedStatement::setInt → KILLED |
preparedStatement.setInt(1, idMaglietta); |
| 74 | ||
| 75 | try (ResultSet resultSet = preparedStatement.executeQuery()) { | |
| 76 |
1
1. doRetrieveAll : negated conditional → TIMED_OUT |
while (resultSet.next()) { |
| 77 | MisuraBean misuraBean = new MisuraBean(); | |
| 78 |
1
1. doRetrieveAll : removed call to model/misura/MisuraDAO::setMisura → KILLED |
setMisura(resultSet, misuraBean); |
| 79 | misure.add(misuraBean); | |
| 80 | } | |
| 81 | } | |
| 82 | } | |
| 83 | ||
| 84 |
1
1. doRetrieveAll : replaced return value with Collections.emptyList for model/misura/MisuraDAO::doRetrieveAll → KILLED |
return misure; |
| 85 | } | |
| 86 | ||
| 87 | private void setMisura(ResultSet resultSet, MisuraBean misuraBean) throws SQLException { | |
| 88 |
1
1. setMisura : removed call to model/misura/MisuraBean::setIDMaglietta → KILLED |
misuraBean.setIDMaglietta(resultSet.getInt("IDMaglietta")); |
| 89 |
1
1. setMisura : removed call to model/misura/MisuraBean::setTaglia → KILLED |
misuraBean.setTaglia(resultSet.getString("taglia")); |
| 90 |
1
1. setMisura : removed call to model/misura/MisuraBean::setQuantita → KILLED |
misuraBean.setQuantita(resultSet.getInt("quantita")); |
| 91 | } | |
| 92 | } | |
Mutations | ||
| 29 |
1.1 |
|
| 30 |
1.1 |
|
| 31 |
1.1 |
|
| 43 |
1.1 |
|
| 44 |
1.1 |
|
| 45 |
1.1 |
|
| 57 |
1.1 |
|
| 58 |
1.1 |
|
| 59 |
1.1 |
|
| 73 |
1.1 |
|
| 76 |
1.1 |
|
| 78 |
1.1 |
|
| 84 |
1.1 |
|
| 88 |
1.1 |
|
| 89 |
1.1 |
|
| 90 |
1.1 |