Skip to content

Commit 98ea3bf

Browse files
author
Janek Bieser
committed
Merge branch 'wp2.2.2-db-interface-impl-jb' into wp2.2.2-db-interface-impl
Conflicts: src/main/java/dbaccess/models/EmployeeCalendarModel.java src/main/java/dbaccess/models/mysql/MySQLAnalyseDataModel.java src/main/java/dbaccess/models/mysql/MySQLBaselineModel.java src/main/java/dbaccess/models/mysql/MySQLConflictsModel.java src/main/java/dbaccess/models/mysql/MySQLDependenciesModel.java src/main/java/dbaccess/models/mysql/MySQLEmployeeCalendarModel.java src/main/java/dbaccess/models/mysql/MySQLEmployeesModel.java src/main/java/dbaccess/models/mysql/MySQLSemaphoreModel.java src/main/java/jdbcConnection/MySqlConnect.java src/main/java/jdbcConnection/SQLExecuter.java src/test/java/dbaccess/models/mysql/MySQLModelsTestSuite.java src/test/java/dbaccess/models/mysql/MySQLSemaphoreModelTest.java src/test/resources/sqlutils/test_data.sql
2 parents a04ca1e + c57e788 commit 98ea3bf

18 files changed

Lines changed: 1370 additions & 432 deletions
Lines changed: 59 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
/*
2-
* The WBS-­Tool is a project managment tool combining the Work Breakdown
3-
* Structure and Earned Value Analysis
4-
* Copyright (C) 2013 FH-­Bingen
5-
*
6-
* This program is free software: you can redistribute it and/or modify
7-
* it under the terms of the GNU General Public License as published by
8-
* the Free Software Foundation, either version 3 of the License, or
9-
* (at your option) any later version.
10-
*
11-
* This program is distributed in the hope that it will be useful,
12-
* but WITHOUT ANY WARRANTY;; without even the implied warranty of
13-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14-
* GNU General Public License for more details.
15-
*
16-
* You should have received a copy of the GNU General Public License
17-
* along with this program. If not, see <http://www.gnu.org/licenses/>.
18-
*/
2+
* The WBS-­Tool is a project managment tool combining the Work Breakdown
3+
* Structure and Earned Value Analysis
4+
* Copyright (C) 2013 FH-­Bingen
5+
*
6+
* This program is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY;; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License
17+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
18+
*/
1919

2020
package dbaccess.models;
2121

@@ -24,57 +24,73 @@
2424

2525
import dbaccess.data.EmployeeCalendar;
2626

27-
/**The interface for the employee calendar model*/
27+
/** The interface for the employee calendar model. */
2828
public interface EmployeeCalendarModel {
2929

3030
/**
3131
* A method to add a new employee calendar to the project.
32-
* @param empCal The calendar which is added to the project.
32+
*
33+
* @param empCal
34+
* The calendar which is added to the project.
3335
*/
34-
public void addNewEmployeeCalendar(EmployeeCalendar empCal);
35-
36+
void addNewEmployeeCalendar(EmployeeCalendar empCal);
37+
3638
/**
3739
* A method to get the employee calendars from all employees.
40+
*
3841
* @return Returns a list with a employee calendar for each employee.
3942
*/
40-
public List<EmployeeCalendar> getEmployeeCalendar();
41-
43+
List<EmployeeCalendar> getEmployeeCalendar();
44+
4245
/**
4346
* A method to get a specific calendar.
44-
* @param id The id from the specific calendar
47+
*
48+
* @param id
49+
* The id from the specific calendar
4550
* @return Returns the selected employee calendar.
4651
*/
47-
public EmployeeCalendar getEmployeeCalendar(int id);
48-
52+
EmployeeCalendar getEmployeeCalendar(int id);
53+
4954
/**
50-
* TODO: ist das richtig?
5155
* A method to get the calendar from an employee.
52-
* @param fid The id of the referenced employee.
56+
*
57+
* @param fid
58+
* The id of the referenced employee.
5359
* @return Returns a list with the calendar of the selected employee.
5460
*/
55-
public List<EmployeeCalendar> getEmployeeCalendarForFID(int fid);
56-
61+
List<EmployeeCalendar> getEmployeeCalendarForFID(int fid);
62+
5763
/**
58-
* A method to get the employee calendars in a specific period.
59-
* @param from The start date from the period.
60-
* @param to The end date from the period
61-
* @return Returns a list with all calendars in the specific period.
64+
* A method to get the calendar from an employee.
65+
*
66+
* @param fid
67+
* The id of the referenced employee.
68+
* @param from
69+
* The start date from the period.
70+
* @param to
71+
* The end date from the period
72+
* @return Returns a list with the calendar of the selected employee.
6273
*/
63-
public List<EmployeeCalendar> getEmployeeCalendarInDateRange(Date from, Date to);
64-
74+
List<EmployeeCalendar> getEmployeeCalendarForFIDInDateRange(int fid,
75+
Date from, Date to);
76+
6577
/**
66-
* TODO: Was macht mode2? wo ist der unterschied zur obigen methode?
6778
* A method to get the employee calendars in a specific period.
68-
* @param from The start date from the period.
69-
* @param to The end date from the period
79+
*
80+
* @param from
81+
* The start date from the period.
82+
* @param to
83+
* The end date from the period
7084
* @return Returns a list with all calendars in the specific period.
7185
*/
72-
public List<EmployeeCalendar> getEmployeeCalendarInDateRange(Date from, Date to, boolean mode2);
86+
List<EmployeeCalendar> getEmployeeCalendarInDateRange(Date from, Date to);
7387

7488
/**
7589
* A method to delete e a specific calendar.
76-
* @param id The id from the calendar which is deleted from the project.
90+
*
91+
* @param id
92+
* The id from the calendar which is deleted from the project.
7793
*/
78-
public void deleteEmployeeCalendar(int id);
79-
94+
void deleteEmployeeCalendar(int id);
95+
8096
}

