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
35 package fr.paris.lutece.plugins.myportal.modules.rss.business;
36
37 import fr.paris.lutece.portal.service.plugin.Plugin;
38 import fr.paris.lutece.util.ReferenceList;
39 import fr.paris.lutece.util.sql.DAOUtil;
40
41 import java.util.ArrayList;
42 import java.util.List;
43
44
45
46
47 public final class RssConfDAO implements IRssConfDAO
48 {
49
50 private static final String SQL_QUERY_NEW_PK = "SELECT max( id_rss_conf ) FROM myportal_rss_advanced_conf";
51 private static final String SQL_QUERY_SELECT = "SELECT id_rss_conf, attributeUser, attributeValue, url, idCategory, idStyleSheet FROM myportal_rss_advanced_conf WHERE id_rss_conf = ?";
52 private static final String SQL_QUERY_INSERT = "INSERT INTO myportal_rss_advanced_conf ( id_rss_conf, attributeUser, attributeValue, url, idCategory, idStyleSheet ) VALUES (?, ?, ?, ?, ?, ? ) ";
53 private static final String SQL_QUERY_DELETE = "DELETE FROM myportal_rss_advanced_conf WHERE id_rss_conf = ? ";
54 private static final String SQL_QUERY_UPDATE = "UPDATE myportal_rss_advanced_conf SET id_rss_conf = ?, attributeUser = ?, attributeValue = ?, url = ?, idCategory = ?, idStyleSheet = ? WHERE id_rss_conf = ?";
55 private static final String SQL_QUERY_SELECTALL = "SELECT id_rss_conf, attributeUser, attributeValue, url, idCategory, idStyleSheet FROM myportal_rss_advanced_conf";
56 private static final String SQL_QUERY_SELECTALL_ID = "SELECT id_rss_conf FROM myportal_rss_advanced_conf";
57 private static final String SQL_QUERY_SELECT_BY_CATEGORY = "SELECT id_rss_conf, attributeUser, attributeValue, url, idCategory, idStyleSheet FROM myportal_rss_advanced_conf WHERE idCategory = ?";
58
59
60
61
62
63
64 public int newPrimaryKey( Plugin plugin)
65 {
66 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_NEW_PK , plugin );
67 daoUtil.executeQuery( );
68 int nKey = 1;
69
70 if( daoUtil.next( ) )
71 {
72 nKey = daoUtil.getInt( 1 ) + 1;
73 }
74
75 daoUtil.free();
76 return nKey;
77 }
78
79
80
81
82 @Override
83 public void insert( RssConf rssConf, Plugin plugin )
84 {
85 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_INSERT, plugin );
86 rssConf.setId( newPrimaryKey( plugin ) );
87 int nIndex = 1;
88
89 daoUtil.setInt( nIndex++ , rssConf.getId( ) );
90 daoUtil.setString( nIndex++ , rssConf.getAttributeUser( ) );
91 daoUtil.setString( nIndex++ , rssConf.getAttributeValue( ) );
92 daoUtil.setString( nIndex++ , rssConf.getUrl( ) );
93 daoUtil.setInt( nIndex++ , rssConf.getIdCategory( ) );
94 daoUtil.setInt( nIndex++ , rssConf.getIdStyleSheet( ) );
95
96 daoUtil.executeUpdate( );
97 daoUtil.free( );
98 }
99
100
101
102
103 @Override
104 public RssConf load( int nKey, Plugin plugin )
105 {
106 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT, plugin );
107 daoUtil.setInt( 1 , nKey );
108 daoUtil.executeQuery( );
109 RssConf rssConf = null;
110
111 if ( daoUtil.next( ) )
112 {
113 rssConf = new RssConf();
114 int nIndex = 1;
115
116 rssConf.setId( daoUtil.getInt( nIndex++ ) );
117 rssConf.setAttributeUser( daoUtil.getString( nIndex++ ) );
118 rssConf.setAttributeValue( daoUtil.getString( nIndex++ ) );
119 rssConf.setUrl( daoUtil.getString( nIndex++ ) );
120 rssConf.setIdCategory( daoUtil.getInt( nIndex++ ) );
121 rssConf.setIdStyleSheet( daoUtil.getInt( nIndex++ ) );
122
123 }
124
125 daoUtil.free( );
126 return rssConf;
127 }
128
129
130
131
132 @Override
133 public void delete( int nKey, Plugin plugin )
134 {
135 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_DELETE, plugin );
136 daoUtil.setInt( 1 , nKey );
137 daoUtil.executeUpdate( );
138 daoUtil.free( );
139 }
140
141
142
143
144 @Override
145 public void store( RssConf rssConf, Plugin plugin )
146 {
147 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_UPDATE, plugin );
148 int nIndex = 1;
149
150 daoUtil.setInt( nIndex++ , rssConf.getId( ) );
151 daoUtil.setString( nIndex++ , rssConf.getAttributeUser( ) );
152 daoUtil.setString( nIndex++ , rssConf.getAttributeValue( ) );
153 daoUtil.setString( nIndex++ , rssConf.getUrl( ) );
154 daoUtil.setInt( nIndex++ , rssConf.getIdCategory( ) );
155 daoUtil.setInt( nIndex++ , rssConf.getIdStyleSheet( ) );
156
157 daoUtil.setInt( nIndex , rssConf.getId( ) );
158
159 daoUtil.executeUpdate( );
160 daoUtil.free( );
161 }
162
163
164
165
166 @Override
167 public List<RssConf> selectRssConfsList( Plugin plugin )
168 {
169 List<RssConf> rssConfList = new ArrayList<RssConf>( );
170 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECTALL, plugin );
171 daoUtil.executeQuery( );
172
173 while ( daoUtil.next( ) )
174 {
175 RssConf rssConf = new RssConf( );
176 int nIndex = 1;
177
178 rssConf.setId( daoUtil.getInt( nIndex++ ) );
179 rssConf.setAttributeUser( daoUtil.getString( nIndex++ ) );
180 rssConf.setAttributeValue( daoUtil.getString( nIndex++ ) );
181 rssConf.setUrl( daoUtil.getString( nIndex++ ) );
182 rssConf.setIdCategory( daoUtil.getInt( nIndex++ ) );
183 rssConf.setIdStyleSheet( daoUtil.getInt( nIndex++ ) );
184
185
186 rssConfList.add( rssConf );
187 }
188
189 daoUtil.free( );
190 return rssConfList;
191 }
192
193
194
195
196 @Override
197 public List<Integer> selectIdRssConfsList( Plugin plugin )
198 {
199 List<Integer> rssConfList = new ArrayList<Integer>( );
200 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECTALL_ID, plugin );
201 daoUtil.executeQuery( );
202
203 while ( daoUtil.next( ) )
204 {
205 rssConfList.add( daoUtil.getInt( 1 ) );
206 }
207
208 daoUtil.free( );
209 return rssConfList;
210 }
211
212
213
214
215 @Override
216 public ReferenceList selectRssConfsReferenceList( Plugin plugin )
217 {
218 ReferenceList rssConfList = new ReferenceList();
219 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECTALL, plugin );
220 daoUtil.executeQuery( );
221
222 while ( daoUtil.next( ) )
223 {
224 rssConfList.addItem( daoUtil.getInt( 1 ) , daoUtil.getString( 2 ) );
225 }
226
227 daoUtil.free( );
228 return rssConfList;
229 }
230
231
232
233
234 @Override
235 public List<RssConf> loadByCategory( int nIdCategory, Plugin plugin )
236 {
237
238 List<RssConf> rssConfList = new ArrayList<RssConf>( );
239
240 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT_BY_CATEGORY, plugin );
241 daoUtil.setInt( 1 , nIdCategory );
242 daoUtil.executeQuery( );
243
244 while ( daoUtil.next( ) )
245 {
246 RssConf rssConf = new RssConf( );
247 int nIndex = 1;
248
249 rssConf.setId( daoUtil.getInt( nIndex++ ) );
250 rssConf.setAttributeUser( daoUtil.getString( nIndex++ ) );
251 rssConf.setAttributeValue( daoUtil.getString( nIndex++ ) );
252 rssConf.setUrl( daoUtil.getString( nIndex++ ) );
253 rssConf.setIdCategory( daoUtil.getInt( nIndex++ ) );
254 rssConf.setIdStyleSheet( daoUtil.getInt( nIndex++ ) );
255
256
257 rssConfList.add( rssConf );
258 }
259
260 daoUtil.free( );
261 return rssConfList;
262 }
263 }