package jp.ossc.petstore.dao.impl;

import java.util.List;

import jp.ossc.petstore.dao.ICustomerDAO;
import jp.ossc.petstore.dao.impl.BaseDAO;
import jp.ossc.petstore.model.Customer;

/**
 * 顧客情報テーブルアクセスクラス
 * @author ossc
 * @version $Revision: 1.2 $
 */
public class CustomerDAO extends BaseDAO implements ICustomerDAO {

	private static final String HQL_GET_CUSTOMER =
		"from Customer where id = ? and password = ?";
	
	
	/* (非 Javadoc)
	 * @see jp.ossc.petstore.dao.ICustomerDAO#getCustomer(String,String)
	 */
	public Customer getCustomer(String userId, String password) {
		
		Customer customer = null;

		// パラメータ設定
		Object[] params = new Object[]{
				new Integer(userId),
				password};

		// 顧客情報取得
		List list = getHibernateTemplate().find(HQL_GET_CUSTOMER, params);
		
		// 取得レコードが１件の場合のみ検索結果を返却する
		if (list.size() == 1) {
			customer = (Customer)list.get(0);
		}
		
		return customer;
	}


	/* (非 Javadoc)
	 * @see jp.ossc.petstore.dao.ICustomerDAO#getCustomer(java.lang.String)
	 */
	public Customer getCustomer(String userId) {
		return (Customer)getHibernateTemplate().get(Customer.class, new Integer(userId));
	}

}
