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
36 package fr.paris.lutece.plugins.formresponsxpage.business;
37
38 import fr.paris.lutece.portal.service.plugin.Plugin;
39 import fr.paris.lutece.util.ReferenceList;
40 import fr.paris.lutece.util.sql.DAOUtil;
41 import java.sql.Statement;
42
43 import java.util.ArrayList;
44 import java.util.List;
45 import java.util.Map;
46
47 import java.util.Optional;
48
49 import org.apache.commons.lang3.StringUtils;
50
51
52
53
54 public final class FormsreponseeditoDAO extends AbstractFilterDao implements IFormsreponseeditoDAO
55 {
56
57 private static final String SQL_QUERY_INSERT = "INSERT INTO formresponsxpage_formsreponseedito ( labelrichtext_un, labelrichtext_deux ) VALUES ( ?, ? ) ";
58 private static final String SQL_QUERY_DELETE = "DELETE FROM formresponsxpage_formsreponseedito WHERE id_formsreponseedito = ? ";
59 private static final String SQL_QUERY_UPDATE = "UPDATE formresponsxpage_formsreponseedito SET labelrichtext_un = ?, labelrichtext_deux = ? WHERE id_formsreponseedito = ?";
60
61 private static final String SQL_QUERY_SELECTALL = "SELECT id_formsreponseedito, labelrichtext_un, labelrichtext_deux FROM formresponsxpage_formsreponseedito";
62 private static final String SQL_QUERY_SELECTALL_ID = "SELECT id_formsreponseedito FROM formresponsxpage_formsreponseedito";
63
64 private static final String SQL_QUERY_SELECTALL_BY_IDS = SQL_QUERY_SELECTALL + " WHERE id_formsreponseedito IN ( ";
65 private static final String SQL_QUERY_SELECT_BY_ID = SQL_QUERY_SELECTALL + " WHERE id_formsreponseedito = ?";
66
67
68
69
70
71 public FormsreponseeditoDAO() {
72
73 initMapSql(Formsreponseedito.class);
74 }
75
76
77
78
79 @Override
80 public void insert( Formsreponseedito formsreponseedito, Plugin plugin )
81 {
82 try( DAOUtil daoUtil = new DAOUtil( SQL_QUERY_INSERT, Statement.RETURN_GENERATED_KEYS, plugin ) )
83 {
84 int nIndex = 1;
85 daoUtil.setString( nIndex++ , formsreponseedito.getLabelrichtextUn( ) );
86 daoUtil.setString( nIndex++ , formsreponseedito.getLabelrichtextDeux( ) );
87
88 daoUtil.executeUpdate( );
89 if ( daoUtil.nextGeneratedKey( ) )
90 {
91 formsreponseedito.setId( daoUtil.getGeneratedKeyInt( 1 ) );
92 }
93 }
94
95 }
96
97
98
99
100 @Override
101 public Optional<Formsreponseedito> load( int nKey, Plugin plugin )
102 {
103 try( DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT_BY_ID, plugin ) )
104 {
105 daoUtil.setInt( 1 , nKey );
106 daoUtil.executeQuery( );
107 Formsreponseedito formsreponseedito = null;
108
109 if ( daoUtil.next( ) )
110 {
111 formsreponseedito = loadFromDaoUtil( daoUtil );
112 }
113
114 return Optional.ofNullable( formsreponseedito );
115 }
116 }
117
118
119
120
121 @Override
122 public void delete( int nKey, Plugin plugin )
123 {
124 try( DAOUtil daoUtil = new DAOUtil( SQL_QUERY_DELETE, plugin ) )
125 {
126 daoUtil.setInt( 1 , nKey );
127 daoUtil.executeUpdate( );
128 }
129 }
130
131
132
133
134 @Override
135 public void store( Formsreponseedito formsreponseedito, Plugin plugin )
136 {
137 try( DAOUtil daoUtil = new DAOUtil( SQL_QUERY_UPDATE, plugin ) )
138 {
139 int nIndex = 1;
140
141 daoUtil.setString( nIndex++ , formsreponseedito.getLabelrichtextUn( ) );
142 daoUtil.setString( nIndex++ , formsreponseedito.getLabelrichtextDeux( ) );
143 daoUtil.setInt( nIndex , formsreponseedito.getId( ) );
144
145 daoUtil.executeUpdate( );
146 }
147 }
148
149
150
151
152 @Override
153 public List<Formsreponseedito> selectFormsreponseeditosList( Plugin plugin )
154 {
155 List<Formsreponseedito> formsreponseeditoList = new ArrayList<>( );
156 try( DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECTALL, plugin ) )
157 {
158 daoUtil.executeQuery( );
159
160 while ( daoUtil.next( ) )
161 {
162 formsreponseeditoList.add( loadFromDaoUtil( daoUtil ) );
163 }
164
165 return formsreponseeditoList;
166 }
167 }
168
169
170
171
172 @Override
173 public List<Integer> selectIdFormsreponseeditosList( Plugin plugin, Map <String,String> mapFilterCriteria, String strColumnToOrder, String strSortMode )
174 {
175 List<Integer> formsreponseeditoList = new ArrayList<>( );
176
177 String strSelectStatement = prepareSelectStatement(SQL_QUERY_SELECTALL_ID, mapFilterCriteria, strColumnToOrder, strSortMode);
178
179 try( DAOUtil daoUtil = new DAOUtil( strSelectStatement, plugin ) )
180 {
181
182 int nIndex = 1;
183
184 for(Map.Entry<String, String> filter : mapFilterCriteria.entrySet()) {
185
186 if(StringUtils.isNotBlank(filter.getValue()) && _mapSql.containsKey(filter.getKey())) {
187 daoUtil.setString( nIndex++ , filter.getValue() );
188 }
189 }
190
191 daoUtil.executeQuery( );
192
193 while ( daoUtil.next( ) )
194 {
195 formsreponseeditoList.add( daoUtil.getInt( 1 ) );
196 }
197
198 return formsreponseeditoList;
199 }
200 }
201
202
203
204
205 @Override
206 public ReferenceList selectFormsreponseeditosReferenceList( Plugin plugin )
207 {
208 ReferenceList formsreponseeditoList = new ReferenceList();
209 try( DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECTALL, plugin ) )
210 {
211 daoUtil.executeQuery( );
212
213 while ( daoUtil.next( ) )
214 {
215 formsreponseeditoList.addItem( daoUtil.getInt( 1 ) , daoUtil.getString( 2 ) );
216 }
217
218 return formsreponseeditoList;
219 }
220 }
221
222
223
224
225 @Override
226 public List<Formsreponseedito> selectFormsreponseeditosListByIds( Plugin plugin, List<Integer> listIds ) {
227 List<Formsreponseedito> formsreponseeditoList = new ArrayList<>( );
228
229 StringBuilder builder = new StringBuilder( );
230
231 if ( !listIds.isEmpty( ) )
232 {
233 for( int i = 0 ; i < listIds.size(); i++ ) {
234 builder.append( "?," );
235 }
236
237 String placeHolders = builder.deleteCharAt( builder.length( ) -1 ).toString( );
238 String stmt = SQL_QUERY_SELECTALL_BY_IDS + placeHolders + ")";
239
240
241 try ( DAOUtil daoUtil = new DAOUtil( stmt, plugin ) )
242 {
243 int index = 1;
244 for( Integer n : listIds ) {
245 daoUtil.setInt( index++, n );
246 }
247
248 daoUtil.executeQuery( );
249 while ( daoUtil.next( ) )
250 {
251 formsreponseeditoList.add( loadFromDaoUtil( daoUtil ) );
252 }
253 }
254 }
255 return formsreponseeditoList;
256
257 }
258
259
260 private Formsreponseedito loadFromDaoUtil (DAOUtil daoUtil) {
261
262 Formsreponseedito formsreponseedito = new Formsreponseedito( );
263 int nIndex = 1;
264
265 formsreponseedito.setId( daoUtil.getInt( nIndex++ ) );
266 formsreponseedito.setLabelrichtextUn( daoUtil.getString( nIndex++ ) );
267 formsreponseedito.setLabelrichtextDeux( daoUtil.getString( nIndex ) );
268
269 return formsreponseedito;
270 }
271 }