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