/*
 * Created on May 31, 2005
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package gov.va.med.esr.common.persistent.comms.hibernate;

import java.util.List;

import org.springframework.dao.DataAccessException;

import gov.va.med.esr.common.model.comms.CommsBulletin;
import gov.va.med.esr.common.persistent.comms.CommsEmailBulletinDAO;
import gov.va.med.fw.persistent.DAOException;
import gov.va.med.fw.persistent.hibernate.AbstractDAOImpl;


/**
 * @author DNS   TSAIG
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class CommsEmailBulletinDAOImpl extends AbstractDAOImpl implements CommsEmailBulletinDAO{
    
    private static final long serialVersionUID = 2735149151895253725L;

    public CommsBulletin findEmailBulletinById(String id) throws DAOException 
    {
		try {

			List lst = super.getHibernateTemplate().find("from CommsBulletin bul where bul.identifier = ?", id);
			
			if (lst != null && lst.size()>0)
			    return (CommsBulletin) lst.get(0);
			
	    }
	    catch( DataAccessException e ) {
	        throw new DAOException( "Failed to find Email Bulletin by by id:" + id, e);
	    }
	    
        return null;
    }
    
    public CommsBulletin findEmailBulletinByName(String name) throws DAOException
    {
		try {

			List lst = super.getHibernateTemplate().find("from CommsBulletin bul where bul.commsBulletinName = ?", name);
			
			if (lst != null && lst.size()>0)
			    return (CommsBulletin) lst.get(0);
	    }
	    catch( DataAccessException e ) {
	        throw new DAOException( "Failed to find Email Bulletin by name:" + name, e);
	    }
	    
        return null;
    }
    
    public void insert(CommsBulletin emailBulletin) throws DAOException 
    {
        super.saveObject(emailBulletin);
        
    }


}
