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