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.linkpages.business.portlet;
35
36 import fr.paris.lutece.portal.business.page.Page;
37 import fr.paris.lutece.portal.business.portlet.Portlet;
38 import fr.paris.lutece.portal.service.util.AppException;
39 import fr.paris.lutece.util.ReferenceList;
40 import fr.paris.lutece.util.sql.DAOUtil;
41
42 import java.util.ArrayList;
43 import java.util.List;
44
45
46
47
48
49 public class LinkPagesPortletDAO implements ILinkPagesPortletDAO
50 {
51 private static final String SQL_QUERY_SELECT_LINKPAGES_LIST = "SELECT id_page, name FROM core_page ORDER BY name";
52 private static final String SQL_QUERY_SELECT_MAX_ORDER = "SELECT max( linkpage_order ) FROM linkpages_portlet WHERE id_portlet=?";
53 private static final String SQL_QUERY_SELECT_LINKPAGE_IN_PORTLET = " SELECT a.id_page, a.name, a.description, a.page_order, a.status, a.role, a.code_theme, a.image_content " +
54 " FROM core_page a, linkpages_portlet b WHERE a.id_page = b.id_linkpage AND b.id_portlet = ? " +
55 " ORDER BY b.linkpage_order";
56 private static final String SQL_QUERY_SELECT_LINKPAGE_ORDER = "SELECT linkpage_order FROM linkpages_portlet WHERE id_portlet = ? AND id_linkpage = ? ";
57 private static final String SQL_QUERY_DELETE = "DELETE FROM linkpages_portlet WHERE id_portlet = ?";
58 private static final String SQL_QUERY_SELECT = "SELECT id_portlet, id_page FROM core_portlet WHERE id_portlet = ?";
59 private static final String SQL_QUERY_SELECT_LINKPAGE_ID_BY_ORDER = "SELECT id_linkpage FROM linkpages_portlet WHERE id_portlet = ? AND linkpage_order = ?";
60 private static final String SQL_QUERY_UPDATE_LINKPAGE_ORDER = "UPDATE linkpages_portlet SET linkpage_order = ? WHERE id_portlet = ? AND id_linkpage = ? ";
61 private static final String SQL_QUERY_DELETE_LINKPAGE = "DELETE FROM linkpages_portlet WHERE id_portlet=? AND id_linkpage =?";
62 private static final String SQL_QUERY_DELETE_LINKPAGE_ALL = "DELETE FROM portlet_link_pages WHERE id_portlet=?";
63 private static final String SQL_QUERY_CHECK_DUPLICATE = "SELECT id_linkpage FROM linkpages_portlet WHERE id_portlet = ? AND id_linkpage = ?";
64 private static final String SQL_QUERY_INSERT_LINKPAGE = "INSERT INTO linkpages_portlet ( id_portlet, id_linkpage, linkpage_order ) VALUES (?,?,?)";
65
66
67
68 public void insert( Portlet portlet )
69 {
70 }
71
72
73
74
75
76
77 public void delete( int nPortletId )
78 {
79 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_DELETE );
80 daoUtil.setInt( 1, nPortletId );
81 daoUtil.executeUpdate( );
82 daoUtil.free( );
83 }
84
85
86
87
88
89
90
91 public Portlet load( int nPortletId )
92 {
93 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT );
94 daoUtil.setInt( 1, nPortletId );
95 daoUtil.executeQuery( );
96
97 LinkPagesPortletges/business/portlet/LinkPagesPortlet.html#LinkPagesPortlet">LinkPagesPortlet portlet = new LinkPagesPortlet( );
98
99 if ( daoUtil.next( ) )
100 {
101 portlet.setId( daoUtil.getInt( 1 ) );
102 portlet.setPageId( daoUtil.getInt( 2 ) );
103 }
104
105 daoUtil.free( );
106
107 return portlet;
108 }
109
110 public void store( Portlet portlet ) throws AppException
111 {
112 }
113
114
115
116
117
118
119 public ReferenceList selectLinkPagesList( )
120 {
121 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT_LINKPAGES_LIST );
122 daoUtil.executeQuery( );
123
124 ReferenceList list = new ReferenceList( );
125
126 while ( daoUtil.next( ) )
127 {
128 list.addItem( daoUtil.getInt( 1 ), daoUtil.getString( 2 ) );
129 }
130
131 daoUtil.free( );
132
133 return list;
134 }
135
136
137
138
139
140
141
142 public int selectMaxOrder( int nPortletId )
143 {
144 int nOrder = 0;
145 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT_MAX_ORDER );
146 daoUtil.setInt( 1, nPortletId );
147 daoUtil.executeQuery( );
148
149 if ( daoUtil.next( ) )
150 {
151 nOrder = daoUtil.getInt( 1 );
152 }
153
154 daoUtil.free( );
155
156 return nOrder;
157 }
158
159
160
161
162
163
164
165 public List<Page> selectLinkPagesInPortletList( int nPortletId )
166 {
167 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT_LINKPAGE_IN_PORTLET );
168 daoUtil.setInt( 1, nPortletId );
169 daoUtil.executeQuery( );
170
171 List<Page> list = new ArrayList<Page>( );
172
173 while ( daoUtil.next( ) )
174 {
175 Page page = new Page( );
176 page.setId( daoUtil.getInt( 1 ) );
177 page.setName( daoUtil.getString( 2 ) );
178 page.setDescription( daoUtil.getString( 3 ) );
179 page.setOrder( daoUtil.getInt( 4 ) );
180 page.setStatus( daoUtil.getInt( 5 ) );
181 page.setRole( daoUtil.getString( 6 ) );
182 page.setCodeTheme( daoUtil.getString( 7 ) );
183 page.setImageContent( daoUtil.getBytes( 8 ) );
184 list.add( page );
185 }
186
187 daoUtil.free( );
188
189 return list;
190 }
191
192
193
194
195
196
197
198
199 public int selectLinkPageOrder( int nPortletId, int nPageId )
200 {
201 int nOrder = 0;
202 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT_LINKPAGE_ORDER );
203 daoUtil.setInt( 1, nPortletId );
204 daoUtil.setInt( 2, nPageId );
205 daoUtil.executeQuery( );
206
207 if ( daoUtil.next( ) )
208 {
209 nOrder = daoUtil.getInt( 1 );
210 }
211
212 daoUtil.free( );
213
214 return nOrder;
215 }
216
217
218
219
220
221
222
223
224 public int selectLinkPageIdByOrder( int nPortletId, int nOrder )
225 {
226 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT_LINKPAGE_ID_BY_ORDER );
227 daoUtil.setInt( 1, nPortletId );
228 daoUtil.setInt( 2, nOrder );
229 daoUtil.executeQuery( );
230
231 if ( !daoUtil.next( ) )
232 {
233 throw new AppException( DAOUtil.MSG_EXCEPTION_SELECT_ERROR + "(PortletId = " + nPortletId + "; Order = " +
234 nOrder + ")" );
235 }
236
237 int nId = daoUtil.getInt( 1 );
238 daoUtil.free( );
239
240 return nId;
241 }
242
243
244
245
246
247
248
249
250 public void storeLinkPageOrder( int nOrder, int nPortletId, int nLinkPageId )
251 {
252 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_UPDATE_LINKPAGE_ORDER );
253 daoUtil.setInt( 1, nOrder );
254 daoUtil.setInt( 2, nPortletId );
255 daoUtil.setInt( 3, nLinkPageId );
256 daoUtil.executeUpdate( );
257 daoUtil.free( );
258 }
259
260
261
262
263
264
265
266 public void deleteLinkPage( int nPortletId, int nLinkPageId )
267 {
268 if ( ( nLinkPageId != 0 ) )
269 {
270 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_DELETE_LINKPAGE );
271 daoUtil.setInt( 1, nPortletId );
272 daoUtil.setInt( 2, nLinkPageId );
273 daoUtil.executeUpdate( );
274 daoUtil.free( );
275 }
276 }
277
278
279
280
281
282
283 public void deleteAllLinkPages( int nPortletId )
284 {
285 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_DELETE_LINKPAGE_ALL );
286 daoUtil.setInt( 1, nPortletId );
287 daoUtil.executeUpdate( );
288 daoUtil.free( );
289 }
290
291
292
293
294
295
296
297
298 public boolean testDuplicate( int nPortletId, int nLinkPageId )
299 {
300 boolean bDuplicate = false;
301 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_CHECK_DUPLICATE );
302 daoUtil.setInt( 1, nPortletId );
303 daoUtil.setInt( 2, nLinkPageId );
304 daoUtil.executeQuery( );
305
306 if ( daoUtil.next( ) )
307 {
308 bDuplicate = true;
309 }
310
311 daoUtil.free( );
312
313 return bDuplicate;
314 }
315
316
317
318
319
320
321
322
323 public void insertLinkPage( int nPortletId, int nLinkPageId, int nOrder )
324 {
325 if ( ( nLinkPageId != 0 ) )
326 {
327 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_INSERT_LINKPAGE );
328 daoUtil.setInt( 1, nPortletId );
329 daoUtil.setInt( 2, nLinkPageId );
330 daoUtil.setInt( 3, nOrder );
331 daoUtil.executeUpdate( );
332 daoUtil.free( );
333 }
334 }
335 }