Rev 34 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
26 | moos | 1 | package ch.ffhs.webE.dao; |
2 | |||
37 | PointedEar | 3 | import java.util.ArrayList; |
26 | moos | 4 | import java.util.List; |
5 | |||
37 | PointedEar | 6 | import org.hibernate.Session; |
7 | import org.hibernate.Transaction; |
||
8 | |||
26 | moos | 9 | import ch.ffhs.webE.domain.RelationshipType; |
10 | |||
37 | PointedEar | 11 | import com.googlecode.s2hibernate.struts2.plugin.annotations.SessionTarget; |
12 | import com.googlecode.s2hibernate.struts2.plugin.annotations.TransactionTarget; |
||
26 | moos | 13 | |
37 | PointedEar | 14 | /** |
15 | * Data Access Object class for {@link RelationshipType}s |
||
16 | * |
||
17 | * @author Thomas Lahn |
||
18 | */ |
||
19 | public class RelationshipTypeDAO |
||
20 | { |
||
26 | moos | 21 | |
37 | PointedEar | 22 | /** |
23 | * Hibernate session target |
||
24 | */ |
||
25 | @SessionTarget |
||
26 | Session session; |
||
26 | moos | 27 | |
37 | PointedEar | 28 | /** |
29 | * Hibernate transaction target |
||
30 | */ |
||
31 | @TransactionTarget |
||
32 | Transaction transaction; |
||
33 | |||
34 | /** |
||
35 | * Gets a list of all the relationshipTypes in the database. |
||
36 | * |
||
37 | * @return List of all the users. In case of a problem, an empty list is |
||
38 | * returned. |
||
39 | */ |
||
40 | @SuppressWarnings("unchecked") |
||
41 | public List<RelationshipType> getList() |
||
42 | { |
||
43 | |||
44 | List<RelationshipType> relType = null; |
||
45 | |||
46 | try |
||
47 | { |
||
48 | relType = this.session.createQuery("from RelationshipType").list(); //$NON-NLS-1$ |
||
49 | } |
||
50 | catch (Exception e) |
||
51 | { |
||
52 | // TODO: Logging |
||
53 | } |
||
54 | |||
55 | if (relType == null) |
||
56 | { |
||
57 | relType = new ArrayList<RelationshipType>(); |
||
58 | } |
||
59 | |||
60 | return relType; |
||
61 | } |
||
62 | |||
63 | /** |
||
64 | * Saves or updates a relationship type |
||
65 | * |
||
66 | * @param relType |
||
67 | * A filled domain object |
||
68 | * @return Boolean indicating success or error in saving the relationshipType |
||
69 | */ |
||
70 | public boolean saveOrUpdate(RelationshipType relType) |
||
71 | { |
||
72 | try |
||
73 | { |
||
74 | this.session.saveOrUpdate(relType); |
||
75 | return true; |
||
76 | } |
||
77 | catch (Exception e) |
||
78 | { |
||
79 | this.transaction.rollback(); |
||
80 | return false; |
||
81 | // TODO: Logging |
||
82 | } |
||
83 | } |
||
84 | |||
85 | /** |
||
86 | * Delete a relationship type |
||
87 | * |
||
88 | * @param relTypeId |
||
89 | * Relationship type ID |
||
90 | * @return boolean indicating success or error in the query execution |
||
91 | */ |
||
92 | public boolean delete(int relTypeId) |
||
93 | { |
||
94 | try |
||
95 | { |
||
96 | RelationshipType relType = (RelationshipType) this.session.get( |
||
97 | RelationshipType.class, relTypeId); |
||
98 | this.session.delete(relType); |
||
99 | return true; |
||
100 | } |
||
101 | catch (Exception e) |
||
102 | { |
||
103 | this.transaction.rollback(); |
||
104 | // TODO: Logging |
||
105 | return false; |
||
106 | } |
||
107 | } |
||
108 | |||
109 | /** |
||
110 | * Used to get a relationship type by ID |
||
111 | * |
||
112 | * @param relTypeID |
||
113 | * @return |
||
114 | */ |
||
115 | public RelationshipType getById(int relTypeID) |
||
116 | { |
||
117 | RelationshipType relType = null; |
||
118 | try |
||
119 | { |
||
120 | relType = (RelationshipType) this.session.get(RelationshipType.class, |
||
121 | relTypeID); |
||
122 | } |
||
123 | catch (Exception e) |
||
124 | { |
||
125 | e.printStackTrace(); |
||
126 | // TODO: Logging |
||
127 | } |
||
128 | return relType; |
||
129 | } |
||
26 | moos | 130 | } |