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