Subversion Repositories WebE

Rev

Rev 27 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 27 Rev 34
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> getRelTypes()
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 saveOrUpdateRelType(RelationshipType relType)
60
    public boolean saveOrUpdateRelType(RelationshipType relType)
61
    {
61
    {
62
        try
62
        try
63
        {
63
        {
64
            session.saveOrUpdate(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
            RelationshipType relType = (RelationshipType) session.get(
87
                    RelationshipType.class, relTypeID);
87
                    RelationshipType.class, relTypeID);
88
            session.delete(relType);
88
            session.delete(relType);
89
            return true;
89
            return true;
90
        }
90
        }
91
        catch (Exception e)
91
        catch (Exception e)
92
        {
92
        {
93
            transaction.rollback();
93
            transaction.rollback();
94
            // TODO: Logging
94
            // TODO: Logging
95
            return false;
95
            return false;
96
        }
96
        }
97
    }
97
    }
98
98
99
    /**
99
    /**
100
     * Used to get a relationship type by ID
100
     * Used to get a relationship type by ID
101
     */
101
     */
102
    @Override
102
    @Override
103
    public RelationshipType listRelTypeById(int relTypeID)
103
    public RelationshipType getRelTypeById(int relTypeID)
104
    {
104
    {
105
        RelationshipType relType = null;
105
        RelationshipType relType = null;
106
        try
106
        try
107
        {
107
        {
108
            relType = (RelationshipType) session.get(RelationshipType.class,
108
            relType = (RelationshipType) session.get(RelationshipType.class,
109
                    relTypeID);
109
                    relTypeID);
110
        }
110
        }
111
        catch (Exception e)
111
        catch (Exception e)
112
        {
112
        {
113
            e.printStackTrace();
113
            e.printStackTrace();
114
            // TODO: Logging
114
            // TODO: Logging
115
        }
115
        }
116
        return relType;
116
        return relType;
117
    }
117
    }
118
}
118
}
119
 
119