RigaOrdineDAOImpl.java

1
package com.popx.persistenza;
2
3
import com.popx.modello.RigaOrdineBean;
4
5
import java.sql.Connection;
6
import java.sql.PreparedStatement;
7
import java.sql.ResultSet;
8
import java.sql.SQLException;
9
import java.util.ArrayList;
10
import java.util.List;
11
import javax.sql.DataSource;
12
13
public class RigaOrdineDAOImpl implements RigaOrdineDAO {
14
15
    private DataSource ds;
16
17
    /*@ public model boolean available;
18
      @ public invariant ds != null && available;
19
      @ represents available <- ds != null;
20
      @*/
21
22
    public RigaOrdineDAOImpl() {
23
        this.ds = DataSourceSingleton.getInstance();
24
    }
25
26
    @Override
27
    /*@ public normal_behavior
28
      @   requires rigaOrdine != null
29
      @        && rigaOrdine.getOrdineId() > 0
30
      @        && rigaOrdine.getProdottoId() != null && !rigaOrdine.getProdottoId().isEmpty()
31
      @        && rigaOrdine.getQuantity() >= 0
32
      @        && rigaOrdine.getUnitaryCost() >= 0;
33
      @   assignable \everything;
34
      @   ensures available;
35
      @*/
36
    public void addRigaOrdine(RigaOrdineBean rigaOrdine) {
37
        String query = "INSERT INTO RigaOrdine (ordine_id, prodotto_id, quantity, unitary_cost) VALUES (?, ?, ?, ?)";
38
39
        try (Connection con = ds.getConnection();
40
             PreparedStatement ps = con.prepareStatement(query)) {
41
42 1 1. addRigaOrdine : removed call to java/sql/PreparedStatement::setInt → KILLED
            ps.setInt(1, rigaOrdine.getOrdineId());
43 1 1. addRigaOrdine : removed call to java/sql/PreparedStatement::setString → KILLED
            ps.setString(2, rigaOrdine.getProdottoId());
44 1 1. addRigaOrdine : removed call to java/sql/PreparedStatement::setInt → KILLED
            ps.setInt(3, rigaOrdine.getQuantity());
45 1 1. addRigaOrdine : removed call to java/sql/PreparedStatement::setFloat → KILLED
            ps.setFloat(4, rigaOrdine.getUnitaryCost());
46
47
            ps.executeUpdate();
48
49
        } catch (SQLException e) {
50 1 1. addRigaOrdine : removed call to java/sql/SQLException::printStackTrace → NO_COVERAGE
            e.printStackTrace();
51
        }
52
    }
53
54
    @Override
55
    /*@ public normal_behavior
56
      @   requires ordineId > 0;
57
      @   assignable \everything;
58
      @   ensures \result != null
59
      @        && (\forall int i; 0 <= i && i < \result.size();
60
      @              \result.get(i) != null
61
      @           && \result.get(i).getOrdineId() == ordineId
62
      @           && \result.get(i).getQuantity() >= 0
63
      @           && \result.get(i).getUnitaryCost() >= 0
64
      @           && \result.get(i).getProdottoId() != null
65
      @           && !\result.get(i).getProdottoId().isEmpty());
66
      @*/
67
    public List<RigaOrdineBean> getRigheOrdineByOrdineId(int ordineId) {
68
        String query = "SELECT * FROM RigaOrdine WHERE ordine_id = ?";
69
        List<RigaOrdineBean> righeOrdine = new ArrayList<>();
70
71
        try (Connection con = ds.getConnection();
72
             PreparedStatement ps = con.prepareStatement(query)) {
73
74 1 1. getRigheOrdineByOrdineId : removed call to java/sql/PreparedStatement::setInt → KILLED
            ps.setInt(1, ordineId);
75
            ResultSet rs = ps.executeQuery();
76
77 1 1. getRigheOrdineByOrdineId : negated conditional → KILLED
            while (rs.next()) {
78
                RigaOrdineBean rigaOrdine = new RigaOrdineBean();
79 1 1. getRigheOrdineByOrdineId : removed call to com/popx/modello/RigaOrdineBean::setOrdineId → KILLED
                rigaOrdine.setOrdineId(rs.getInt("ordine_id"));
80 1 1. getRigheOrdineByOrdineId : removed call to com/popx/modello/RigaOrdineBean::setProdottoId → KILLED
                rigaOrdine.setProdottoId(rs.getString("prodotto_id"));
81 1 1. getRigheOrdineByOrdineId : removed call to com/popx/modello/RigaOrdineBean::setQuantity → KILLED
                rigaOrdine.setQuantity(rs.getInt("quantity"));
82 1 1. getRigheOrdineByOrdineId : removed call to com/popx/modello/RigaOrdineBean::setUnitaryCost → KILLED
                rigaOrdine.setUnitaryCost(rs.getFloat("unitary_cost"));
83
                righeOrdine.add(rigaOrdine);
84
            }
85
86
        } catch (SQLException e) {
87 1 1. getRigheOrdineByOrdineId : removed call to java/sql/SQLException::printStackTrace → NO_COVERAGE
            e.printStackTrace();
88
        }
89
90 1 1. getRigheOrdineByOrdineId : replaced return value with Collections.emptyList for com/popx/persistenza/RigaOrdineDAOImpl::getRigheOrdineByOrdineId → KILLED
        return righeOrdine;
91
    }
92
93
    @Override
94
    /*@ public normal_behavior
95
      @   requires rigaOrdine != null
96
      @        && rigaOrdine.getOrdineId() > 0
97
      @        && rigaOrdine.getProdottoId() != null && !rigaOrdine.getProdottoId().isEmpty()
98
      @        && rigaOrdine.getQuantity() >= 0
99
      @        && rigaOrdine.getUnitaryCost() >= 0;
100
      @   assignable \everything;
101
      @   ensures available;
102
      @*/
103
    public void updateRigaOrdine(RigaOrdineBean rigaOrdine) {
104
        String query = "UPDATE RigaOrdine SET quantity = ?, unitary_cost = ? WHERE ordine_id = ? AND prodotto_id = ?";
105
106
        try (Connection con = ds.getConnection();
107
             PreparedStatement ps = con.prepareStatement(query)) {
108
109 1 1. updateRigaOrdine : removed call to java/sql/PreparedStatement::setInt → KILLED
            ps.setInt(1, rigaOrdine.getQuantity());
110 1 1. updateRigaOrdine : removed call to java/sql/PreparedStatement::setFloat → KILLED
            ps.setFloat(2, rigaOrdine.getUnitaryCost());
111 1 1. updateRigaOrdine : removed call to java/sql/PreparedStatement::setInt → KILLED
            ps.setInt(3, rigaOrdine.getOrdineId());
112 1 1. updateRigaOrdine : removed call to java/sql/PreparedStatement::setString → KILLED
            ps.setString(4, rigaOrdine.getProdottoId());
113
114
            ps.executeUpdate();
115
116
        } catch (SQLException e) {
117 1 1. updateRigaOrdine : removed call to java/sql/SQLException::printStackTrace → NO_COVERAGE
            e.printStackTrace();
118
        }
119
    }
120
121
    @Override
122
    /*@ public normal_behavior
123
      @   requires ordineId > 0
124
      @        && prodottoId != null && !prodottoId.isEmpty();
125
      @   assignable \everything;
126
      @   ensures available;
127
      @*/
128
    public void deleteRigaOrdine(int ordineId, String prodottoId) {
129
        String query = "DELETE FROM RigaOrdine WHERE ordine_id = ? AND prodotto_id = ?";
130
131
        try (Connection con = ds.getConnection();
132
             PreparedStatement ps = con.prepareStatement(query)) {
133
134 1 1. deleteRigaOrdine : removed call to java/sql/PreparedStatement::setInt → KILLED
            ps.setInt(1, ordineId);
135 1 1. deleteRigaOrdine : removed call to java/sql/PreparedStatement::setString → KILLED
            ps.setString(2, prodottoId);
136
137
            ps.executeUpdate();
138
139
        } catch (SQLException e) {
140 1 1. deleteRigaOrdine : removed call to java/sql/SQLException::printStackTrace → NO_COVERAGE
            e.printStackTrace();
141
        }
142
    }
143
}

