| 1 | package model.acquisto; | |
| 2 | ||
| 3 | import model.DAOInterface; | |
| 4 | import model.DBConnection; | |
| 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 AcquistoDAO implements DAOInterface<AcquistoBean, Integer> { | |
| 14 | private static final String TABLE_NAME = "Acquisto"; | |
| 15 | private static DataSource ds; | |
| 16 | ||
| 17 | public AcquistoDAO() { | |
| 18 | ds = DBConnection.getDataSource(); | |
| 19 | } | |
| 20 | ||
| 21 | public AcquistoDAO(DataSource ds) { | |
| 22 | AcquistoDAO.ds = ds; | |
| 23 | } | |
| 24 | ||
| 25 | @Override | |
| 26 | public AcquistoBean doRetrieveByKey(Integer code) throws SQLException { | |
| 27 | AcquistoBean acquistoBean = new AcquistoBean(); | |
| 28 | ||
| 29 | String query = "SELECT * FROM " + TABLE_NAME + " WHERE IDAcquisto = ?"; | |
| 30 | ||
| 31 | try (Connection connection = ds.getConnection(); PreparedStatement preparedStatement = connection.prepareStatement(query)) { | |
| 32 |
1
1. doRetrieveByKey : removed call to java/sql/PreparedStatement::setInt → KILLED |
preparedStatement.setInt(1, code); |
| 33 | ResultSet resultSet = preparedStatement.executeQuery(); | |
| 34 | ||
| 35 |
1
1. doRetrieveByKey : removed call to model/acquisto/AcquistoDAO::setAcquisto → KILLED |
setAcquisto(resultSet, acquistoBean); |
| 36 | } | |
| 37 | ||
| 38 |
1
1. doRetrieveByKey : replaced return value with null for model/acquisto/AcquistoDAO::doRetrieveByKey → KILLED |
return acquistoBean; |
| 39 | } | |
| 40 | ||
| 41 | public Collection<AcquistoBean> doRetrieveByOrdine(Integer codeOrdini) throws SQLException { | |
| 42 | Collection<AcquistoBean> acquisti = new ArrayList<>(); | |
| 43 | ||
| 44 | String query = "SELECT * FROM " + TABLE_NAME + " WHERE IDOrdine = ?"; | |
| 45 | ||
| 46 | try (Connection connection = ds.getConnection(); PreparedStatement preparedStatement = connection.prepareStatement(query)) { | |
| 47 |
1
1. doRetrieveByOrdine : removed call to java/sql/PreparedStatement::setInt → KILLED |
preparedStatement.setInt(1, codeOrdini); |
| 48 | ResultSet resultSet = preparedStatement.executeQuery(); | |
| 49 | ||
| 50 |
1
1. doRetrieveByOrdine : negated conditional → TIMED_OUT |
while (resultSet.next()) { |
| 51 | AcquistoBean acquistoBean = new AcquistoBean(); | |
| 52 |
1
1. doRetrieveByOrdine : removed call to model/acquisto/AcquistoDAO::setAcquisto → KILLED |
setAcquisto(resultSet, acquistoBean); |
| 53 | acquisti.add(acquistoBean); | |
| 54 | } | |
| 55 | } | |
| 56 | ||
| 57 |
1
1. doRetrieveByOrdine : replaced return value with Collections.emptyList for model/acquisto/AcquistoDAO::doRetrieveByOrdine → KILLED |
return acquisti; |
| 58 | } | |
| 59 | ||
| 60 | @Override | |
| 61 | public Collection<AcquistoBean> doRetriveAll(String order) { | |
| 62 |
1
1. doRetriveAll : replaced return value with Collections.emptyList for model/acquisto/AcquistoDAO::doRetriveAll → KILLED |
return new ArrayList<>(); |
| 63 | } | |
| 64 | ||
| 65 | @Override | |
| 66 | public void doSave(AcquistoBean acquistoBean) throws SQLException { | |
| 67 | String query = "INSERT INTO " + TABLE_NAME + " (IDOrdine, IDMaglietta, quantita, immagine, prezzoAq, ivaAq, taglia) "+ | |
| 68 | "VALUES(?, ?, ?, ?, ?, ?, ?)"; | |
| 69 | ||
| 70 | try (Connection connection = ds.getConnection(); PreparedStatement preparedStatement = connection.prepareStatement(query)) { | |
| 71 |
1
1. doSave : removed call to model/acquisto/AcquistoDAO::setAcquistoStatement → KILLED |
setAcquistoStatement(acquistoBean, preparedStatement); |
| 72 | ||
| 73 | preparedStatement.executeUpdate(); | |
| 74 | } | |
| 75 | ||
| 76 | } | |
| 77 | ||
| 78 | @Override | |
| 79 | public void doUpdate(AcquistoBean product) { | |
| 80 | // Update operation is not supported for Acquisto entities | |
| 81 | } | |
| 82 | ||
| 83 | @Override | |
| 84 | public boolean doDelete(Integer code) { | |
| 85 |
1
1. doDelete : replaced boolean return with true for model/acquisto/AcquistoDAO::doDelete → KILLED |
return false; |
| 86 | } | |
| 87 | ||
| 88 | private void setAcquisto(ResultSet resultSet, AcquistoBean acquistoBean) throws SQLException { | |
| 89 |
1
1. setAcquisto : removed call to model/acquisto/AcquistoBean::setIDAcquisto → KILLED |
acquistoBean.setIDAcquisto(resultSet.getInt("IDAcquisto")); |
| 90 |
1
1. setAcquisto : removed call to model/acquisto/AcquistoBean::setIDOrdine → KILLED |
acquistoBean.setIDOrdine(resultSet.getInt("IDOrdine")); |
| 91 |
1
1. setAcquisto : removed call to model/acquisto/AcquistoBean::setIDMaglietta → KILLED |
acquistoBean.setIDMaglietta(resultSet.getInt("IDMaglietta")); |
| 92 |
1
1. setAcquisto : removed call to model/acquisto/AcquistoBean::setQuantita → KILLED |
acquistoBean.setQuantita(resultSet.getInt("quantita")); |
| 93 |
1
1. setAcquisto : removed call to model/acquisto/AcquistoBean::setImmagine → KILLED |
acquistoBean.setImmagine(resultSet.getString("immagine")); |
| 94 |
1
1. setAcquisto : removed call to model/acquisto/AcquistoBean::setPrezzoAq → KILLED |
acquistoBean.setPrezzoAq(resultSet.getFloat("prezzoAq")); |
| 95 |
1
1. setAcquisto : removed call to model/acquisto/AcquistoBean::setIvaAq → KILLED |
acquistoBean.setIvaAq(resultSet.getInt("ivaAq")); |
| 96 |
1
1. setAcquisto : removed call to model/acquisto/AcquistoBean::setTaglia → KILLED |
acquistoBean.setTaglia(resultSet.getString("taglia")); |
| 97 | } | |
| 98 | ||
| 99 | private void setAcquistoStatement(AcquistoBean acquistoBean, PreparedStatement preparedStatement) throws SQLException { | |
| 100 |
1
1. setAcquistoStatement : removed call to java/sql/PreparedStatement::setInt → KILLED |
preparedStatement.setInt(1, acquistoBean.getIDOrdine()); |
| 101 |
1
1. setAcquistoStatement : removed call to java/sql/PreparedStatement::setInt → KILLED |
preparedStatement.setInt(2, acquistoBean.getIDMaglietta()); |
| 102 |
1
1. setAcquistoStatement : removed call to java/sql/PreparedStatement::setInt → KILLED |
preparedStatement.setInt(3, acquistoBean.getQuantita()); |
| 103 |
1
1. setAcquistoStatement : removed call to java/sql/PreparedStatement::setString → KILLED |
preparedStatement.setString(4, acquistoBean.getImmagine()); |
| 104 |
1
1. setAcquistoStatement : removed call to java/sql/PreparedStatement::setFloat → KILLED |
preparedStatement.setFloat(5, acquistoBean.getPrezzoAq()); |
| 105 |
1
1. setAcquistoStatement : removed call to java/sql/PreparedStatement::setInt → KILLED |
preparedStatement.setInt(6, acquistoBean.getIvaAq()); |
| 106 |
1
1. setAcquistoStatement : removed call to java/sql/PreparedStatement::setString → KILLED |
preparedStatement.setString(7, acquistoBean.getTaglia()); |
| 107 | } | |
| 108 | } | |
Mutations | ||
| 32 |
1.1 |
|
| 35 |
1.1 |
|
| 38 |
1.1 |
|
| 47 |
1.1 |
|
| 50 |
1.1 |
|
| 52 |
1.1 |
|
| 57 |
1.1 |
|
| 62 |
1.1 |
|
| 71 |
1.1 |
|
| 85 |
1.1 |
|
| 89 |
1.1 |
|
| 90 |
1.1 |
|
| 91 |
1.1 |
|
| 92 |
1.1 |
|
| 93 |
1.1 |
|
| 94 |
1.1 |
|
| 95 |
1.1 |
|
| 96 |
1.1 |
|
| 100 |
1.1 |
|
| 101 |
1.1 |
|
| 102 |
1.1 |
|
| 103 |
1.1 |
|
| 104 |
1.1 |
|
| 105 |
1.1 |
|
| 106 |
1.1 |