/*
 * Created on May 11, 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.math.BigDecimal;
import java.util.List;

import gov.va.med.esr.common.model.comms.CommsTemplate;
import gov.va.med.esr.common.persistent.comms.CommsTemplateDAO;
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 CommsTemplateDAOImpl extends AbstractDAOImpl implements CommsTemplateDAO{

    private static final long serialVersionUID = 7174484969506507125L;

    public CommsTemplate findTemplateById(BigDecimal templateId) throws DAOException
    {
		try {
 	    	//org.springframework.orm.hibernate3.HibernateTemplate t = getHibernateTemplate();
 	    	 
			List lst = super.getHibernateTemplate().find("from CommsTemplate tmpl where tmpl.identifier = ?", templateId);
			
			if (lst != null && lst.size()>0)
			    return (CommsTemplate) lst.get(0);
			
	    }
	    catch( Exception e ) {
	        throw new DAOException( "Failed to find comms template by id", e);
	    } 
        return null;
    }
    
    public List findTemplateListByFormNumber(String formNumber) throws DAOException
    {
		try {
 	    	//org.springframework.orm.hibernate3.HibernateTemplate t = getHibernateTemplate();
 	    	 
			List lst = super.getHibernateTemplate().find("from CommsTemplate tmpl where tmpl.commsTemplateFormNumber = ? order by tmpl.identifier", formNumber);
			
			return lst;
			
	    }
	    catch( Exception e ) {
	        throw new DAOException( "Failed to find comms template list by form number!", e);
	    } 
    }
    
    public List findTemplateListByLetterType(String letterTypeCd) throws DAOException
    {
		try {
 	    	//org.springframework.orm.hibernate3.HibernateTemplate t = getHibernateTemplate();
 	    	 
			List lst = super.getHibernateTemplate().find("from CommsTemplate tmpl where tmpl.letterType.code = ?", letterTypeCd);
			
			return lst;
			
	    }
	    catch( Exception e ) {
	        throw new DAOException( "Failed to find comms template list by letter type!", e);
	    } 
    }
    
    public void insert(CommsTemplate template) throws DAOException
    {
        super.saveObject(template);
    }
}
