Blame |
Compare with Previous |
Last modification |
View Log
| RSS feed
package pt.estgp.estgweb.domain.dao.impl;
import jomm.dao.DaoException;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Hibernate;
import static org.
hibernate.
criterion.
Restrictions.
eq;
import java.util.List;
import pt.estgp.estgweb.domain.User;
/**
* @author Jorge Machado
* @date 28/Fev/2008
* @time 2:51:06
* @see pt.estgp.estgweb.domain.dao.impl
*/
public class UserDaoImpl
extends UserDao
{
public static UserDaoImpl getInstance
()
{
if (myInstance ==
null)
myInstance =
new UserDaoImpl
();
return (UserDaoImpl
) myInstance
;
}
/**
* Used by the base DAO classes but here for your modification Load object
* matching the given key and return it.
*
* @param username to load
* @return a user
*/
public final User loadByUsername
(1.5.0/docs/api/java/lang/String.html">String username
)
{
try
{
5+0%2Fdocs%2Fapi+List">List list =
createCriteria
()
.
add(eq
("username",username
))
.
setMaxResults(1
)
.
list();
if(list.
size() == 0
)
return null;
return (User
) list.
get(0
);
}
catch (HibernateException e
)
{
throw new DaoException
(e
);
}
}
/**
* Used by the base DAO classes but here for your modification Load object
* matching the given key and return it.
*
* @param email to load
* @return a user
*/
public final User loadByEmail
(1.5.0/docs/api/java/lang/String.html">String email
)
{
try
{
return (User
) createCriteria
()
.
add(eq
("email",email
))
.
uniqueResult();
}
catch (HibernateException e
)
{
throw new DaoException
(e
);
}
}
/**
* Used by the base DAO classes but here for your modification Load object
* matching the given key and return it.
*
* @param username to load
* @param password to load
* @return a user
*/
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
)
{
try
{
return (User
) createCriteria
()
.
add(eq
("username",username
))
.
add(eq
("password", jomm.
utils.
BytesUtils.
getDigestMD5Hex(password
)))
.
uniqueResult();
}
catch (HibernateException e
)
{
throw new DaoException
(e
);
}
}
}