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.portal.business.xsl;
35
36 import fr.paris.lutece.portal.business.file.File;
37 import fr.paris.lutece.portal.service.plugin.Plugin;
38 import fr.paris.lutece.util.sql.DAOUtil;
39
40 import java.util.ArrayList;
41 import java.util.List;
42
43
44
45
46
47 public final class XslExportDAO implements IXslExportDAO
48 {
49
50 private static final String SQL_QUERY_NEW_PK = "SELECT max( id_xsl_export ) FROM core_xsl_export";
51 private static final String SQL_QUERY_FIND_BY_PRIMARY_KEY = "SELECT id_xsl_export,title,description,extension,id_file,plugin FROM core_xsl_export WHERE id_xsl_export = ?";
52 private static final String SQL_QUERY_INSERT = "INSERT INTO core_xsl_export( id_xsl_export,title,description,extension,id_file,plugin) VALUES(?,?,?,?,?,?)";
53 private static final String SQL_QUERY_DELETE = "DELETE FROM core_xsl_export WHERE id_xsl_export = ? ";
54 private static final String SQL_QUERY_UPDATE = "UPDATE core_xsl_export SET id_xsl_export=?,title=?,description=?,extension=?,id_file=?,plugin=? WHERE id_xsl_export = ? ";
55 private static final String SQL_QUERY_SELECT = "SELECT id_xsl_export,title,description,extension,id_file,plugin FROM core_xsl_export ";
56 private static final String SQL_WHERE = " WHERE ";
57 private static final String SQL_FILTER_PLUGIN = " plugin = ? ";
58
59
60
61
62 @Override
63 public int newPrimaryKey( )
64 {
65 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_NEW_PK );
66 daoUtil.executeQuery( );
67
68 int nKey;
69
70 if ( !daoUtil.next( ) )
71 {
72
73 nKey = 1;
74 }
75 else
76 {
77 nKey = daoUtil.getInt( 1 ) + 1;
78 }
79
80 daoUtil.free( );
81
82 return nKey;
83 }
84
85
86
87
88 @Override
89 public synchronized void insert( XslExport xslExport )
90 {
91 xslExport.setIdXslExport( newPrimaryKey( ) );
92
93 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_INSERT );
94 daoUtil.setInt( 1, xslExport.getIdXslExport( ) );
95 daoUtil.setString( 2, xslExport.getTitle( ) );
96 daoUtil.setString( 3, xslExport.getDescription( ) );
97 daoUtil.setString( 4, xslExport.getExtension( ) );
98
99 if ( xslExport.getFile( ) != null )
100 {
101 daoUtil.setInt( 5, xslExport.getFile( ).getIdFile( ) );
102 }
103 else
104 {
105 daoUtil.setIntNull( 5 );
106 }
107
108 daoUtil.setString( 6, xslExport.getPlugin( ) );
109
110 daoUtil.executeUpdate( );
111
112 daoUtil.free( );
113 }
114
115
116
117
118 @Override
119 public XslExport load( int nId )
120 {
121 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_FIND_BY_PRIMARY_KEY );
122 daoUtil.setInt( 1, nId );
123 daoUtil.executeQuery( );
124
125 XslExport xslExport = null;
126 File file = null;
127
128 if ( daoUtil.next( ) )
129 {
130 xslExport = new XslExport( );
131 xslExport.setIdXslExport( daoUtil.getInt( 1 ) );
132 xslExport.setTitle( daoUtil.getString( 2 ) );
133 xslExport.setDescription( daoUtil.getString( 3 ) );
134 xslExport.setExtension( daoUtil.getString( 4 ) );
135
136 if ( daoUtil.getObject( 5 ) != null )
137 {
138 file = new File( );
139 file.setIdFile( daoUtil.getInt( 5 ) );
140 xslExport.setFile( file );
141 }
142
143 xslExport.setPlugin( daoUtil.getString( 6 ) );
144 }
145
146 daoUtil.free( );
147
148 return xslExport;
149 }
150
151
152
153
154 @Override
155 public void delete( int nIdXslExport )
156 {
157 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_DELETE );
158 daoUtil.setInt( 1, nIdXslExport );
159 daoUtil.executeUpdate( );
160 daoUtil.free( );
161 }
162
163
164
165
166 @Override
167 public void store( XslExport xslExport )
168 {
169 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_UPDATE );
170 daoUtil.setInt( 1, xslExport.getIdXslExport( ) );
171 daoUtil.setString( 2, xslExport.getTitle( ) );
172 daoUtil.setString( 3, xslExport.getDescription( ) );
173 daoUtil.setString( 4, xslExport.getExtension( ) );
174
175 if ( xslExport.getFile( ) != null )
176 {
177 daoUtil.setInt( 5, xslExport.getFile( ).getIdFile( ) );
178 }
179 else
180 {
181 daoUtil.setIntNull( 5 );
182 }
183
184 daoUtil.setString( 6, xslExport.getPlugin( ) );
185
186 daoUtil.setInt( 7, xslExport.getIdXslExport( ) );
187 daoUtil.executeUpdate( );
188 daoUtil.free( );
189 }
190
191
192
193
194 @Override
195 public List<XslExport> selectList( )
196 {
197 List<XslExport> listXslExport = new ArrayList<XslExport>( );
198 XslExport xslExport = null;
199 File file = null;
200
201 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT );
202
203 daoUtil.executeQuery( );
204
205 while ( daoUtil.next( ) )
206 {
207 xslExport = new XslExport( );
208 xslExport.setIdXslExport( daoUtil.getInt( 1 ) );
209 xslExport.setTitle( daoUtil.getString( 2 ) );
210 xslExport.setDescription( daoUtil.getString( 3 ) );
211 xslExport.setExtension( daoUtil.getString( 4 ) );
212
213 if ( daoUtil.getObject( 5 ) != null )
214 {
215 file = new File( );
216 file.setIdFile( daoUtil.getInt( 5 ) );
217 xslExport.setFile( file );
218 }
219
220 xslExport.setPlugin( daoUtil.getString( 6 ) );
221
222 listXslExport.add( xslExport );
223 }
224
225 daoUtil.free( );
226
227 return listXslExport;
228 }
229
230
231
232
233 @Override
234 public List<XslExport> selectListByPlugin( Plugin plugin )
235 {
236 List<XslExport> listXslExport = new ArrayList<XslExport>( );
237 XslExport xslExport = null;
238 File file = null;
239
240 StringBuilder sbSql = new StringBuilder( SQL_QUERY_SELECT );
241 sbSql.append( SQL_WHERE );
242 sbSql.append( SQL_FILTER_PLUGIN );
243
244 DAOUtil daoUtil = new DAOUtil( sbSql.toString( ) );
245 daoUtil.setString( 1, plugin.getName( ) );
246 daoUtil.executeQuery( );
247
248 while ( daoUtil.next( ) )
249 {
250 xslExport = new XslExport( );
251 xslExport.setIdXslExport( daoUtil.getInt( 1 ) );
252 xslExport.setTitle( daoUtil.getString( 2 ) );
253 xslExport.setDescription( daoUtil.getString( 3 ) );
254 xslExport.setExtension( daoUtil.getString( 4 ) );
255
256 if ( daoUtil.getObject( 5 ) != null )
257 {
258 file = new File( );
259 file.setIdFile( daoUtil.getInt( 5 ) );
260 xslExport.setFile( file );
261 }
262
263 xslExport.setPlugin( daoUtil.getString( 6 ) );
264
265 listXslExport.add( xslExport );
266 }
267
268 daoUtil.free( );
269
270 return listXslExport;
271 }
272 }