| 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 br.mia.test.model.Build; |
| 8 | |
import br.mia.test.model.Projeto; |
| 9 | |
|
| 10 | 0 | public class DAOBuild |
| 11 | |
{ |
| 12 | |
|
| 13 | 0 | public List<Build> selectBuilds(Projeto projeto) |
| 14 | |
throws InstantiationException, IllegalAccessException, |
| 15 | 0 | ClassNotFoundException, SQLException, IOException { |
| 16 | |
|
| 17 | 0 | return projeto.getBuilds(); |
| 18 | 0 | |
| 19 | |
} |
| 20 | 0 | |
| 21 | |
public Build selectBuild(int id) throws InstantiationException, |
| 22 | 0 | IllegalAccessException, ClassNotFoundException, SQLException, |
| 23 | 0 | IOException { |
| 24 | |
|
| 25 | 0 | org.hibernate.Session session = HibernateUtil.getSession(); |
| 26 | |
|
| 27 | 0 | session.beginTransaction(); |
| 28 | |
|
| 29 | 0 | Build build = (Build) session.load(Build.class, id); |
| 30 | 0 | |
| 31 | 0 | session.getTransaction().commit(); |
| 32 | 0 | |
| 33 | 0 | return build; |
| 34 | 0 | |
| 35 | 0 | } |
| 36 | 0 | |
| 37 | |
public Build update(Build build) throws InstantiationException, |
| 38 | 0 | IllegalAccessException, ClassNotFoundException, SQLException, |
| 39 | |
IOException { |
| 40 | |
|
| 41 | 0 | org.hibernate.Session session = HibernateUtil.getSession(); |
| 42 | |
|
| 43 | 0 | session.beginTransaction(); |
| 44 | |
|
| 45 | 0 | session.saveOrUpdate(build); |
| 46 | 0 | |
| 47 | 0 | session.getTransaction().commit(); |
| 48 | 0 | |
| 49 | 0 | return build; |
| 50 | 0 | } |
| 51 | |
|
| 52 | 0 | public Build insert(Build build, Projeto projeto) |
| 53 | |
throws InstantiationException, IllegalAccessException, |
| 54 | 0 | ClassNotFoundException, SQLException, IOException { |
| 55 | |
|
| 56 | 0 | org.hibernate.Session session = HibernateUtil.getSession(); |
| 57 | |
|
| 58 | 0 | |
| 59 | 0 | |
| 60 | 0 | session.beginTransaction(); |
| 61 | 0 | |
| 62 | 0 | build.setProjeto(projeto); |
| 63 | 0 | |
| 64 | 0 | session.saveOrUpdate(build); |
| 65 | 0 | |
| 66 | 0 | projeto.getBuilds().add(build); |
| 67 | 0 | |
| 68 | 0 | session.getTransaction().commit(); |
| 69 | 0 | |
| 70 | 0 | session.flush(); |
| 71 | 0 | |
| 72 | 0 | return build; |
| 73 | 0 | } |
| 74 | |
|
| 75 | 0 | public void delete(Build build) throws InstantiationException, |
| 76 | 0 | IllegalAccessException, ClassNotFoundException, SQLException, |
| 77 | 0 | IOException { |
| 78 | 0 | org.hibernate.Session session = HibernateUtil.getSession(); |
| 79 | 0 | |
| 80 | 0 | session.beginTransaction(); |
| 81 | 0 | |
| 82 | 0 | session.delete(build); |
| 83 | 0 | |
| 84 | 0 | session.getTransaction().commit(); |
| 85 | 0 | |
| 86 | 0 | session.flush(); |
| 87 | 0 | |
| 88 | 0 | } |
| 89 | 0 | |
| 90 | |
} |