Datasets:
ArXiv:
License:
File size: 1,634 Bytes
c574d3a |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
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> {
@Override
public Teatro get(String id) {
EntityManager em = this.getEntityManager();
Teatro teatro = em.find(Teatro.class, id);
em.close();
return teatro;
}
@Override
public void save(Teatro teatro) throws EntityExistsException{
EntityManager em = this.getEntityManager();
EntityTransaction tx = em.getTransaction();
tx.begin();
em.persist(teatro);
tx.commit();
em.close();
}
@Override
public List<Teatro> getAll() {
EntityManager em = this.getEntityManager();
List<Teatro> teatros = em.createNamedQuery("Teatro.findAll", Teatro.class).getResultList();
em.close();
return teatros;
}
@Override
public void update(Teatro teatro) throws EntityExistsException{
EntityManager em = this.getEntityManager();
EntityTransaction tx = em.getTransaction();
tx.begin();
em.merge(teatro);
tx.commit();
em.close();
}
@Override
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();
}
}
|