Newer
Older
import edu.ncsu.csc.itrust.beans.ExerciseEntryBean;
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
/**
* ExerciseEntryLoader.java
* Version 1
* 2/21/2015
* Copyright notice: none
* A loader for entries into the Exercise Diary (ExerciseEntry's).
*
* Loads information to/from beans using PreparedStatements and ResultSets.
*/
public class ExerciseEntryLoader implements BeanLoader<ExerciseEntryBean> {
/**
* Returns the list of Exercise entries for a patient
* @param rs the result set to load into beans
* @return the list of exercise entries for a patient
*/
public List<ExerciseEntryBean> loadList(ResultSet rs) throws SQLException {
ArrayList<ExerciseEntryBean> list = new ArrayList<ExerciseEntryBean>();
while (rs.next()) {
list.add(loadSingle(rs));
}
return list;
}
/**
* Loads a single exercise entry from a result set
* @param rs the result of a query
* @return a exercise entry bean that has the values from the db
*/
@Override
public ExerciseEntryBean loadSingle(ResultSet rs) throws SQLException {
ExerciseEntryBean exerciseEntry = new ExerciseEntryBean();
exerciseEntry.setEntryID(rs.getLong("EntryID"));
exerciseEntry.setStrDate(new SimpleDateFormat("MM/dd/yyyy")
.format(new java.util.Date(rs.getDate(
"Date").getTime())));
exerciseEntry.setExerciseType(rs.getString("ExerciseType"));
exerciseEntry.setStrName(rs.getString("Name"));
exerciseEntry.setHoursWorked(rs.getDouble("Hours"));
exerciseEntry.setCaloriesBurned(rs.getInt("Calories"));
exerciseEntry.setNumSets(rs.getInt("Sets"));
exerciseEntry.setNumReps(rs.getInt("Reps"));
exerciseEntry.setPatientID(rs.getLong("PatientID"));
exerciseEntry.setLabelID(rs.getLong("LabelID"));
return exerciseEntry;
}
/**
* Loads the values of the exercise entry into the prepared statement
* @param ps the sql statement to load into
* @param bean the exercise entry we want to store in the db
* @return a prepared statement for loading a exercise entry into the db
*/
@Override
public PreparedStatement loadParameters(PreparedStatement ps,
ExerciseEntryBean bean) throws SQLException {
ps.setLong(1, bean.getEntryID());
ps.setDate(2, new java.sql.Date(bean.getDate().getTime()));
ps.setString(3, bean.getExerciseType().getName());
ps.setString(4, bean.getStrName());
ps.setDouble(5, bean.getHoursWorked());
ps.setInt(6, bean.getCaloriesBurned());
ps.setInt(7, bean.getNumSets());
ps.setInt(8, bean.getNumReps());
ps.setLong(9, bean.getPatientID());
return ps;
}
}