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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67 package fr.paris.lutece.plugins.appointment.modules.resource.business.workflow;
68
69 import fr.paris.lutece.portal.service.plugin.Plugin;
70 import fr.paris.lutece.util.sql.DAOUtil;
71
72 import java.util.ArrayList;
73 import java.util.List;
74
75
76
77
78 public class SetAppointmentResourceHistoryDAO implements ISetAppointmentResourceHistoryDAO
79 {
80 private static final String SQL_QUERY_FIND_BY_PRIMARY_KEY = "SELECT id_history,id_appointment,id_resource,id_form_resource_type FROM workflow_task_set_appointment_resource_history WHERE id=?";
81 private static final String SQL_QUERY_FIND_BY_ID_HISTORY = "SELECT id,id_history,id_appointment,id_resource,id_form_resource_type FROM workflow_task_set_appointment_resource_history WHERE id_history=?";
82 private static final String SQL_QUERY_INSERT = "INSERT INTO workflow_task_set_appointment_resource_history(id,id_history,id_appointment,id_resource,id_form_resource_type) VALUES (?,?,?,?,?)";
83 private static final String SQL_QUERY_DELETE = "DELETE FROM workflow_task_set_appointment_resource_history WHERE id = ? ";
84 private static final String SQL_QUERY_DELETE_BY_ID_APPOINTMENT = "DELETE FROM workflow_task_set_appointment_resource_history WHERE id_appointment = ? ";
85 private static final String SQL_QUEERY_NEW_PRIMARY_KEY = "SELECT MAX(id) FROM workflow_task_set_appointment_resource_history";
86
87
88
89
90
91
92
93
94 private int newPrimaryKey( Plugin plugin )
95 {
96 DAOUtil daoUtil = new DAOUtil( SQL_QUEERY_NEW_PRIMARY_KEY, plugin );
97 daoUtil.executeQuery( );
98
99 int nRes = 1;
100
101 if ( daoUtil.next( ) )
102 {
103 nRes = daoUtil.getInt( 1 ) + 1;
104 }
105
106 daoUtil.free( );
107
108 return nRes;
109 }
110
111
112
113
114 @Override
115 public synchronized void create( SetAppointmentResourceHistory history, Plugin plugin )
116 {
117 history.setId( newPrimaryKey( plugin ) );
118
119 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_INSERT, plugin );
120 int nIndex = 1;
121 daoUtil.setInt( nIndex++, history.getId( ) );
122 daoUtil.setInt( nIndex++, history.getIdHistory( ) );
123 daoUtil.setInt( nIndex++, history.getIdAppointment( ) );
124 daoUtil.setString( nIndex++, history.getIdResource( ) );
125 daoUtil.setInt( nIndex, history.getIdFormResourceType( ) );
126 daoUtil.executeUpdate( );
127 daoUtil.free( );
128 }
129
130
131
132
133 @Override
134 public SetAppointmentResourceHistory findByPrimaryKey( int nId, Plugin plugin )
135 {
136 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_FIND_BY_PRIMARY_KEY, plugin );
137 daoUtil.setInt( 1, nId );
138 daoUtil.executeQuery( );
139
140 SetAppointmentResourceHistory history;
141
142 if ( daoUtil.next( ) )
143 {
144 int nIndex = 1;
145 history = new SetAppointmentResourceHistory( );
146 history.setId( nId );
147 history.setIdHistory( daoUtil.getInt( nIndex++ ) );
148 history.setIdAppointment( daoUtil.getInt( nIndex++ ) );
149 history.setIdResource( daoUtil.getString( nIndex++ ) );
150 history.setIdFormResourceType( daoUtil.getInt( nIndex ) );
151 }
152 else
153 {
154 history = null;
155 }
156
157 daoUtil.free( );
158
159 return history;
160 }
161
162
163
164
165 @Override
166 public void delete( int nIdNotif, Plugin plugin )
167 {
168 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_DELETE, plugin );
169 daoUtil.setInt( 1, nIdNotif );
170 daoUtil.executeUpdate( );
171 daoUtil.free( );
172 }
173
174
175
176
177 @Override
178 public List<SetAppointmentResourceHistory> findByIdHistory( int nIdHistory, Plugin plugin )
179 {
180 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_FIND_BY_ID_HISTORY, plugin );
181 daoUtil.setInt( 1, nIdHistory );
182 daoUtil.executeQuery( );
183
184 List<SetAppointmentResourceHistory> listHistory = new ArrayList<SetAppointmentResourceHistory>( );
185
186 while ( daoUtil.next( ) )
187 {
188 int nIndex = 1;
189 SetAppointmentResourceHistoryodules/resource/business/workflow/SetAppointmentResourceHistory.html#SetAppointmentResourceHistory">SetAppointmentResourceHistory history = new SetAppointmentResourceHistory( );
190 history.setId( daoUtil.getInt( nIndex++ ) );
191 history.setIdHistory( daoUtil.getInt( nIndex++ ) );
192 history.setIdAppointment( daoUtil.getInt( nIndex++ ) );
193 history.setIdResource( daoUtil.getString( nIndex++ ) );
194 history.setIdFormResourceType( daoUtil.getInt( nIndex ) );
195 listHistory.add( history );
196 }
197
198 daoUtil.free( );
199
200 return listHistory;
201 }
202
203
204
205
206 @Override
207 public void deleteByIdAppointment( int nIdAppointment, Plugin plugin )
208 {
209 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_DELETE_BY_ID_APPOINTMENT, plugin );
210 daoUtil.setInt( 1, nIdAppointment );
211 daoUtil.executeUpdate( );
212 daoUtil.free( );
213 }
214 }