package flex.spring.samples.industry;

import java.util.List;

import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;

public class IbatisIndustryDAO extends SqlMapClientDaoSupport implements IIndustryDAO {

	private static final String INDUSTRY_NS = "Industry.";
	
	public Industry create(Industry item) {
		Integer id = (Integer) getSqlMapClientTemplate().insert(INDUSTRY_NS+"create", item);
		item.setId(id);
		return item;
	}

	@SuppressWarnings("unchecked")
	public List<Industry> findAll() {
		return getSqlMapClientTemplate().queryForList(INDUSTRY_NS+"findAll");
	}

	public Industry findById(int id) {
		return (Industry) getSqlMapClientTemplate().queryForObject(INDUSTRY_NS+"findById", id);
	}

	@SuppressWarnings("unchecked")
	public List<Industry> findByName(String name) {
		return getSqlMapClientTemplate().queryForList(INDUSTRY_NS+"findByName", "%" + name.toUpperCase() + "%");
	}

	public boolean remove(Industry item) {
		int count = getSqlMapClientTemplate().delete(INDUSTRY_NS+"remove", item);
		return (count == 1);
	}

	public boolean update(Industry item) {
		int count = getSqlMapClientTemplate().update(INDUSTRY_NS+"update", item);
		return (count == 1);
	}

}
