1 package uk.ac.ebi.intenz.mapper;
2
3 import java.sql.CallableStatement;
4 import java.sql.Connection;
5 import java.sql.Date;
6 import java.sql.SQLException;
7 import java.sql.Timestamp;
8 import java.util.GregorianCalendar;
9
10
11
12
13
14
15
16
17 public class EventPackageMapper {
18
19 public EventPackageMapper() {
20 }
21
22 private String callInsertFutureCreationStatement() {
23 return "{CALL event.p_insert_future_creation(?, ?)}";
24 }
25
26 private String callUpdateFutureCreationStatement() {
27 return "{CALL event.p_update_future_creation(?, ?, ?)}";
28 }
29
30 private String callInsertFutureTransferStatement() {
31 return "{CALL event.p_insert_future_transfer(?, ?, ?, ?, ?)}";
32 }
33
34 private String callUpdateFutureTransferStatement() {
35 return "{CALL event.p_update_future_transfer(?, ?, ?, ?, ?)}";
36 }
37
38 private String callInsertFutureDeletionStatement() {
39 return "{CALL event.p_insert_future_deletion(?, ?, ?, ?, ?)}";
40 }
41
42 private String callUpdateFutureDeletionStatement() {
43 return "{CALL event.p_update_future_deletion(?, ?, ?, ?)}";
44 }
45
46 private String callInsertFutureModificationStatement() {
47 return "{CALL event.p_insert_future_modification(?, ?, ?)}";
48 }
49
50 private String callUpdateFutureModificationStatement() {
51 return "{CALL event.p_update_future_modification(?, ?, ?)}";
52 }
53
54
55
56
57
58
59
60
61 public void insertFutureCreationEvent(Long enzymeId, Connection con) throws SQLException {
62 CallableStatement cStmt = null;
63
64 try {
65 cStmt = con.prepareCall(callInsertFutureCreationStatement());
66 cStmt.setLong(1, enzymeId.longValue());
67 cStmt.setTimestamp(2, new Timestamp(System.currentTimeMillis()));
68 cStmt.execute();
69
70
71
72
73 } finally {
74 if (cStmt != null) cStmt.close();
75 }
76 }
77
78
79
80
81
82
83
84
85
86
87 public void updateFutureCreationEvent(int groupId, int eventId, String newStatus, Connection con) throws SQLException {
88 CallableStatement cStmt = null;
89
90 try {
91 cStmt = con.prepareCall(callUpdateFutureCreationStatement());
92 cStmt.setInt(1, groupId);
93 cStmt.setInt(2, eventId);
94 cStmt.setString(3, newStatus);
95 cStmt.execute();
96
97
98
99
100 } finally {
101 if (cStmt != null) cStmt.close();
102 }
103 }
104
105
106
107
108
109
110
111
112
113 public void insertFutureModificationEvent(Long beforeId, Long afterId, Connection con) throws SQLException {
114 CallableStatement cStmt = null;
115
116 try {
117 cStmt = con.prepareCall(callInsertFutureModificationStatement());
118 cStmt.setLong(1, beforeId.longValue());
119 cStmt.setLong(2, afterId.longValue());
120 cStmt.setTimestamp(3, new Timestamp(System.currentTimeMillis()));
121 cStmt.execute();
122
123
124
125
126 } finally {
127 if (cStmt != null) cStmt.close();
128 }
129 }
130
131
132
133
134
135
136
137
138
139
140 public void updateFutureModificationEvent(int groupId, int eventId, String newStatus, Connection con) throws SQLException {
141 CallableStatement cStmt = null;
142
143 try {
144 cStmt = con.prepareCall(callUpdateFutureModificationStatement());
145 cStmt.setInt(1, groupId);
146 cStmt.setInt(2, eventId);
147 cStmt.setString(3, newStatus);
148 cStmt.execute();
149
150
151
152
153 } finally {
154 if (cStmt != null) cStmt.close();
155 }
156 }
157
158
159
160
161
162
163
164
165
166
167 public void insertFutureTransferEvent(Long beforeId, Long afterId, String comment, Connection con) throws SQLException {
168 CallableStatement cStmt = null;
169 GregorianCalendar gc = new GregorianCalendar();
170 Date date = new Date(gc.getTimeInMillis());
171
172 try {
173 cStmt = con.prepareCall(callInsertFutureTransferStatement());
174 cStmt.setLong(1, beforeId.longValue());
175 cStmt.setLong(2, afterId.longValue());
176 cStmt.setTimestamp(3, new Timestamp(System.currentTimeMillis()));
177 cStmt.setString(4, comment);
178 cStmt.setString(5, "SU");
179 cStmt.execute();
180
181
182
183
184 } finally {
185 if (cStmt != null) cStmt.close();
186 }
187 }
188
189
190
191
192
193
194
195
196
197
198
199 public void updateFutureTransferEvent(int groupId, int eventId, String newHistoryComment, String newStatus, String historyLineOfDeletedEntry, Connection con) throws SQLException {
200 CallableStatement cStmt = null;
201
202 try {
203 cStmt = con.prepareCall(callUpdateFutureTransferStatement());
204 cStmt.setInt(1, groupId);
205 cStmt.setInt(2, eventId);
206 cStmt.setString(3, newStatus);
207 cStmt.setString(4, newHistoryComment);
208 cStmt.setString(5, historyLineOfDeletedEntry);
209 cStmt.execute();
210
211
212
213
214 } finally {
215 if (cStmt != null) cStmt.close();
216 }
217 }
218
219
220
221
222
223
224
225
226
227
228 public void insertFutureDeletionEvent(Long beforeId, Long afterId, String comment, Connection con) throws SQLException {
229 CallableStatement cStmt = null;
230
231 try {
232 cStmt = con.prepareCall(callInsertFutureDeletionStatement());
233 cStmt.setLong(1, beforeId.longValue());
234 cStmt.setLong(2, afterId.longValue());
235 cStmt.setTimestamp(3, new Timestamp(System.currentTimeMillis()));
236 cStmt.setString(4, comment);
237 cStmt.setString(5, "SU");
238 cStmt.execute();
239
240
241
242
243 } finally {
244 if (cStmt != null) cStmt.close();
245 }
246 }
247
248
249
250
251
252
253
254
255
256
257
258 public void updateFutureDeletionEvent(int groupId, int eventId, String comment, String newStatus, Connection con) throws SQLException {
259 CallableStatement cStmt = null;
260
261 try {
262 cStmt = con.prepareCall(callUpdateFutureDeletionStatement());
263 cStmt.setInt(1, groupId);
264 cStmt.setInt(2, eventId);
265 cStmt.setString(3, newStatus);
266 cStmt.setString(4, comment);
267 cStmt.execute();
268
269
270
271
272 } finally {
273 if (cStmt != null) cStmt.close();
274 }
275 }
276 }