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.gru.business.demandtype;
35
36 import fr.paris.lutece.portal.service.plugin.Plugin;
37 import fr.paris.lutece.util.ReferenceList;
38 import fr.paris.lutece.util.sql.DAOUtil;
39
40 import java.util.ArrayList;
41 import java.util.List;
42
43
44
45
46 public final class DemandTypeActionDAO implements IDemandTypeActionDAO
47 {
48
49 private static final String SQL_QUERY_NEW_PK = "SELECT max( id_demand_type_action ) FROM gru_demand_type_action";
50 private static final String SQL_QUERY_SELECT = "SELECT a.id_demand_type_action, a.action_link, a.action_label, a.id_demand_type, b.title "
51 + " FROM gru_demand_type_action a, gru_demand_type b WHERE a.id_demand_type = b.id_demand_type AND id_demand_type_action = ?";
52 private static final String SQL_QUERY_INSERT = "INSERT INTO gru_demand_type_action ( id_demand_type_action, action_link, action_label, id_demand_type ) VALUES ( ?, ?, ?, ? ) ";
53 private static final String SQL_QUERY_DELETE = "DELETE FROM gru_demand_type_action WHERE id_demand_type_action = ? ";
54 private static final String SQL_QUERY_UPDATE = "UPDATE gru_demand_type_action SET id_demand_type_action = ?, action_link = ?, action_label = ?, id_demand_type = ? WHERE id_demand_type_action = ?";
55 private static final String SQL_QUERY_SELECTALL = "SELECT a.id_demand_type_action, a.action_link, a.action_label, a.id_demand_type, b.title "
56 + " FROM gru_demand_type_action a, gru_demand_type b WHERE a.id_demand_type = b.id_demand_type ";
57 private static final String SQL_QUERY_SELECTALL_ID = "SELECT id_demand_type_action FROM gru_demand_type_action";
58 private static final String SQL_QUERY_SELECT_BY_TYPE = "SELECT a.id_demand_type_action, a.action_link, a.action_label, a.id_demand_type, b.title "
59 + " FROM gru_demand_type_action a, gru_demand_type b WHERE a.id_demand_type = b.id_demand_type AND a.id_demand_type = ?";
60
61
62
63
64
65
66
67
68 public int newPrimaryKey( Plugin plugin )
69 {
70 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_NEW_PK, plugin );
71 daoUtil.executeQuery( );
72
73 int nKey = 1;
74
75 if ( daoUtil.next( ) )
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 void insert( DemandTypeAction demandTypeAction, Plugin plugin )
90 {
91 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_INSERT, plugin );
92
93 demandTypeAction.setId( newPrimaryKey( plugin ) );
94
95 daoUtil.setInt( 1, demandTypeAction.getId( ) );
96 daoUtil.setString( 2, demandTypeAction.getLink( ) );
97 daoUtil.setString( 3, demandTypeAction.getLabel( ) );
98 daoUtil.setInt( 4, demandTypeAction.getIdDemandType( ) );
99
100 daoUtil.executeUpdate( );
101 daoUtil.free( );
102 }
103
104
105
106
107 @Override
108 public DemandTypeAction load( int nKey, Plugin plugin )
109 {
110 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT, plugin );
111 daoUtil.setInt( 1, nKey );
112 daoUtil.executeQuery( );
113
114 DemandTypeAction demandTypeAction = null;
115
116 if ( daoUtil.next( ) )
117 {
118 demandTypeAction = new DemandTypeAction( );
119 demandTypeAction.setId( daoUtil.getInt( 1 ) );
120 demandTypeAction.setLink( daoUtil.getString( 2 ) );
121 demandTypeAction.setLabel( daoUtil.getString( 3 ) );
122 demandTypeAction.setIdDemandType( daoUtil.getInt( 4 ) );
123 demandTypeAction.setDemandType( daoUtil.getString( 5 ) );
124 }
125
126 daoUtil.free( );
127
128 return demandTypeAction;
129 }
130
131
132
133
134 @Override
135 public void delete( int nKey, Plugin plugin )
136 {
137 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_DELETE, plugin );
138 daoUtil.setInt( 1, nKey );
139 daoUtil.executeUpdate( );
140 daoUtil.free( );
141 }
142
143
144
145
146 @Override
147 public void store( DemandTypeAction demandTypeAction, Plugin plugin )
148 {
149 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_UPDATE, plugin );
150
151 daoUtil.setInt( 1, demandTypeAction.getId( ) );
152 daoUtil.setString( 2, demandTypeAction.getLink( ) );
153 daoUtil.setString( 3, demandTypeAction.getLabel( ) );
154 daoUtil.setInt( 4, demandTypeAction.getIdDemandType( ) );
155 daoUtil.setInt( 5, demandTypeAction.getId( ) );
156
157 daoUtil.executeUpdate( );
158 daoUtil.free( );
159 }
160
161
162
163
164 @Override
165 public List<DemandTypeAction> selectDemandTypeActionsList( Plugin plugin )
166 {
167 List<DemandTypeAction> demandTypeActionList = new ArrayList<DemandTypeAction>( );
168 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECTALL, plugin );
169 daoUtil.executeQuery( );
170
171 while ( daoUtil.next( ) )
172 {
173 DemandTypeActionmandtype/DemandTypeAction.html#DemandTypeAction">DemandTypeAction demandTypeAction = new DemandTypeAction( );
174
175 demandTypeAction.setId( daoUtil.getInt( 1 ) );
176 demandTypeAction.setLink( daoUtil.getString( 2 ) );
177 demandTypeAction.setLabel( daoUtil.getString( 3 ) );
178 demandTypeAction.setIdDemandType( daoUtil.getInt( 4 ) );
179 demandTypeAction.setDemandType( daoUtil.getString( 5 ) );
180
181 demandTypeActionList.add( demandTypeAction );
182 }
183
184 daoUtil.free( );
185
186 return demandTypeActionList;
187 }
188
189
190
191
192 @Override
193 public List<Integer> selectIdDemandTypeActionsList( Plugin plugin )
194 {
195 List<Integer> demandTypeActionList = new ArrayList<Integer>( );
196 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECTALL_ID, plugin );
197 daoUtil.executeQuery( );
198
199 while ( daoUtil.next( ) )
200 {
201 demandTypeActionList.add( daoUtil.getInt( 1 ) );
202 }
203
204 daoUtil.free( );
205
206 return demandTypeActionList;
207 }
208
209
210
211
212 @Override
213 public List<DemandTypeAction> selectActionsByType( int nDemandTypeId, Plugin plugin )
214 {
215 List<DemandTypeAction> demandTypeActionList = new ArrayList<DemandTypeAction>( );
216 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT_BY_TYPE, plugin );
217 daoUtil.setInt( 1, nDemandTypeId );
218 daoUtil.executeQuery( );
219
220 while ( daoUtil.next( ) )
221 {
222 DemandTypeActionmandtype/DemandTypeAction.html#DemandTypeAction">DemandTypeAction demandTypeAction = new DemandTypeAction( );
223
224 demandTypeAction.setId( daoUtil.getInt( 1 ) );
225 demandTypeAction.setLink( daoUtil.getString( 2 ) );
226 demandTypeAction.setLabel( daoUtil.getString( 3 ) );
227 demandTypeAction.setIdDemandType( daoUtil.getInt( 4 ) );
228 demandTypeAction.setDemandType( daoUtil.getString( 5 ) );
229
230 demandTypeActionList.add( demandTypeAction );
231 }
232
233 daoUtil.free( );
234
235 return demandTypeActionList;
236 }
237
238
239
240
241 @Override
242 public ReferenceList selectActionsReferenceList( Plugin plugin )
243 {
244 ReferenceList list = new ReferenceList( );
245 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECTALL, plugin );
246 daoUtil.executeQuery( );
247
248 while ( daoUtil.next( ) )
249 {
250 list.addItem( daoUtil.getInt( 1 ), daoUtil.getString( 5 ) + " - " + daoUtil.getString( 3 ) );
251 }
252
253 daoUtil.free( );
254
255 return list;
256 }
257 }