package br.com.colibri.dao;
import java.util.Calendar;
import java.util.Date;
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.Locacao;
@Repository(value="locacaoHibernateDAO")
public class LocacaoHibernateDAO {
@Autowired
private HibernateTemplate hibernateTemplate;
@Transactional
public void inserirLocacao(Locacao locacao) throws Exception {
hibernateTemplate.save(locacao);
}
@Transactional
public Locacao obterPorId(Long id) throws Exception {
Locacao locacao = hibernateTemplate.get(Locacao.class, id);
return locacao;
}
@Transactional
public List<Locacao> obterTodasLocacoes() throws Exception {
List<Locacao> listaLocacoes = this.hibernateTemplate.find("from Locacao");
return listaLocacoes;
}
@Transactional
public List<Locacao> obterLocacoesVencidas() throws Exception {
Date dataHoje = new Date();
List<Locacao> listaLocacoes = this.hibernateTemplate.find("select locacao from Locacao as locacao where locacao.dtEntrega < ?", dataHoje);
return listaLocacoes;
}
}