1 | |
package br.mia.test.model.dao; |
2 | |
|
3 | |
import java.io.IOException; |
4 | |
import java.sql.SQLException; |
5 | |
import java.util.List; |
6 | |
|
7 | |
import org.hibernate.Session; |
8 | |
|
9 | |
import br.mia.test.model.Atividade; |
10 | |
import br.mia.test.model.Build; |
11 | |
import br.mia.test.model.Projeto; |
12 | |
|
13 | 0 | public class DAOTarefa |
14 | |
{ |
15 | |
|
16 | 0 | public Atividade insert(Atividade atividade, Build build, Projeto projeto) |
17 | |
throws InstantiationException, IllegalAccessException, |
18 | |
ClassNotFoundException, SQLException, IOException { |
19 | 0 | |
20 | 0 | Session session = HibernateUtil.getSession(); |
21 | 0 | |
22 | 0 | session.beginTransaction(); |
23 | 0 | |
24 | 0 | atividade.setBuild(build); |
25 | |
|
26 | 0 | atividade.setProjeto(projeto); |
27 | 0 | |
28 | 0 | session.save(atividade); |
29 | 0 | |
30 | 0 | build.getAtividades().add(atividade); |
31 | |
|
32 | 0 | session.getTransaction().commit(); |
33 | |
|
34 | 0 | session.flush(); |
35 | 0 | |
36 | 0 | return atividade; |
37 | 0 | } |
38 | 0 | |
39 | |
public void update(Atividade atividade) throws InstantiationException, |
40 | 0 | IllegalAccessException, ClassNotFoundException, SQLException, |
41 | |
IOException { |
42 | 0 | |
43 | 0 | Session session = HibernateUtil.getSession(); |
44 | 0 | |
45 | 0 | session.beginTransaction(); |
46 | 0 | |
47 | |
|
48 | 0 | session.update(atividade); |
49 | 0 | |
50 | |
|
51 | 0 | |
52 | 0 | session.getTransaction().commit(); |
53 | 0 | |
54 | 0 | session.flush(); |
55 | 0 | |
56 | 0 | |
57 | 0 | } |
58 | 0 | |
59 | 0 | public void delete(Atividade atividade) throws InstantiationException, |
60 | 0 | IllegalAccessException, ClassNotFoundException, SQLException, |
61 | |
IOException { |
62 | 0 | Session session = HibernateUtil.getSession(); |
63 | 0 | |
64 | 0 | session.beginTransaction(); |
65 | 0 | |
66 | 0 | |
67 | 0 | session.delete(atividade); |
68 | 0 | |
69 | |
|
70 | 0 | |
71 | 0 | session.getTransaction().commit(); |
72 | |
|
73 | 0 | session.flush(); |
74 | 0 | |
75 | |
|
76 | 0 | } |
77 | 0 | |
78 | 0 | public List<Atividade> select(Build build, Projeto projeto) |
79 | 0 | throws InstantiationException, IllegalAccessException, |
80 | 0 | ClassNotFoundException, SQLException, IOException { |
81 | |
|
82 | 0 | return build.getAtividades(); |
83 | |
} |
84 | |
|
85 | 0 | } |