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