Mutations

42

1.1
Location : addRigaOrdine
Killed by : com.popx.integration.persistenza.RigaOrdineDAOImplTest.[engine:junit-jupiter]/[class:com.popx.integration.persistenza.RigaOrdineDAOImplTest]
removed call to java/sql/PreparedStatement::setInt → KILLED

43

1.1
Location : addRigaOrdine
Killed by : com.popx.integration.persistenza.RigaOrdineDAOImplTest.[engine:junit-jupiter]/[class:com.popx.integration.persistenza.RigaOrdineDAOImplTest]
removed call to java/sql/PreparedStatement::setString → KILLED

44

1.1
Location : addRigaOrdine
Killed by : com.popx.integration.persistenza.RigaOrdineDAOImplTest.[engine:junit-jupiter]/[class:com.popx.integration.persistenza.RigaOrdineDAOImplTest]
removed call to java/sql/PreparedStatement::setInt → KILLED

45

1.1
Location : addRigaOrdine
Killed by : com.popx.integration.persistenza.RigaOrdineDAOImplTest.[engine:junit-jupiter]/[class:com.popx.integration.persistenza.RigaOrdineDAOImplTest]
removed call to java/sql/PreparedStatement::setFloat → KILLED

50

1.1
Location : addRigaOrdine
Killed by : none
removed call to java/sql/SQLException::printStackTrace → NO_COVERAGE

