AcquistoDAO.java

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
Location : doRetrieveByKey
Killed by : model.acquisto.AcquistoDAOTest.[engine:junit-jupiter]/[class:model.acquisto.AcquistoDAOTest]/[method:doRetrieveByKey_ok_setsFields()]
removed call to java/sql/PreparedStatement::setInt → KILLED

35

1.1
Location : doRetrieveByKey
Killed by : model.acquisto.AcquistoDAOTest.[engine:junit-jupiter]/[class:model.acquisto.AcquistoDAOTest]/[method:doRetrieveByKey_ok_setsFields()]
removed call to model/acquisto/AcquistoDAO::setAcquisto → KILLED

38

1.1
Location : doRetrieveByKey
Killed by : model.acquisto.AcquistoDAOTest.[engine:junit-jupiter]/[class:model.acquisto.AcquistoDAOTest]/[method:doRetrieveByKey_ok_setsFields()]
replaced return value with null for model/acquisto/AcquistoDAO::doRetrieveByKey → KILLED

47

1.1
Location : doRetrieveByOrdine
Killed by : model.acquisto.AcquistoDAOTest.[engine:junit-jupiter]/[class:model.acquisto.AcquistoDAOTest]/[method:doRetrieveByOrdine_zeroRighe_returnsEmpty()]
removed call to java/sql/PreparedStatement::setInt → KILLED

50

1.1
Location : doRetrieveByOrdine
Killed by : none
negated conditional → TIMED_OUT

52

1.1
Location : doRetrieveByOrdine
Killed by : model.acquisto.AcquistoDAOTest.[engine:junit-jupiter]/[class:model.acquisto.AcquistoDAOTest]/[method:doRetrieveByOrdine_dueRighe_valuesAreMapped()]
removed call to model/acquisto/AcquistoDAO::setAcquisto → KILLED

57

1.1
Location : doRetrieveByOrdine
Killed by : model.acquisto.AcquistoDAOTest.[engine:junit-jupiter]/[class:model.acquisto.AcquistoDAOTest]/[method:doRetrieveByOrdine_dueRighe_valuesAreMapped()]
replaced return value with Collections.emptyList for model/acquisto/AcquistoDAO::doRetrieveByOrdine → KILLED

62

1.1
Location : doRetriveAll
Killed by : model.acquisto.AcquistoDAOTest.[engine:junit-jupiter]/[class:model.acquisto.AcquistoDAOTest]/[method:doRetriveAll_returnsModifiableEmptyList()]
replaced return value with Collections.emptyList for model/acquisto/AcquistoDAO::doRetriveAll → KILLED

71

1.1
Location : doSave
Killed by : model.acquisto.AcquistoDAOTest.[engine:junit-jupiter]/[class:model.acquisto.AcquistoDAOTest]/[method:doSave_ok_setsAllParamsAndExecutes()]
removed call to model/acquisto/AcquistoDAO::setAcquistoStatement → KILLED

85

1.1
Location : doDelete
Killed by : model.acquisto.AcquistoDAOTest.[engine:junit-jupiter]/[class:model.acquisto.AcquistoDAOTest]/[method:doDelete_alwaysFalse()]
replaced boolean return with true for model/acquisto/AcquistoDAO::doDelete → KILLED

89

1.1
Location : setAcquisto
Killed by : model.acquisto.AcquistoDAOTest.[engine:junit-jupiter]/[class:model.acquisto.AcquistoDAOTest]/[method:setAcquisto_ok_setsAllFields()]
removed call to model/acquisto/AcquistoBean::setIDAcquisto → KILLED

90

1.1
Location : setAcquisto
Killed by : model.acquisto.AcquistoDAOTest.[engine:junit-jupiter]/[class:model.acquisto.AcquistoDAOTest]/[method:setAcquisto_ok_setsAllFields()]
removed call to model/acquisto/AcquistoBean::setIDOrdine → KILLED

91

1.1
Location : setAcquisto
Killed by : model.acquisto.AcquistoDAOTest.[engine:junit-jupiter]/[class:model.acquisto.AcquistoDAOTest]/[method:setAcquisto_ok_setsAllFields()]
removed call to model/acquisto/AcquistoBean::setIDMaglietta → KILLED

