Statistics
| Branch: | Revision:

m2u-upass-core / src / my / com / upass / dao / hibernate / UserMasterDAOHibernate.java @ 0:02300db8682b

History | View | Annotate | Download (2.96 KB)

1
/**
2
 * Copyright (M) 2011 Penril Datability (M) Sdn Bhd All rights reserved.
3
 *
4
 * This software is copyrighted. Under the copyright laws, this software
5
 * may not be copied, in whole or in part, without prior written consent
6
 * of Penril Datability (M) Sdn Bhd or its assignees. This software is
7
 * provided under the terms of a license between Penril Datability (M)
8
 * Sdn Bhd and the recipient, and its use is subject to the terms of that
9
 * license.
10
 */
11

    
12
package my.com.upass.dao.hibernate;
13

    
14
import my.com.upass.dao.TbAmUsermasDAO;
15
import my.com.upass.pojo.UserMasterBean;
16
import net.penril.generic.hibernate.GenericDAOHibernate;
17

    
18
import org.hibernate.Criteria;
19
import org.hibernate.HibernateException;
20
import org.hibernate.criterion.Restrictions;
21

    
22
/**
23
 * 
24
 * PROGRAMMER: Danniell CHANGE-NO: TASK-NO: DATE CREATED: Aug 3, 2011 TAG AS:
25
 * REASON(S): MODIFICATION:
26
 */
27

    
28
public class UserMasterDAOHibernate extends
29
                GenericDAOHibernate<UserMasterBean, Long> implements TbAmUsermasDAO
30
{
31
        public UserMasterBean getTbAmUsermasByUserId (Integer tUserId)
32
                        throws Exception
33
        {
34
                UserMasterBean TbAmUserMas;
35
                try
36
                {
37
                        getSession ().beginTransaction ();
38

    
39
                        Criteria m_oCriteria = getSession ().createCriteria (
40
                                        UserMasterBean.class);
41
                        m_oCriteria.add (Restrictions.eq ("userId", tUserId));
42
                        TbAmUserMas = (UserMasterBean) m_oCriteria.uniqueResult ();
43

    
44
                        getSession ().getTransaction ().commit ();
45
                }
46
                catch (Exception e)
47
                {
48
                        if (e instanceof HibernateException)
49
                        {
50
                                getSession ().getTransaction ().rollback ();
51
                        }
52
                        throw e;
53
                }
54
                finally
55
                {
56
                        getSession ().close ();
57
                }
58
                return TbAmUserMas;
59
        }
60

    
61
        public UserMasterBean getTbAmUsermasByUserAlias (String userAlias)
62
                        throws Exception
63
        {
64
                UserMasterBean TbAmUserMas;
65
                try
66
                {
67
                        getSession ().beginTransaction ();
68

    
69
                        Criteria m_oCriteria = getSession ().createCriteria (
70
                                        UserMasterBean.class);
71
                        m_oCriteria.add (Restrictions.eq ("userAlias", userAlias));
72
                        TbAmUserMas = (UserMasterBean) m_oCriteria.uniqueResult ();
73

    
74
                        getSession ().getTransaction ().commit ();
75
                }
76
                catch (Exception e)
77
                {
78
                        if (e instanceof HibernateException)
79
                        {
80
                                getSession ().getTransaction ().rollback ();
81
                        }
82
                        throw e;
83
                }
84
                finally
85
                {
86
                        getSession ().close ();
87
                }
88
                return TbAmUserMas;
89
        }
90

    
91
        public void deleteTbAmUsermas (Integer tUserId) throws Exception
92
        {
93
                Long ID = Long.valueOf (String.valueOf (tUserId));
94
                UserMasterBean tbAmUsermas;
95
                try
96
                {
97
                        getSession ().beginTransaction ();
98
                        Criteria m_oCriteria = getSession ().createCriteria (
99
                                        UserMasterBean.class);
100
                        m_oCriteria.add (Restrictions.eq ("userId", ID));
101
                        tbAmUsermas = (UserMasterBean) m_oCriteria.uniqueResult ();
102

    
103
                        makeTransient (tbAmUsermas);
104
                        getSession ().getTransaction ().commit ();
105
                        getSession ().close ();
106
                }
107
                catch (Exception e)
108
                {
109
                        getSession ().getTransaction ().rollback ();
110
                        throw e;
111
                }
112
                finally
113
                {
114
                        getSession ().close ();
115
                }
116
        }
117
}