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.appointment.modules.resource.business;
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 public class AppointmentFormResourceTypeDAO implements IAppointmentFormResourceTypeDAO
46 {
47 private static final String SQL_QUERY_NEW_PRIMARY_KEY = " SELECT MAX(id) FROM appointment_resource_form_rt ";
48 private static final String SQL_QUERY_SELECT = " SELECT id, id_appointment_form, resource_type_name, description, is_app_admin_user, is_localization FROM appointment_resource_form_rt ";
49 private static final String SQL_QUERY_SELECT_BY_PRIMARY_KEY = SQL_QUERY_SELECT + " WHERE id = ? ";
50 private static final String SQL_QUERY_SELECT_BY_ID_APPOINTMENT_FORM = SQL_QUERY_SELECT + " WHERE id_appointment_form = ? ";
51
52
53 private static final String SQL_QUERY_INSERT = " INSERT INTO appointment_resource_form_rt ( id, id_appointment_form, resource_type_name, description, is_app_admin_user, is_localization ) VALUES (?,?,?,?,?,?) ";
54 private static final String SQL_QUERY_UPDATE = " UPDATE appointment_resource_form_rt SET description = ?, is_app_admin_user = ?, is_localization = ? WHERE id = ? ";
55 private static final String SQL_QUERY_RESET_APP_ADMIN_USER = "UPDATE appointment_resource_form_rt SET is_app_admin_user = 0 WHERE id_appointment_form= ? ";
56 private static final String SQL_QUERY_RESET_APP_LOCALIZATION = "UPDATE appointment_resource_form_rt SET is_localization = 0 WHERE id_appointment_form= ? ";
57 private static final String SQL_QUERY_DELETE = " DELETE FROM appointment_resource_form_rt WHERE id = ? ";
58 private static final String SQL_QUERY_DELETE_FROM_ID_FORM = " DELETE FROM appointment_resource_form_rt WHERE id_appointment_form = ? ";
59
60
61
62
63
64
65
66
67 private int newPrimaryKey( Plugin plugin )
68 {
69 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_NEW_PRIMARY_KEY, plugin );
70 daoUtil.executeQuery( );
71
72 int nRes = 1;
73
74 if ( daoUtil.next( ) )
75 {
76 nRes = daoUtil.getInt( 1 ) + 1;
77 }
78
79 daoUtil.free( );
80
81 return nRes;
82 }
83
84
85
86
87 @Override
88 public synchronized void insert( AppointmentFormResourceType formResourceType, Plugin plugin )
89 {
90 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_INSERT, plugin );
91 int nIndex = 1;
92 formResourceType.setId( newPrimaryKey( plugin ) );
93 daoUtil.setInt( nIndex++, formResourceType.getId( ) );
94 daoUtil.setInt( nIndex++, formResourceType.getIdAppointmentForm( ) );
95 daoUtil.setString( nIndex++, formResourceType.getResourceTypeName( ) );
96 daoUtil.setString( nIndex++, formResourceType.getDescription( ) );
97 daoUtil.setBoolean( nIndex++, formResourceType.getIsAppointmentAdminUser( ) );
98 daoUtil.setBoolean( nIndex, formResourceType.getIsLocation( ) );
99 daoUtil.executeUpdate( );
100 daoUtil.free( );
101 }
102
103
104
105
106 @Override
107 public void update( AppointmentFormResourceType formResourceType, Plugin plugin )
108 {
109 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_UPDATE, plugin );
110 int nIndex = 1;
111 daoUtil.setString( nIndex++, formResourceType.getDescription( ) );
112 daoUtil.setBoolean( nIndex++, formResourceType.getIsAppointmentAdminUser( ) );
113 daoUtil.setBoolean( nIndex++, formResourceType.getIsLocation( ) );
114 daoUtil.setInt( nIndex, formResourceType.getId( ) );
115 daoUtil.executeUpdate( );
116 daoUtil.free( );
117 }
118
119
120
121
122 @Override
123 public void remove( int nId, Plugin plugin )
124 {
125 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_DELETE, plugin );
126 int nIndex = 1;
127 daoUtil.setInt( nIndex, nId );
128 daoUtil.executeUpdate( );
129 daoUtil.free( );
130 }
131
132
133
134
135 @Override
136 public void removeFromIdAppointmentForm( int nIdAppointmentForm, Plugin plugin )
137 {
138 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_DELETE_FROM_ID_FORM, plugin );
139 int nIndex = 1;
140 daoUtil.setInt( nIndex, nIdAppointmentForm );
141 daoUtil.executeUpdate( );
142 daoUtil.free( );
143 }
144
145
146
147
148 @Override
149 public AppointmentFormResourceType findByPrimaryKey( int nId, Plugin plugin )
150 {
151 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT_BY_PRIMARY_KEY, plugin );
152 daoUtil.setInt( 1, nId );
153 daoUtil.executeQuery( );
154
155 AppointmentFormResourceType formResourceType = null;
156
157 if ( daoUtil.next( ) )
158 {
159 formResourceType = getFormResourceTypeFromDAO( daoUtil );
160 }
161
162 daoUtil.free( );
163
164 return formResourceType;
165 }
166
167
168
169
170 @Override
171 public List<AppointmentFormResourceType> findResourceTypesListFromIdForm( int nIdAppointmentForm, Plugin plugin )
172 {
173 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT_BY_ID_APPOINTMENT_FORM, plugin );
174 daoUtil.setInt( 1, nIdAppointmentForm );
175 daoUtil.executeQuery( );
176
177 List<AppointmentFormResourceType> listFormResourceTypes = new ArrayList<AppointmentFormResourceType>( );
178
179 while ( daoUtil.next( ) )
180 {
181 listFormResourceTypes.add( getFormResourceTypeFromDAO( daoUtil ) );
182 }
183
184 daoUtil.free( );
185
186 return listFormResourceTypes;
187 }
188
189
190
191
192 @Override
193 public void resetAppAdminUser( int nIdAppointmentForm, Plugin plugin )
194 {
195 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_RESET_APP_ADMIN_USER, plugin );
196 daoUtil.setInt( 1, nIdAppointmentForm );
197 daoUtil.executeUpdate( );
198 daoUtil.free( );
199 }
200
201
202
203
204 @Override
205 public void resetLocalization( int nIdAppointmentForm, Plugin plugin )
206 {
207 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_RESET_APP_LOCALIZATION, plugin );
208 daoUtil.setInt( 1, nIdAppointmentForm );
209 daoUtil.executeUpdate( );
210 daoUtil.free( );
211 }
212
213
214
215
216
217
218
219
220
221
222 private AppointmentFormResourceType getFormResourceTypeFromDAO( DAOUtil daoUtil )
223 {
224 AppointmentFormResourceTypeource/business/AppointmentFormResourceType.html#AppointmentFormResourceType">AppointmentFormResourceType formResourceType = new AppointmentFormResourceType( );
225 int nIndex = 1;
226 formResourceType.setId( daoUtil.getInt( nIndex++ ) );
227 formResourceType.setIdAppointmentForm( daoUtil.getInt( nIndex++ ) );
228 formResourceType.setResourceTypeName( daoUtil.getString( nIndex++ ) );
229 formResourceType.setDescription( daoUtil.getString( nIndex++ ) );
230 formResourceType.setIsAppointmentAdminUser( daoUtil.getBoolean( nIndex++ ) );
231 formResourceType.setIsLocation( daoUtil.getBoolean( nIndex ) );
232
233 return formResourceType;
234 }
235 }