Datasets:

ArXiv:
License:
File size: 1,789 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
59
60
61
62
63
64
65
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> {
    @Override
    public Promocao get(Long id) {
        EntityManager em = this.getEntityManager();
        Promocao promocao = em.getReference(Promocao.class, id);
        em.close();
        
        return promocao;
    }
     @Override
     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;
    }
    
    @Override
    public void save(Promocao promocao) throws EntityExistsException {
        EntityManager em = this.getEntityManager();
        EntityTransaction tx = em.getTransaction();
        tx.begin();
     
        em.persist(promocao);
      
        tx.commit();
        em.close();
    }
    
    @Override
    public void update(Promocao promocao) {
        EntityManager em = this.getEntityManager();
        EntityTransaction tx = em.getTransaction();
        tx.begin();
        em.merge(promocao);

        tx.commit();
        em.close();
    }
    
    @Override
    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();
    }
}