Subversion Repositories bacoAlunos

Rev

Rev 38 | Rev 45 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 fvelez 1
package pt.estgp.estgweb.domain.dao.impl;
2
 
3
import jomm.dao.DaoException;
4
import org.hibernate.HibernateException;
5
import org.hibernate.Query;
6
import org.hibernate.Hibernate;
7
import static org.hibernate.criterion.Restrictions.eq;
8
 
9
 
10
import java.util.List;
11
 
12
import pt.estgp.estgweb.domain.User;
13
 
14
/**
15
 * @author Jorge Machado
16
 * @date 28/Fev/2008
17
 * @time 2:51:06
18
 * @see pt.estgp.estgweb.domain.dao.impl
19
 */
20
public class UserDaoImpl extends UserDao
21
{
22
    public static UserDaoImpl getInstance()
23
    {
24
        if (myInstance == null)
25
            myInstance = new UserDaoImpl();
26
        return (UserDaoImpl) myInstance;
27
    }
28
 
29
    /**
30
     * Used by the base DAO classes but here for your modification Load object
31
     * matching the given key and return it.
32
     *
33
     * @param username to load
34
     * @return a user
35
     */
36
    public final User loadByUsername(1.5.0/docs/api/java/lang/String.html">String username)
37
    {
38
        try
39
        {
40
            5+0%2Fdocs%2Fapi+List">List list =
41
                    createCriteria()
42
                            .add(eq("username",username))
43
                            .setMaxResults(1)
44
                            .list();
45
 
46
            if(list.size() == 0)
47
                return null;
48
            return (User) list.get(0);
49
        }
50
        catch (HibernateException e)
51
        {
52
            throw new DaoException(e);
53
        }
54
    }
55
    /**
56
     * Used by the base DAO classes but here for your modification Load object
57
     * matching the given key and return it.
58
     *
59
     * @param email to load
60
     * @return a user
61
     */
62
    public final User loadByEmail(1.5.0/docs/api/java/lang/String.html">String email)
63
    {
64
        try
65
        {
66
            return (User) createCriteria()
67
                    .add(eq("email",email))
68
                    .uniqueResult();
69
        }
70
        catch (HibernateException e)
71
        {
72
            throw new DaoException(e);
73
        }
74
    }
75
 
44 fvelez 76
     /**
77
     * Used by the base DAO classes but here for your modification Load object
78
     * matching the given key and return it.
79
     *
80
     * @param ID to load
81
     * @return a user
82
     */
38 fvelez 83
     public final User loadByID(1.5.0/docs/api/java/lang/String.html">String ID)
84
    {
85
        try
86
        {
87
            return (User) createCriteria()
88
                    .add(eq("id",ID))
89
                    .uniqueResult();
90
        }
91
        catch (HibernateException e)
92
        {
93
            throw new DaoException(e);
94
        }
95
    }
96
 
1 fvelez 97
    /**
98
     * Used by the base DAO classes but here for your modification Load object
99
     * matching the given key and return it.
100
     *
101
     * @param username to load
102
     * @param password to load
103
     * @return a user
104
     */
105
    public final User loadByUsernameAndPassword(1.5.0/docs/api/java/lang/String.html">String username, 1.5.0/docs/api/java/lang/String.html">String password)
106
    {
107
        try
108
        {
109
            return (User) createCriteria()
110
                    .add(eq("username",username))
111
                    .add(eq("password", jomm.utils.BytesUtils.getDigestMD5Hex(password)))
112
                    .uniqueResult();
113
        }
114
        catch (HibernateException e)
115
        {
116
            throw new DaoException(e);
117
        }
118
    }
119
 
120
}