/*
 * Created on Feb 23, 2006
 *
 * 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.demographic.hibernate;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

import org.hibernate.Query;

import gov.va.med.fw.persistent.DAOException;
import gov.va.med.fw.persistent.hibernate.AbstractDAOImpl;
import gov.va.med.esr.common.persistent.demographic.ConfidentialAddressCategoryDAO;
import gov.va.med.esr.common.infra.ImpreciseDate;
import gov.va.med.esr.common.model.lookup.AddressType;
import gov.va.med.esr.common.model.lookup.BadAddressReason;
import gov.va.med.esr.common.model.lookup.ConfidentialAddressCategoryType;
import gov.va.med.esr.common.model.party.Address;
import gov.va.med.esr.common.model.party.ConfidentialAddressCategory;
import gov.va.med.esr.common.model.person.Person;

/**
 * @author DNS   HURAND
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */


public class ConfidentialAddressCategoryDAOImpl extends AbstractDAOImpl implements ConfidentialAddressCategoryDAO {
	                                                                               
	  private static final long serialVersionUID = -395329300598826545L;
	  private static final String Get_ConfAddrCategory_By_PersonID_SQL = "getConfAddrCategoryByPersonId";
      private static final String PERSON_ID_PARAM = "personId";
    
      //public ConfidentialAddressCategory getConfAddCategoriesByPersonId (BigDecimal personId) throws DAOException {
      public List getConfAddCategoriesByPersonId (BigDecimal personId) throws DAOException {
    	ConfidentialAddressCategory  confidentialAddressCategory = null;
    	  List lst = null;
    	  
    	try {
    	   	//confidentialAddressCategory = this.getHibernateTemplate().findByNamedQueryAndNamedParam(getConfAddrCategoryByPersonId, PERSON_ID_PARAM, personId);
    		lst = this.getHibernateTemplate().findByNamedQueryAndNamedParam(Get_ConfAddrCategory_By_PersonID_SQL, PERSON_ID_PARAM, personId);
    	} catch( Exception e ) {
            throw new DAOException( "Failed to find ConfidentialAddressCategory by person id", e);
        }

     	//return confidentialAddressCategory;
    	return mapToconfidentialAddressCategoryList(lst);
     	//return lst;
    }
     
      private List mapToconfidentialAddressCategoryList(List lst)
      {
          if (lst == null)
              return null;
          
          List confidentialAddressCategoryList = new java.util.ArrayList();
          
          ConfidentialAddressCategory confidentialAddressCategory = null;
         
          for (int i=0; i< lst.size(); i++)
          {
              Object [] attributes = (Object []) lst.get(i);

              confidentialAddressCategory = new ConfidentialAddressCategory();
              
              if (attributes[0] != null)
            	  confidentialAddressCategory.setPerson((Person)attributes[0]);
              if (attributes[1] != null)
            	  confidentialAddressCategory.setType((ConfidentialAddressCategoryType)attributes[1]);
              
              confidentialAddressCategoryList.add(confidentialAddressCategory);
          }    
          return confidentialAddressCategoryList;
          
      }     
    
}

