Statistics
| Branch: | Revision:

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

History | View | Annotate | Download (2.57 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.UserTacDAO;
15
import my.com.upass.pojo.TacBean;
16
import net.penril.generic.hibernate.GenericDAOHibernate;
17

    
18
import org.apache.log4j.Logger;
19
import org.hibernate.Criteria;
20
import org.hibernate.FetchMode;
21
import org.hibernate.HibernateException;
22
import org.hibernate.Session;
23
import org.hibernate.criterion.Restrictions;
24

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

    
31
public class UserTacDAOHibernate
32
                extends GenericDAOHibernate<TacBean, String>
33
                implements UserTacDAO {
34

    
35
        private static Logger logger = Logger.getLogger(UserTacDAOHibernate.class);
36

    
37
        /**
38
         * @see my.com.upass.dao.UserTacDAO#getTacFromStore(java.lang.String, int)
39
         */
40
        @Override
41
        public TacBean getTacFromStore(String userAlias, int appId) {
42

    
43
                TacBean tac = null;
44
                Criteria criteria;
45
                Session session = null;
46

    
47
                try {
48
                        session = getSession();
49
                        criteria = session.createCriteria(TacBean.class);
50
                        criteria.setFetchMode("upassUser", FetchMode.JOIN);
51
                        criteria.createAlias("upassUser", "u");
52
                        criteria.add(Restrictions.eq("u.userAlias", userAlias));
53
                        criteria.add(Restrictions.eq("u.applicationId", appId));
54
                        tac = (TacBean) criteria.uniqueResult();
55

    
56
                } catch (Exception e) {
57
                        logger.error(e, e);
58

    
59
                } finally {
60
                        if (session != null && session.isConnected()) {
61
                                session.close();
62
                        }
63
                }
64
                return tac;
65
        }
66

    
67
        /**
68
         * @see my.com.upass.dao.UserTacDAO#updateTacToStore(my.com.upass.pojo.TacBean)
69
         */
70
        @Override
71
        public boolean updateTacToStore(TacBean tacBean) {
72
                boolean isUpdated = false;
73
                Session session = null;
74

    
75
                try {
76
                        session = getSession();
77
                        session.beginTransaction();
78
                        session.update(tacBean);
79
                        session.getTransaction().commit();
80
                        isUpdated = true;
81

    
82
                } catch (Exception e) {
83
                        if (e instanceof HibernateException) {
84
                                if (session != null) {
85
                                        session.getTransaction().rollback();
86
                                }
87
                        }
88
                        logger.error(e, e);
89
                } finally {
90
                        if (session != null && session.isConnected()) {
91
                                session.close();
92
                        }
93
                }
94
                return isUpdated;
95
        }
96
}