Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
37 | PointedEar | 1 | /** |
2 | * |
||
3 | */ |
||
4 | package ch.ffhs.webE.dao; |
||
5 | |||
6 | import java.util.ArrayList; |
||
7 | import java.util.List; |
||
8 | |||
9 | import org.hibernate.Session; |
||
10 | import org.hibernate.Transaction; |
||
11 | |||
12 | import ch.ffhs.webE.domain.History; |
||
13 | |||
14 | import com.googlecode.s2hibernate.struts2.plugin.annotations.SessionTarget; |
||
15 | import com.googlecode.s2hibernate.struts2.plugin.annotations.TransactionTarget; |
||
16 | |||
17 | /** |
||
18 | * @author pelinux |
||
19 | * |
||
20 | */ |
||
21 | public class HistoryDAO |
||
22 | { |
||
23 | /** |
||
24 | * Database session |
||
25 | */ |
||
26 | @SessionTarget |
||
27 | Session session; |
||
28 | |||
29 | /** |
||
30 | * Database transaction |
||
31 | */ |
||
32 | @TransactionTarget |
||
33 | Transaction transaction; |
||
34 | |||
35 | /** |
||
36 | * Executes the query to save the history record |
||
37 | * |
||
38 | * @param history |
||
39 | * Domain object to be saved |
||
40 | * @return <code>true</code> if successful, <code>false</code> otherwise |
||
41 | */ |
||
42 | public boolean saveOrUpdate(History history) |
||
43 | { |
||
44 | try |
||
45 | { |
||
46 | history.setId(history.getId()); |
||
47 | this.session.saveOrUpdate(history); |
||
48 | return true; |
||
49 | } |
||
50 | catch (Exception e) |
||
51 | { |
||
52 | this.transaction.rollback(); |
||
53 | e.printStackTrace(); |
||
54 | return false; |
||
55 | } |
||
56 | } |
||
57 | |||
58 | /** |
||
59 | * Returns a list of all terms |
||
60 | * |
||
61 | * @return an ArrayList with all the terms - in case of a problem, an empty |
||
62 | * list is returned |
||
63 | */ |
||
64 | @SuppressWarnings("unchecked") |
||
65 | public List<History> getList() |
||
66 | { |
||
67 | List<History> history = null; |
||
68 | try |
||
69 | { |
||
70 | history = this.session.createQuery("from History").list(); //$NON-NLS-1$ |
||
71 | } |
||
72 | catch (Exception e) |
||
73 | { |
||
74 | e.printStackTrace(); |
||
75 | } |
||
76 | |||
77 | /* |
||
78 | * If no term was checked, return an empty list to mitigate null pointer |
||
79 | * exceptions |
||
80 | */ |
||
81 | if (history == null) |
||
82 | { |
||
83 | history = new ArrayList<History>(); |
||
84 | } |
||
85 | |||
86 | return history; |
||
87 | } |
||
88 | } |