92

1.1
Location : setAcquisto
Killed by : model.acquisto.AcquistoDAOTest.[engine:junit-jupiter]/[class:model.acquisto.AcquistoDAOTest]/[method:setAcquisto_ok_setsAllFields()]
removed call to model/acquisto/AcquistoBean::setQuantita → KILLED

93

1.1
Location : setAcquisto
Killed by : model.acquisto.AcquistoDAOTest.[engine:junit-jupiter]/[class:model.acquisto.AcquistoDAOTest]/[method:setAcquisto_ok_setsAllFields()]
removed call to model/acquisto/AcquistoBean::setImmagine → KILLED

94

1.1
Location : setAcquisto
Killed by : model.acquisto.AcquistoDAOTest.[engine:junit-jupiter]/[class:model.acquisto.AcquistoDAOTest]/[method:setAcquisto_ok_setsAllFields()]
removed call to model/acquisto/AcquistoBean::setPrezzoAq → KILLED

95

1.1
Location : setAcquisto
Killed by : model.acquisto.AcquistoDAOTest.[engine:junit-jupiter]/[class:model.acquisto.AcquistoDAOTest]/[method:setAcquisto_ok_setsAllFields()]
removed call to model/acquisto/AcquistoBean::setIvaAq → KILLED

96

1.1
Location : setAcquisto
Killed by : model.acquisto.AcquistoDAOTest.[engine:junit-jupiter]/[class:model.acquisto.AcquistoDAOTest]/[method:setAcquisto_ok_setsAllFields()]
removed call to model/acquisto/AcquistoBean::setTaglia → KILLED

100

1.1
Location : setAcquistoStatement
Killed by : model.acquisto.AcquistoDAOTest.[engine:junit-jupiter]/[class:model.acquisto.AcquistoDAOTest]/[method:doSave_ok_setsAllParamsAndExecutes()]
removed call to java/sql/PreparedStatement::setInt → KILLED

101

1.1
Location : setAcquistoStatement
Killed by : model.acquisto.AcquistoDAOTest.[engine:junit-jupiter]/[class:model.acquisto.AcquistoDAOTest]/[method:doSave_ok_setsAllParamsAndExecutes()]
removed call to java/sql/PreparedStatement::setInt → KILLED

102

1.1
Location : setAcquistoStatement
Killed by : model.acquisto.AcquistoDAOTest.[engine:junit-jupiter]/[class:model.acquisto.AcquistoDAOTest]/[method:doSave_ok_setsAllParamsAndExecutes()]
removed call to java/sql/PreparedStatement::setInt → KILLED

103

1.1
Location : setAcquistoStatement
Killed by : model.acquisto.AcquistoDAOTest.[engine:junit-jupiter]/[class:model.acquisto.AcquistoDAOTest]/[method:doSave_ok_setsAllParamsAndExecutes()]
removed call to java/sql/PreparedStatement::setString → KILLED

104

1.1
Location : setAcquistoStatement
Killed by : model.acquisto.AcquistoDAOTest.[engine:junit-jupiter]/[class:model.acquisto.AcquistoDAOTest]/[method:doSave_ok_setsAllParamsAndExecutes()]
removed call to java/sql/PreparedStatement::setFloat → KILLED

105

1.1
Location : setAcquistoStatement
Killed by : model.acquisto.AcquistoDAOTest.[engine:junit-jupiter]/[class:model.acquisto.AcquistoDAOTest]/[method:doSave_ok_setsAllParamsAndExecutes()]
removed call to java/sql/PreparedStatement::setInt → KILLED

106

1.1
Location : setAcquistoStatement
Killed by : model.acquisto.AcquistoDAOTest.[engine:junit-jupiter]/[class:model.acquisto.AcquistoDAOTest]/[method:doSave_ok_setsAllParamsAndExecutes()]
removed call to java/sql/PreparedStatement::setString → KILLED

Active mutators

Tests examined


Report generated by PIT 1.22.0