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.myportal.business.icon;
35
36 import fr.paris.lutece.portal.service.plugin.Plugin;
37 import fr.paris.lutece.util.sql.DAOUtil;
38
39 import java.util.ArrayList;
40 import java.util.List;
41
42
43
44
45
46
47 public class IconDAO implements IIconDAO
48 {
49 private static final String SQL_QUERY_NEW_PK = "SELECT max( id_icon ) FROM myportal_icon";
50 private static final String SQL_QUERY_FIND_BY_PRIMARY_KEY = "SELECT id_icon,name,mime_type,file_value,width,height,display_fo"
51 + " FROM myportal_icon WHERE id_icon=?";
52 private static final String SQL_QUERY_SELECT_ICON = "SELECT id_icon,name,mime_type,width,height,display_fo" + " FROM myportal_icon ORDER BY name DESC ";
53 private static final String SQL_QUERY_INSERT = "INSERT INTO myportal_icon "
54 + "(id_icon,name,mime_type,file_value,width,height,display_fo)VALUES(?,?,?,?,?,?,?)";
55 private static final String SQL_QUERY_UPDATE = "UPDATE myportal_icon SET id_icon=?,name=?,mime_type=?,file_value=?,width=?,height=?,display_fo=?"
56 + " WHERE id_icon=?";
57 private static final String SQL_QUERY_UPDATE_METADATA = "UPDATE myportal_icon SET id_icon=?,name=?,width=?,height=?,display_fo=?" + " WHERE id_icon=?";
58 private static final String SQL_QUERY_DELETE = "DELETE FROM myportal_icon WHERE id_icon=? ";
59
60 private static final String SQL_QUERY_FIND_ICON_FO = "SELECT id_icon,name,mime_type,width,height,display_fo" + " FROM myportal_icon WHERE display_fo=?";
61
62
63
64
65
66
67
68
69 private int newPrimaryKey( Plugin plugin )
70 {
71 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_NEW_PK, plugin );
72 daoUtil.executeQuery( );
73
74 int nKey;
75
76 if ( !daoUtil.next( ) )
77 {
78
79 nKey = 1;
80 }
81
82 nKey = daoUtil.getInt( 1 ) + 1;
83 daoUtil.free( );
84
85 return nKey;
86 }
87
88
89
90
91
92
93
94 public synchronized void insert( Icon icon, Plugin plugin )
95 {
96 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_INSERT, plugin );
97
98 int nPos = 0;
99 icon.setId( newPrimaryKey( plugin ) );
100
101 daoUtil.setInt( ++nPos, icon.getId( ) );
102 daoUtil.setString( ++nPos, icon.getName( ) );
103 daoUtil.setString( ++nPos, icon.getMimeType( ) );
104 daoUtil.setBytes( ++nPos, icon.getValue( ) );
105 daoUtil.setInt( ++nPos, icon.getWidth( ) );
106 daoUtil.setInt( ++nPos, icon.getHeight( ) );
107 daoUtil.setBoolean( ++nPos, icon.getDispolayFO( ) );
108 daoUtil.executeUpdate( );
109 daoUtil.free( );
110 }
111
112
113
114
115
116
117
118 public void store( Icon icon, Plugin plugin )
119 {
120 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_UPDATE, plugin );
121
122 int nPos = 0;
123
124 daoUtil.setInt( ++nPos, icon.getId( ) );
125 daoUtil.setString( ++nPos, icon.getName( ) );
126 daoUtil.setString( ++nPos, icon.getMimeType( ) );
127 daoUtil.setBytes( ++nPos, icon.getValue( ) );
128 daoUtil.setInt( ++nPos, icon.getWidth( ) );
129 daoUtil.setInt( ++nPos, icon.getHeight( ) );
130 daoUtil.setBoolean( ++nPos, icon.getDispolayFO( ) );
131
132 daoUtil.setInt( ++nPos, icon.getId( ) );
133 daoUtil.executeUpdate( );
134 daoUtil.free( );
135 }
136
137 public void storeMetadata( Icon icon, Plugin plugin )
138 {
139 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_UPDATE_METADATA, plugin );
140
141 int nPos = 0;
142
143 daoUtil.setInt( ++nPos, icon.getId( ) );
144 daoUtil.setString( ++nPos, icon.getName( ) );
145 daoUtil.setInt( ++nPos, icon.getWidth( ) );
146 daoUtil.setInt( ++nPos, icon.getHeight( ) );
147 daoUtil.setBoolean( ++nPos, icon.getDispolayFO( ) );
148
149 daoUtil.setInt( ++nPos, icon.getId( ) );
150 daoUtil.executeUpdate( );
151 daoUtil.free( );
152 }
153
154
155
156
157
158
159 public Icon load( int nIdIcon, Plugin plugin )
160 {
161 Icon icon = null;
162 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_FIND_BY_PRIMARY_KEY, plugin );
163
164 daoUtil.setInt( 1, nIdIcon );
165
166 daoUtil.executeQuery( );
167
168 int nPos = 0;
169
170 if ( daoUtil.next( ) )
171 {
172 icon = new Icon( );
173 icon.setId( daoUtil.getInt( ++nPos ) );
174 icon.setName( daoUtil.getString( ++nPos ) );
175 icon.setMimeType( daoUtil.getString( ++nPos ) );
176 icon.setValue( daoUtil.getBytes( ++nPos ) );
177 icon.setWidth( daoUtil.getInt( ++nPos ) );
178 icon.setHeight( daoUtil.getInt( ++nPos ) );
179 icon.setDispolayFO( daoUtil.getBoolean( ++nPos ) );
180 }
181
182 daoUtil.free( );
183
184 return icon;
185 }
186
187
188
189
190
191
192 public void delete( int nIdIcon, Plugin plugin )
193 {
194 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_DELETE, plugin );
195
196 daoUtil.setInt( 1, nIdIcon );
197 daoUtil.executeUpdate( );
198 daoUtil.free( );
199 }
200
201
202
203
204
205
206 public List<Icon> selectAll( Plugin plugin )
207 {
208 Icon icon = null;
209 List<Icon> listIcon = new ArrayList<Icon>( );
210
211 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT_ICON, plugin );
212 daoUtil.executeQuery( );
213
214 int nPos;
215
216 while ( daoUtil.next( ) )
217 {
218 nPos = 0;
219 icon = new Icon( );
220 icon.setId( daoUtil.getInt( ++nPos ) );
221 icon.setName( daoUtil.getString( ++nPos ) );
222 icon.setMimeType( daoUtil.getString( ++nPos ) );
223 icon.setWidth( daoUtil.getInt( ++nPos ) );
224 icon.setHeight( daoUtil.getInt( ++nPos ) );
225 icon.setDispolayFO( daoUtil.getBoolean( ++nPos ) );
226
227 listIcon.add( icon );
228 }
229
230 daoUtil.free( );
231
232 return listIcon;
233 }
234
235
236
237
238
239
240 public List<Icon> selectIconFO( boolean displayInFo, Plugin plugin )
241 {
242 Icon icon = null;
243 List<Icon> listIcon = new ArrayList<Icon>( );
244
245 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_FIND_ICON_FO, plugin );
246 daoUtil.setBoolean( 1, displayInFo );
247 daoUtil.executeQuery( );
248
249 int nPos;
250
251 while ( daoUtil.next( ) )
252 {
253 nPos = 0;
254 icon = new Icon( );
255 icon.setId( daoUtil.getInt( ++nPos ) );
256 icon.setName( daoUtil.getString( ++nPos ) );
257 icon.setMimeType( daoUtil.getString( ++nPos ) );
258 icon.setWidth( daoUtil.getInt( ++nPos ) );
259 icon.setHeight( daoUtil.getInt( ++nPos ) );
260 icon.setDispolayFO( daoUtil.getBoolean( ++nPos ) );
261
262 listIcon.add( icon );
263 }
264
265 daoUtil.free( );
266
267 return listIcon;
268 }
269
270 }