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 package fr.paris.lutece.plugins.announce.business.portlet;
35
36 import fr.paris.lutece.plugins.announce.service.AnnouncePlugin;
37 import fr.paris.lutece.portal.business.portlet.Portlet;
38 import fr.paris.lutece.util.sql.DAOUtil;
39
40
41
42
43 public final class LastAnnouncesPortletDAO implements ILastAnnouncesPortletDAO
44 {
45 private static final String SQL_QUERY_INSERT = " INSERT INTO announce_portlet_last_announces ( id_portlet, nb_announces ) VALUES (?,?) ";
46 private static final String SQL_QUERY_DELETE = " DELETE FROM announce_portlet_last_announces WHERE id_portlet = ? ";
47 private static final String SQL_QUERY_UPDATE = " UPDATE announce_portlet_last_announces SET nb_announces = ? WHERE id_portlet = ? ";
48 private static final String SQL_QUERY_SELECT = " SELECT nb_announces FROM announce_portlet_last_announces WHERE id_portlet = ? ";
49
50
51
52
53 @Override
54 public void insert( Portlet portlet )
55 {
56 try ( DAOUtil daoUtil = new DAOUtil( SQL_QUERY_INSERT, AnnouncePlugin.getPlugin( ) ) )
57 {
58 LastAnnouncesPortlets/lutece/plugins/announce/business/portlet/LastAnnouncesPortlet.html#LastAnnouncesPortlet">LastAnnouncesPortlet lastAnnouncesPortlet = (LastAnnouncesPortlet) portlet;
59 int nIndex = 1;
60 daoUtil.setInt( nIndex++, lastAnnouncesPortlet.getId( ) );
61 daoUtil.setInt( nIndex, lastAnnouncesPortlet.getNbAnnouncesToDisplay( ) );
62
63 daoUtil.executeUpdate( );
64 }
65 }
66
67
68
69
70 @Override
71 public void delete( int nPortletId )
72 {
73 try ( DAOUtil daoUtil = new DAOUtil( SQL_QUERY_DELETE, AnnouncePlugin.getPlugin( ) ) )
74 {
75 daoUtil.setInt( 1, nPortletId );
76 daoUtil.executeUpdate( );
77 }
78 }
79
80
81
82
83 @Override
84 public void store( Portlet portlet )
85 {
86 try ( DAOUtil daoUtil = new DAOUtil( SQL_QUERY_UPDATE, AnnouncePlugin.getPlugin( ) ) )
87 {
88 LastAnnouncesPortlets/lutece/plugins/announce/business/portlet/LastAnnouncesPortlet.html#LastAnnouncesPortlet">LastAnnouncesPortlet lastAnnouncesPortlet = (LastAnnouncesPortlet) portlet;
89 int nIndex = 1;
90 daoUtil.setInt( nIndex++, lastAnnouncesPortlet.getNbAnnouncesToDisplay( ) );
91 daoUtil.setInt( nIndex, lastAnnouncesPortlet.getId( ) );
92
93 daoUtil.executeUpdate( );
94 }
95 }
96
97
98
99
100 @Override
101 public Portlet load( int nIdPortlet )
102 {
103 LastAnnouncesPortletusiness/portlet/LastAnnouncesPortlet.html#LastAnnouncesPortlet">LastAnnouncesPortlet portlet = new LastAnnouncesPortlet( );
104 try ( DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT, AnnouncePlugin.getPlugin( ) ) )
105 {
106 daoUtil.setInt( 1, nIdPortlet );
107 portlet.setId( nIdPortlet );
108
109 if ( daoUtil.next( ) )
110 {
111 portlet.setNbAnnouncesToDisplay( daoUtil.getInt( 1 ) );
112 }
113 }
114 return portlet;
115 }
116 }