package br.com.colibri.dao;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
import br.com.colibri.modelo.Cliente;
@Repository(value="clienteHibernateDAO")
public class ClienteHibernateDAO {
@Autowired
private HibernateTemplate hibernateTemplate;
@Transactional
public void inserirCliente(Cliente cliente) throws Exception {
this.hibernateTemplate.save(cliente);
}
@Transactional
public void remover(Cliente cliente) throws Exception {
this.hibernateTemplate.delete(cliente);
}
@Transactional
public void atualizar(Cliente cliente) throws Exception {
this.hibernateTemplate.merge(cliente);
}
@Transactional
public Cliente obterPorId(Long id) throws Exception {
Cliente cliente = (Cliente) hibernateTemplate.get(Cliente.class, id);
return cliente;
}
@Transactional
public List<Cliente> obterPorNome(String nome) throws Exception {
List<Cliente> clientes = hibernateTemplate.find("from Cliente c where c.nome like ?", "%"+nome+"%");
return clientes;
}
@Transactional
public List<Cliente> obterTodosClientes() throws Exception {
List<Cliente> clientes = hibernateTemplate.find("from Cliente");
return clientes;
}
}