‎src/main/java/dbaccess/models/mysql/MySQLAnalyseDataModel.java‎

Lines changed: 59 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -20,42 +20,61 @@
2020
package dbaccess.models.mysql;
2121

2222
import java.sql.Connection;
23+
import java.sql.PreparedStatement;
2324
import java.sql.ResultSet;
2425
import java.sql.SQLException;
25-
import java.sql.Statement;
2626
import java.util.ArrayList;
2727
import java.util.List;
2828

2929
import jdbcConnection.SQLExecuter;
3030
import dbaccess.data.AnalyseData;
3131
import dbaccess.models.AnalyseDataModel;
3232

33-
3433
/**
3534
* The <code>MySQLAnalyseDataModel</code> class implements the
3635
* <code>AnalyseDataModel</code> and handles all the database access concerning
3736
* analyse data.
3837
*/
3938
public class MySQLAnalyseDataModel implements AnalyseDataModel {
40-
39+
4140
/**
4241
* The MySQL connection to use.
4342
*/
4443
private Connection connection;
4544

4645
@Override
4746
public void addNewAnalyseData(AnalyseData data) {
48-
connection=SQLExecuter.getConnection();
47+
connection = SQLExecuter.getConnection();
48+
final int paramCount = 15;
49+
PreparedStatement stm = null;
4950
try {
50-
Statement stm = connection.createStatement();
51-
stm.execute("CALL analyse_data_new ("
52-
+ data.getFid_wp() + "," + data.getFid_baseline()
53-
+ ", '" + data.getName() + "'," + data.getBac() + ","
54-
+ data.getAc() + "," + data.getEv() + "," + data.getEtc()
55-
+ "," + data.getEac() + "," + data.getCpi() + ","
56-
+ data.getBac_costs() + "," + data.getAc_costs() + ","
57-
+ data.getEtc_costs() + "," + data.getSv() + ","
58-
+ data.getSpi() + "," + data.getPv() + ")");
51+
String storedProcedure = "CALL analyse_data_new (";
52+
53+
for (int i = 1; i < paramCount; i++) {
54+
storedProcedure += "?,";
55+
}
56+
57+
storedProcedure += "?)";
58+
59+
stm = connection.prepareStatement(storedProcedure);
60+
stm.setInt(1, data.getFid_wp());
61+
stm.setInt(2, data.getFid_baseline());
62+
stm.setString(3, data.getName());
63+
stm.setDouble(4, data.getBac());
64+
stm.setDouble(5, data.getAc());
65+
stm.setDouble(6, data.getEv());
66+
stm.setDouble(7, data.getEtc());
67+
stm.setDouble(8, data.getEac());
68+
stm.setDouble(9, data.getCpi());
69+
stm.setDouble(10, data.getBac_costs());
70+
stm.setDouble(11, data.getAc_costs());
71+
stm.setDouble(12, data.getEtc_costs());
72+
stm.setInt(13, data.getSv());
73+
stm.setInt(14, data.getSpi());
74+
stm.setInt(15, data.getPv());
75+
76+
stm.execute();
77+
5978
} catch (SQLException e) {
6079
e.printStackTrace();
6180
}
@@ -64,17 +83,23 @@ public void addNewAnalyseData(AnalyseData data) {
6483

6584
@Override
6685
public AnalyseData getAnalyseData(int fid) {
67-
connection=SQLExecuter.getConnection();
86+
connection = SQLExecuter.getConnection();
6887
AnalyseData aData = new AnalyseData();
6988
try {
7089
ResultSet result = null;
71-
Statement stm = connection.createStatement();
72-
result = stm.executeQuery("CALL analyse_data_select_by("
73-
+ fid+",false)");
90+
PreparedStatement stm = null;
91+
92+
String storedProcedure = "CALL analyse_data_select_by(?,?)";
7493

75-
if (result.next()){
94+
stm = connection.prepareStatement(storedProcedure);
95+
stm.setInt(1, fid);
96+
stm.setBoolean(2, false);
97+
98+
result = stm.executeQuery();
99+
100+
if (result.next()) {
76101
aData = AnalyseData.fromResultSet(result);
77-
102+
78103
}
79104
} catch (SQLException e) {
80105
e.printStackTrace();
@@ -84,25 +109,32 @@ public AnalyseData getAnalyseData(int fid) {
84109

85110
@Override
86111
public List<AnalyseData> getAnalyseDataForBaseline(int baseline) {
87-
connection=SQLExecuter.getConnection();
112+
connection = SQLExecuter.getConnection();
88113
List<AnalyseData> adList = new ArrayList<AnalyseData>();
89114
try {
90115
ResultSet result = null;
91-
AnalyseData aData=new AnalyseData();
92-
Statement stm = connection.createStatement();
93-
result = stm.executeQuery("CALL analyse_data_select_by("
94-
+ baseline+",true)");
116+
AnalyseData aData = new AnalyseData();
117+
118+
PreparedStatement stm = null;
119+
120+
String storedProcedure = "CALL analyse_data_select_by(?,?)";
95121

96-
while (result.next()){
122+
stm = connection.prepareStatement(storedProcedure);
123+
stm.setInt(1, baseline);
124+
stm.setBoolean(2, true);
125+
126+
result = stm.executeQuery();
127+
128+
while (result.next()) {
97129
aData = AnalyseData.fromResultSet(result);
98130
adList.add(aData);
99131
}
100-
132+
101133
return adList;
102134
} catch (SQLException e) {
103135
e.printStackTrace();
104136
}
105-
return null;
137+
return adList;
106138
}
107139

108140
}

‎src/main/java/dbaccess/models/mysql/MySQLBaselineModel.java‎

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
package dbaccess.models.mysql;
2222

2323
import java.sql.Connection;
24+
import java.sql.PreparedStatement;
2425
import java.sql.ResultSet;
2526
import java.sql.SQLException;
2627
import java.sql.Statement;
@@ -47,11 +48,18 @@ public class MySQLBaselineModel implements BaselineModel {
4748
public void addNewBaseline(Baseline line) {
4849
connection=SQLExecuter.getConnection();
4950
try {
50-
Statement stm = connection.createStatement();
51+
PreparedStatement stm = null;
52+
53+
String storedProcedure = "CALL baseline_new (?,?,?)";
54+
55+
stm = connection.prepareStatement(storedProcedure);
56+
stm.setInt(1, line.getFid_project());
57+
stm.setTimestamp(2, new Timestamp(line.getBl_date().getTime()));
58+
stm.setString(3, line.getDescription());
59+
60+
stm.execute();
61+
5162

52-
stm.execute("CALL baseline_new ("
53-
+ line.getFid_project() + ",'" + new Timestamp(line.getBl_date().getTime()) + "','"
54-
+ line.getDescription() + "')");
5563
} catch (SQLException e) {
5664
e.printStackTrace();
5765
}
@@ -64,6 +72,8 @@ public List<Baseline> getBaseline() {
6472
try {
6573
ResultSet result = null;
6674
Baseline baseline=new Baseline();
75+
76+
6777
Statement stm = connection.createStatement();
6878
result = stm.executeQuery("CALL baseline_select(NULL)");
6979

@@ -76,7 +86,7 @@ public List<Baseline> getBaseline() {
7686
} catch (SQLException e) {
7787
e.printStackTrace();
7888
}
79-
return null;
89+
return blList;
8090
}
8191

8292
@Override
@@ -85,10 +95,16 @@ public Baseline getBaseline(int baselineID) {
8595
Baseline baseline = new Baseline();
8696
try {
8797
ResultSet result = null;
88-
Statement stm = connection.createStatement();
89-
result = stm.executeQuery("CALL baseline_select("
90-
+ baselineID + ")");
98+
99+
PreparedStatement stm = null;
91100

101+
String storedProcedure = "CALL baseline_select(?)";
102+
103+
stm = connection.prepareStatement(storedProcedure);
104+
stm.setInt(1, baselineID);
105+
106+
result=stm.executeQuery();
107+
92108
if (result.next()){
93109
baseline = Baseline.fromResultSet(result);
94110
}
@@ -97,6 +113,6 @@ public Baseline getBaseline(int baselineID) {
97113
} catch (SQLException e) {
98114
e.printStackTrace();
99115
}
100-
return null;
116+
return baseline;
101117
}
102118
}

0 commit comments

Comments
 (0)