Rev 34 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 34 | Rev 37 | ||
---|---|---|---|
1 | package ch.ffhs.webE.dao; |
1 | package ch.ffhs.webE.dao; |
2 | 2 | ||
- | 3 | import java.util.ArrayList; |
|
3 | import java.util.List; |
4 | import java.util.List; |
4 | 5 | ||
- | 6 | import org.hibernate.Session; |
|
- | 7 | import org.hibernate.Transaction; |
|
- | 8 | ||
5 | import ch.ffhs.webE.domain.RelationshipType; |
9 | import ch.ffhs.webE.domain.RelationshipType; |
6 | 10 | ||
- | 11 | import com.googlecode.s2hibernate.struts2.plugin.annotations.SessionTarget; |
|
- | 12 | import com.googlecode.s2hibernate.struts2.plugin.annotations.TransactionTarget; |
|
- | 13 | ||
- | 14 | /**
|
|
- | 15 | * Data Access Object class for {@link RelationshipType}s
|
|
- | 16 | *
|
|
- | 17 | * @author Thomas Lahn
|
|
- | 18 | */
|
|
7 | public interface RelationshipTypeDAO { |
19 | public class RelationshipTypeDAO |
- | 20 | {
|
|
- | 21 | ||
- | 22 | /**
|
|
- | 23 | * Hibernate session target
|
|
- | 24 | */
|
|
- | 25 | @SessionTarget |
|
- | 26 | Session session;
|
|
- | 27 | ||
- | 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 | }
|
|
8 | 59 | ||
9 | List<RelationshipType> getRelTypes(); |
60 | return relType; |
- | 61 | }
|
|
10 | 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 | */
|
|
11 | boolean deleteRelationshipType(int relTypeID); |
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 | }
|
|
12 | 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( |
|
13 | RelationshipType getRelTypeById(int relTypeID); |
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 | }
|
|
14 | 108 | ||
- | 109 | /**
|
|
15 | boolean saveOrUpdateRelType(RelationshipType relType); |
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 | }
|
|
16 | }
|
130 | }
|
17 | 131 |