Datasets:
ArXiv:
License:
| package br.dsw.dao; | |
| import br.dsw.pojo.Promocao; | |
| import java.util.List; | |
| import javax.persistence.EntityExistsException; | |
| import javax.persistence.EntityManager; | |
| import javax.persistence.EntityTransaction; | |
| public class PromocaoDAO extends GenericDAO<Promocao,Long> { | |
| public Promocao get(Long id) { | |
| EntityManager em = this.getEntityManager(); | |
| Promocao promocao = em.getReference(Promocao.class, id); | |
| em.close(); | |
| return promocao; | |
| } | |
| public List<Promocao> getAll() { | |
| EntityManager em = this.getEntityManager(); | |
| List<Promocao> promocoes = em.createNamedQuery("Promocao.findAll", Promocao.class).getResultList(); | |
| for(Promocao promocao:promocoes) { | |
| promocao.getTeatro(); | |
| promocao.getSiteVendas(); | |
| } | |
| em.close(); | |
| return promocoes; | |
| } | |
| public void save(Promocao promocao) throws EntityExistsException { | |
| EntityManager em = this.getEntityManager(); | |
| EntityTransaction tx = em.getTransaction(); | |
| tx.begin(); | |
| em.persist(promocao); | |
| tx.commit(); | |
| em.close(); | |
| } | |
| public void update(Promocao promocao) { | |
| EntityManager em = this.getEntityManager(); | |
| EntityTransaction tx = em.getTransaction(); | |
| tx.begin(); | |
| em.merge(promocao); | |
| tx.commit(); | |
| em.close(); | |
| } | |
| public void delete(Promocao promocao) { | |
| EntityManager em = this.getEntityManager(); | |
| EntityTransaction tx = em.getTransaction(); | |
| promocao = em.getReference(Promocao.class, promocao.getId()); | |
| tx.begin(); | |
| em.remove(promocao); | |
| tx.commit(); | |
| em.close(); | |
| } | |
| } | |