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.MegasenaModel; 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 MegasenaModelDAO implements ModalidadeDAO<MegasenaModel>, Serializable { private Session session = HibernateUtil.getSessionFactory().getCurrentSession(); private List<MegasenaModel> lista; public MegasenaModelDAO() { } public MegasenaModelDAO(List<MegasenaModel> lista) { this.lista = lista; } public Session getSession() { return session; } protected List<MegasenaModel> getLista() { return lista; } public void setLista(List<MegasenaModel> lista) { this.lista = lista; } @Override public void salvar() { for (MegasenaModel concurso : getLista()) { getSession().save(concurso); } } @Override public void salvar(MegasenaModel m) { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } @Override public void excluir() { for (MegasenaModel concurso : getLista()) { getSession().delete(concurso); } } @Override public void excluir(MegasenaModel m) { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } @Override public List<MegasenaModel> listarModalidade() { Query query; query = getSession().createQuery(Queries.RETORNA_TODOS_CONCURSOS_MEGASENA); return query.list(); } @Override public List<MegasenaModel> listarModalidade(int first, int pageSize) { Query query; query = getSession().createQuery(Queries.RETORNA_TODOS_CONCURSOS_MEGASENA); query.setFirstResult(first); query.setMaxResults(pageSize); return query.list(); } @Override public int contarTotalRegistros() { Query query; query = getSession().createQuery(Queries.CONTA_CONCURSOS_MEGASENA); Number result = (Number) query.uniqueResult(); return result.intValue(); } }