Package br.com.colibri.dao

Source Code of br.com.colibri.dao.ClienteHibernateDAO

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;
  }

}
TOP

Related Classes of br.com.colibri.dao.ClienteHibernateDAO

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.