Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package br.luck.dal; import br.luck.interfaces.ModalidadeDAO; import br.luck.configuracao.HibernateUtil; import br.luck.model.LotofacilModel; import br.luck.util.Queries; import br.luck.util.Util; import java.io.Serializable; import java.util.List; import org.hibernate.Query; import org.hibernate.Session; /** * * @author filipi */ public class LotofacilModelDAO implements ModalidadeDAO<LotofacilModel>, Serializable { private Session session = HibernateUtil.getSessionFactory().getCurrentSession(); private List<LotofacilModel> lista; public LotofacilModelDAO() { } public LotofacilModelDAO(List<LotofacilModel> lista) { this.lista = lista; } public Session getSession() { return session; } public List<LotofacilModel> getLista() { return lista; } public void setLista(List<LotofacilModel> lista) { this.lista = lista; } @Override public void salvar() { for (LotofacilModel concurso : getLista()) { getSession().save(concurso); } } @Override public void salvar(LotofacilModel m) { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } @Override public void excluir() { for (LotofacilModel concurso : getLista()) { getSession().delete(concurso); } } @Override public void excluir(LotofacilModel m) { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } @Override public List<LotofacilModel> listarModalidade() { Query query; query = getSession().createQuery(Queries.RETORNA_TODOS_CONCURSOS_LOTOFACIL); return query.list(); } @Override public List<LotofacilModel> listarModalidade(int first, int pageSize) { Query query; query = getSession().createQuery(Queries.RETORNA_TODOS_CONCURSOS_LOTOFACIL); query.setFirstResult(first); query.setMaxResults(pageSize); return query.list(); } @Override public int contarTotalRegistros() { Query query; query = getSession().createQuery(Queries.CONTA_CONCURSOS_LOTOFACIL); Number result = (Number) query.uniqueResult(); return result.intValue(); } }