Rev 2018 | Go to most recent revision | Details | 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; |
||
11 | |||
12 | public class ServicoPaginas |
||
13 | { |
||
14 | |||
15 | 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); |
||
16 | |||
17 | @Transaction |
||
18 | @IsAuthenticated |
||
19 | @HasRole(role = "admin") |
||
20 | 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) |
||
21 | { |
||
22 | Pagina p = (Pagina) HibernateUtils.getCurrentSession().load(Pagina.class, new 1.5.0/docs/api/java/lang/Long.html">Long(idPagina)); |
||
23 | Seccao seccao = new SeccaoImpl(); |
||
24 | seccao.setTitulo(titulo); |
||
25 | p.getSeccoes().add(seccao); |
||
26 | seccao.setPagina(p); |
||
27 | |||
28 | HibernateUtils.getCurrentSession().save(seccao); |
||
29 | } |
||
30 | public long deleteSeccaoService(1.5.0/docs/api/java/lang/String.html">String idSeccao) |
||
31 | { |
||
32 | Seccao seccao = (Seccao) HibernateUtils.getCurrentSession().load(Seccao.class, new 1.5.0/docs/api/java/lang/Long.html">Long(idSeccao)); |
||
33 | long id = seccao.getPagina().getId(); |
||
34 | seccao.getPagina().getSeccoes().remove(seccao); |
||
35 | seccao.setPagina(null); |
||
36 | HibernateUtils.getCurrentSession().delete(seccao); |
||
37 | |||
38 | return id; |
||
39 | } |
||
40 | } |