package gov.va.med.esr.persistence.hibernate;

import gov.va.med.esr.model.ServiceUser;
import gov.va.med.fw.persistent.DAOException;
import gov.va.med.fw.persistent.hibernate.GenericDAOImpl;

import java.util.List;

import org.springframework.dao.DataAccessException;

public class ServiceUserDAOImpl extends GenericDAOImpl implements
		ServiceUserDAO {


	private static final long serialVersionUID = -8428717271859831697L;

	public ServiceUser getUserByUserName(String userName) throws DAOException {
		// TODO Auto-generated method stub
		try {
			String query = "select l from " + ServiceUser.class.getName() + 
				" l where  l.userName = '"+ userName  +  "'";
			
			List<?> list = getJpaTemplate().find(query);	
			return (ServiceUser) (list.size() > 0 ? list.get(0) : null);
			
		} catch (DataAccessException e) {
			throw new DAOException(e.getMessage(), e);
		}
	}

}
