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
68
69 package fr.paris.lutece.plugins.releaser.business;
70
71 import fr.paris.lutece.portal.service.plugin.Plugin;
72 import fr.paris.lutece.util.ReferenceList;
73 import fr.paris.lutece.util.sql.DAOUtil;
74 import java.sql.Statement;
75
76 import java.util.ArrayList;
77 import java.util.List;
78
79
80
81
82 public final class WorkflowContextHistoryDAO implements IWorkflowContextHistoryDAO
83 {
84
85 private static final String SQL_QUERY_SELECT = "SELECT id_wf_context, date_begin, date_end, artifact_id,data, user_name FROM releaser_workflow_context_history WHERE id_wf_context = ?";
86 private static final String SQL_QUERY_INSERT = "INSERT INTO releaser_workflow_context_history ( date_begin, date_end, artifact_id,data, user_name ) VALUES ( ?, ?, ?, ?, ?) ";
87 private static final String SQL_QUERY_DELETE = "DELETE FROM releaser_workflow_context_history WHERE id_wf_context = ? ";
88 private static final String SQL_QUERY_UPDATE = "UPDATE releaser_workflow_context_history SET id_wf_context = ?, date_begin = ?, date_end = ?, artifact_id= ?, data = ?, user_name = ? WHERE id_wf_context = ?";
89 private static final String SQL_QUERY_SELECTALL = "SELECT id_wf_context, date_begin, date_end, artifact_id ,data, user_name FROM releaser_workflow_context_history";
90 private static final String FILTER_BY_ARTIFACT_ID = " WHERE artifact_id= ?";
91
92
93
94
95 @Override
96 public void insert( WorkflowContextHistory workflowContext, Plugin plugin )
97 {
98 try ( DAOUtil daoUtil = new DAOUtil( SQL_QUERY_INSERT, Statement.RETURN_GENERATED_KEYS, plugin ) )
99 {
100 int nIndex = 1;
101 daoUtil.setTimestamp( nIndex++, workflowContext.getDateBegin( ) );
102 daoUtil.setTimestamp( nIndex++, workflowContext.getDateEnd( ) );
103 daoUtil.setString( nIndex++, workflowContext.getArtifactId( ) );
104 daoUtil.setString( nIndex++, workflowContext.getData( ) );
105 daoUtil.setString( nIndex++, workflowContext.getUser( ) );
106
107 daoUtil.executeUpdate( );
108 if ( daoUtil.nextGeneratedKey( ) )
109 {
110 workflowContext.setId( daoUtil.getGeneratedKeyInt( 1 ) );
111 }
112 }
113
114 }
115
116
117
118
119 @Override
120 public WorkflowContextHistory load( int nKey, Plugin plugin )
121 {
122 try ( DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT, plugin ) )
123 {
124 daoUtil.setInt( 1, nKey );
125 daoUtil.executeQuery( );
126 WorkflowContextHistory workflowContext = null;
127
128 if ( daoUtil.next( ) )
129 {
130 workflowContext = new WorkflowContextHistory( );
131 int nIndex = 1;
132
133 workflowContext.setId( daoUtil.getInt( nIndex++ ) );
134
135 workflowContext.setDateBegin( daoUtil.getTimestamp( nIndex++ ) );
136 workflowContext.setDateEnd( daoUtil.getTimestamp( nIndex++ ) );
137 workflowContext.setArtifactId( daoUtil.getString( nIndex++ ) );
138 workflowContext.setData( daoUtil.getString( nIndex++ ) );
139 workflowContext.setUser( daoUtil.getString( nIndex ) );
140 }
141
142 daoUtil.free( );
143 return workflowContext;
144 }
145 }
146
147
148
149
150 @Override
151 public void delete( int nKey, Plugin plugin )
152 {
153 try ( DAOUtil daoUtil = new DAOUtil( SQL_QUERY_DELETE, plugin ) )
154 {
155 daoUtil.setInt( 1, nKey );
156 daoUtil.executeUpdate( );
157 daoUtil.free( );
158 }
159 }
160
161
162
163
164 @Override
165 public void store( WorkflowContextHistory workflowContext, Plugin plugin )
166 {
167 try ( DAOUtil daoUtil = new DAOUtil( SQL_QUERY_UPDATE, plugin ) )
168 {
169 int nIndex = 1;
170
171 daoUtil.setInt( nIndex++, workflowContext.getId( ) );
172
173 daoUtil.setTimestamp( nIndex++, workflowContext.getDateBegin( ) );
174 daoUtil.setTimestamp( nIndex++, workflowContext.getDateEnd( ) );
175 daoUtil.setString( nIndex++, workflowContext.getArtifactId( ) );
176 daoUtil.setString( nIndex++, workflowContext.getData( ) );
177 daoUtil.setString( nIndex++, workflowContext.getUser( ) );
178 daoUtil.setInt( nIndex, workflowContext.getId( ) );
179
180 daoUtil.executeUpdate( );
181 daoUtil.free( );
182 }
183 }
184
185
186
187
188 @Override
189 public List<WorkflowContextHistory> selectWorkflowDeployContextsList( Plugin plugin )
190 {
191 List<WorkflowContextHistory> workflowContextList = new ArrayList<>( );
192 try ( DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECTALL, plugin ) )
193 {
194 daoUtil.executeQuery( );
195
196 while ( daoUtil.next( ) )
197 {
198 WorkflowContextHistorylowContextHistory.html#WorkflowContextHistory">WorkflowContextHistory workflowContext = new WorkflowContextHistory( );
199 int nIndex = 1;
200
201 workflowContext.setId( daoUtil.getInt( nIndex++ ) );
202 workflowContext.setDateBegin( daoUtil.getTimestamp( nIndex++ ) );
203 workflowContext.setDateEnd( daoUtil.getTimestamp( nIndex++ ) );
204 workflowContext.setArtifactId( daoUtil.getString( nIndex++ ) );
205 workflowContext.setData( daoUtil.getString( nIndex++ ) );
206 workflowContext.setUser( daoUtil.getString( nIndex ) );
207
208 workflowContextList.add( workflowContext );
209 }
210
211 daoUtil.free( );
212 return workflowContextList;
213 }
214 }
215
216
217
218
219 @Override
220 public List<WorkflowContextHistory> selectWorkflowDeployContextsListByArtifactId( Plugin plugin, String strArtifactId )
221 {
222 List<WorkflowContextHistory> workflowContextList = new ArrayList<>( );
223 try ( DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECTALL + FILTER_BY_ARTIFACT_ID, plugin ) )
224 {
225
226 daoUtil.setString( 1, strArtifactId );
227 daoUtil.executeQuery( );
228 while ( daoUtil.next( ) )
229 {
230 WorkflowContextHistorylowContextHistory.html#WorkflowContextHistory">WorkflowContextHistory workflowContext = new WorkflowContextHistory( );
231 int nIndex = 1;
232
233 workflowContext.setId( daoUtil.getInt( nIndex++ ) );
234 workflowContext.setDateBegin( daoUtil.getTimestamp( nIndex++ ) );
235 workflowContext.setDateEnd( daoUtil.getTimestamp( nIndex++ ) );
236 workflowContext.setArtifactId( daoUtil.getString( nIndex++ ) );
237 workflowContext.setData( daoUtil.getString( nIndex++ ) );
238 workflowContext.setUser( daoUtil.getString( nIndex ) );
239
240 workflowContextList.add( workflowContext );
241 }
242
243 daoUtil.free( );
244 return workflowContextList;
245 }
246 }
247
248 }