package cz.vavru.test.dwr.dao.ibatis;

import java.util.List;

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

import cz.vavru.test.dwr.dao.MessageDao;
import cz.vavru.test.dwr.domain.Message;
/**
 * 
 * @author vlastimil@vavru.cz (http://vavru.cz)
 *
 */
public class MessageDaoIbatisImpl extends SqlMapClientDaoSupport implements MessageDao {

	@SuppressWarnings("unchecked")
	public List<Message> getMessages(int userId) throws DataAccessException {
		return (List<Message>)getSqlMapClientTemplate().queryForList("getMessages", userId);
	}

	public void insertMessage(Message message) throws DataAccessException {
		int messageId = (Integer)getSqlMapClientTemplate().insert("insertMessage", message);
		message.setMessageId(messageId);
	}
}