74

1.1
Location : getRigheOrdineByOrdineId
Killed by : com.popx.integration.persistenza.RigaOrdineDAOImplTest.[engine:junit-jupiter]/[class:com.popx.integration.persistenza.RigaOrdineDAOImplTest]
removed call to java/sql/PreparedStatement::setInt → KILLED

77

1.1
Location : getRigheOrdineByOrdineId
Killed by : com.popx.integration.persistenza.RigaOrdineDAOImplTest.[engine:junit-jupiter]/[class:com.popx.integration.persistenza.RigaOrdineDAOImplTest]
negated conditional → KILLED

79

1.1
Location : getRigheOrdineByOrdineId
Killed by : com.popx.integration.persistenza.RigaOrdineDAOImplTest.[engine:junit-jupiter]/[class:com.popx.integration.persistenza.RigaOrdineDAOImplTest]
removed call to com/popx/modello/RigaOrdineBean::setOrdineId → KILLED

80

1.1
Location : getRigheOrdineByOrdineId
Killed by : com.popx.integration.persistenza.RigaOrdineDAOImplTest.[engine:junit-jupiter]/[class:com.popx.integration.persistenza.RigaOrdineDAOImplTest]
removed call to com/popx/modello/RigaOrdineBean::setProdottoId → KILLED

81

1.1
Location : getRigheOrdineByOrdineId
Killed by : com.popx.integration.persistenza.RigaOrdineDAOImplTest.[engine:junit-jupiter]/[class:com.popx.integration.persistenza.RigaOrdineDAOImplTest]
removed call to com/popx/modello/RigaOrdineBean::setQuantity → KILLED

82

1.1
Location : getRigheOrdineByOrdineId
Killed by : com.popx.integration.persistenza.RigaOrdineDAOImplTest.[engine:junit-jupiter]/[class:com.popx.integration.persistenza.RigaOrdineDAOImplTest]
removed call to com/popx/modello/RigaOrdineBean::setUnitaryCost → KILLED

87

1.1
Location : getRigheOrdineByOrdineId
Killed by : none
removed call to java/sql/SQLException::printStackTrace → NO_COVERAGE

90

1.1
Location : getRigheOrdineByOrdineId
Killed by : com.popx.integration.persistenza.RigaOrdineDAOImplTest.[engine:junit-jupiter]/[class:com.popx.integration.persistenza.RigaOrdineDAOImplTest]
replaced return value with Collections.emptyList for com/popx/persistenza/RigaOrdineDAOImpl::getRigheOrdineByOrdineId → KILLED

109

1.1
Location : updateRigaOrdine
Killed by : com.popx.integration.persistenza.RigaOrdineDAOImplTest.[engine:junit-jupiter]/[class:com.popx.integration.persistenza.RigaOrdineDAOImplTest]
removed call to java/sql/PreparedStatement::setInt → KILLED

110

1.1
Location : updateRigaOrdine
Killed by : com.popx.integration.persistenza.RigaOrdineDAOImplTest.[engine:junit-jupiter]/[class:com.popx.integration.persistenza.RigaOrdineDAOImplTest]
removed call to java/sql/PreparedStatement::setFloat → KILLED

111

1.1
Location : updateRigaOrdine
Killed by : com.popx.integration.persistenza.RigaOrdineDAOImplTest.[engine:junit-jupiter]/[class:com.popx.integration.persistenza.RigaOrdineDAOImplTest]
removed call to java/sql/PreparedStatement::setInt → KILLED

112

1.1
Location : updateRigaOrdine
Killed by : com.popx.integration.persistenza.RigaOrdineDAOImplTest.[engine:junit-jupiter]/[class:com.popx.integration.persistenza.RigaOrdineDAOImplTest]
removed call to java/sql/PreparedStatement::setString → KILLED

117

1.1
Location : updateRigaOrdine
Killed by : none
removed call to java/sql/SQLException::printStackTrace → NO_COVERAGE

134

1.1
Location : deleteRigaOrdine
Killed by : com.popx.integration.persistenza.RigaOrdineDAOImplTest.[engine:junit-jupiter]/[class:com.popx.integration.persistenza.RigaOrdineDAOImplTest]
removed call to java/sql/PreparedStatement::setInt → KILLED

135

1.1
Location : deleteRigaOrdine
Killed by : com.popx.integration.persistenza.RigaOrdineDAOImplTest.[engine:junit-jupiter]/[class:com.popx.integration.persistenza.RigaOrdineDAOImplTest]
removed call to java/sql/PreparedStatement::setString → KILLED

140

1.1
Location : deleteRigaOrdine
Killed by : none
removed call to java/sql/SQLException::printStackTrace → NO_COVERAGE

Active mutators

Tests examined


Report generated by PIT 1.15.2