Newer
Older
import edu.ncsu.csc.itrust.beans.MacronutrientsBean;
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
/**
* MacronutrientsLoader.java
* Version 1
* 03/31/2015
* Copyright notice: none
* A loader for entries into Macronutrients (personalhealthinformation, patients).
*
* Loads information to/from beans using PreparedStatements and ResultSets.
*/
public class MacronutrientsLoader implements BeanLoader<MacronutrientsBean> {
/**
* Returns the list of Food entries for a patient
* @param rs the result set to load into beans
* @return the list of food entries for a patient
*/
public List<MacronutrientsBean> loadList(ResultSet rs) throws SQLException {
ArrayList<MacronutrientsBean> list = new ArrayList<MacronutrientsBean>();
while (rs.next()) {
list.add(loadSingle(rs));
}
return list;
}
/**
* Loads a single food entry from a result set
* @param rs the result of a query
* @return a food entry bean that has the values from the db
*/
@Override
public MacronutrientsBean loadSingle(ResultSet rs) throws SQLException {
MacronutrientsBean msj = new MacronutrientsBean();
// Some sort of database issue getting the results of the query
msj.setHeight(rs.getFloat("Height"));
msj.setWeight(rs.getFloat("personalhealthinformation.Weight"));
msj.setYears(rs.getDate("patients.DateOfBirth"));
msj.setMsj(rs.getFloat("height"), rs.getFloat("weight"), msj.getYears());
msj.setPatientID(rs.getLong("PatientID"));
return msj;
}
@Override
public PreparedStatement loadParameters(PreparedStatement ps,
MacronutrientsBean bean) throws SQLException {
return null;
}
}