Go to most recent revision | Details | 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 |
||
60 | public boolean saveRelationshipType(RelationshipType relType) |
||
61 | { |
||
62 | try |
||
63 | { |
||
64 | session.save(relType); |
||
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 | { |
||
86 | User user = (User) session.get(RelationshipType.class, relTypeID); |
||
87 | session.delete(user); |
||
88 | return true; |
||
89 | } |
||
90 | catch (Exception e) |
||
91 | { |
||
92 | transaction.rollback(); |
||
93 | // TODO: Logging |
||
94 | return false; |
||
95 | } |
||
96 | } |
||
97 | } |