Subversion Repositories bacoAlunos

Rev

Rev 38 | Go to most recent revision | Details | 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
 
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 username to load
81
     * @param password to load
82
     * @return a user
83
     */
84
    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)
85
    {
86
        try
87
        {
88
            return (User) createCriteria()
89
                    .add(eq("username",username))
90
                    .add(eq("password", jomm.utils.BytesUtils.getDigestMD5Hex(password)))
91
                    .uniqueResult();
92
        }
93
        catch (HibernateException e)
94
        {
95
            throw new DaoException(e);
96
        }
97
    }
98
 
99
}