Datasets:
ArXiv:
License:
| package br.dsw.dao; | |
| import br.dsw.pojo.Teatro; | |
| import java.util.List; | |
| import javax.persistence.EntityExistsException; | |
| import javax.persistence.EntityManager; | |
| import javax.persistence.EntityTransaction; | |
| public class TeatroDAO extends GenericDAO<Teatro,String> { | |
| public Teatro get(String id) { | |
| EntityManager em = this.getEntityManager(); | |
| Teatro teatro = em.find(Teatro.class, id); | |
| em.close(); | |
| return teatro; | |
| } | |
| public void save(Teatro teatro) throws EntityExistsException{ | |
| EntityManager em = this.getEntityManager(); | |
| EntityTransaction tx = em.getTransaction(); | |
| tx.begin(); | |
| em.persist(teatro); | |
| tx.commit(); | |
| em.close(); | |
| } | |
| public List<Teatro> getAll() { | |
| EntityManager em = this.getEntityManager(); | |
| List<Teatro> teatros = em.createNamedQuery("Teatro.findAll", Teatro.class).getResultList(); | |
| em.close(); | |
| return teatros; | |
| } | |
| public void update(Teatro teatro) throws EntityExistsException{ | |
| EntityManager em = this.getEntityManager(); | |
| EntityTransaction tx = em.getTransaction(); | |
| tx.begin(); | |
| em.merge(teatro); | |
| tx.commit(); | |
| em.close(); | |
| } | |
| public void delete(Teatro teatro) { | |
| EntityManager em = this.getEntityManager(); | |
| EntityTransaction tx = em.getTransaction(); | |
| teatro = em.getReference(Teatro.class, teatro.getNome()); | |
| tx.begin(); | |
| em.remove(teatro); | |
| tx.commit(); | |
| em.close(); | |
| } | |
| } | |