Rev 2018 | Rev 2069 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2009 | es | 1 | package pt.estgp.es.exemplos.hibernate.services; |
2 | |||
3 | import org.apache.log4j.Logger; |
||
4 | import pt.estgp.es.exemplos.hibernate.HibernateUtils; |
||
5 | import pt.estgp.es.exemplos.hibernate.Pagina; |
||
6 | import pt.estgp.es.exemplos.hibernate.Seccao; |
||
7 | import pt.estgp.es.exemplos.hibernate.SeccaoImpl; |
||
8 | import pt.estgp.es.exemplos.hibernate.security.logic.HasRole; |
||
9 | import pt.estgp.es.exemplos.hibernate.security.logic.IsAuthenticated; |
||
10 | import pt.estgp.es.exemplos.hibernate.security.logic.Transaction; |
||
2018 | es | 11 | import pt.estgp.es.exemplos.hibernate.web.PaginasServlet; |
2009 | es | 12 | |
2018 | es | 13 | import javax.servlet.ServletException; |
14 | |||
2009 | es | 15 | public class ServicoPaginas |
16 | { |
||
17 | |||
18 | private static final 1.5.0/docs/api/java/util/logging/Logger.html">Logger logger = 1.5.0/docs/api/java/util/logging/Logger.html">Logger.getLogger(ServicoPaginas.class); |
||
19 | |||
2049 | es | 20 | @Transaction @IsAuthenticated @HasRole(role = "admin") |
2009 | es | 21 | public void criaSeccaoService(1.5.0/docs/api/java/lang/String.html">String idPagina, 1.5.0/docs/api/java/lang/String.html">String titulo) |
22 | { |
||
2018 | es | 23 | try { |
24 | new PaginasServlet().init(); |
||
25 | } catch (ServletException e) { |
||
26 | e.printStackTrace(); |
||
27 | } |
||
2049 | es | 28 | Pagina p = (Pagina) HibernateUtils.getCurrentSession().load(Pagina.class,new 1.5.0/docs/api/java/lang/Long.html">Long(idPagina)); |
2009 | es | 29 | Seccao seccao = new SeccaoImpl(); |
30 | seccao.setTitulo(titulo); |
||
31 | p.getSeccoes().add(seccao); |
||
32 | seccao.setPagina(p); |
||
33 | |||
2049 | es | 34 | |
2009 | es | 35 | HibernateUtils.getCurrentSession().save(seccao); |
36 | } |
||
2018 | es | 37 | |
2049 | es | 38 | @Transaction @IsAuthenticated @HasRole(role = "admin") |
2009 | es | 39 | public long deleteSeccaoService(1.5.0/docs/api/java/lang/String.html">String idSeccao) |
40 | { |
||
2049 | es | 41 | Seccao seccao = (Seccao) HibernateUtils.getCurrentSession().load(Seccao.class,new 1.5.0/docs/api/java/lang/Long.html">Long(idSeccao)); |
42 | |||
43 | |||
2009 | es | 44 | long id = seccao.getPagina().getId(); |
45 | seccao.getPagina().getSeccoes().remove(seccao); |
||
46 | seccao.setPagina(null); |
||
47 | HibernateUtils.getCurrentSession().delete(seccao); |
||
48 | |||
49 | return id; |
||
2049 | es | 50 | |
2009 | es | 51 | } |
2049 | es | 52 | |
2009 | es | 53 | } |