View Javadoc

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   * Provides methods for event package access.
12   *
13   * @author Michael Darsow
14   * @version $Revision: 1.2 $ $Date: 2008/01/28 12:33:08 $
15   * @deprecated use {@link HistoryEventMapper} instead.
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     * Inserts a new enzyme creation event into the <code>FUTURE_EVENTS</code> table.
56     *
57     * @param enzymeId The enzyme ID.
58     * @param con      The connection.
59     * @throws SQLException
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  //      con.commit();
70  //    } catch (SQLException e) {
71  //      con.rollback();
72  //      throw e;
73      } finally {
74        if (cStmt != null) cStmt.close();
75      }
76    }
77  
78    /**
79     * Updates a new enzyme creation event in the <code>FUTURE_EVENTS</code> table.
80     *
81     * @param groupId   The enzyme ID of the original enzyme.
82     * @param eventId   The enzyme ID of the cloned enzyme.
83     * @param newStatus ...
84     * @param con       ...
85     * @throws SQLException
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  //      con.commit();
97  //    } catch (SQLException e) {
98  //      con.rollback();
99  //      throw e;
100     } finally {
101     	if (cStmt != null) cStmt.close();
102     }
103   }
104 
105   /**
106    * Inserts a new enzyme creation event into the <code>FUTURE_EVENTS</code> table.
107    *
108    * @param beforeId The enzyme ID of the original enzyme.
109    * @param afterId  The enzyme ID of the cloned enzyme.
110    * @param con      The connection.
111    * @throws SQLException
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 //      con.commit();
123 //    } catch (SQLException e) {
124 //      con.rollback();
125 //      throw e;
126     } finally {
127     	if (cStmt != null) cStmt.close();
128     }
129   }
130 
131   /**
132    * Updates a new enzyme creation event in the <code>FUTURE_EVENTS</code> table.
133    *
134    * @param groupId   The event group ID.
135    * @param eventId   The event ID.
136    * @param newStatus ...
137    * @param con       ...
138    * @throws SQLException
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 //      con.commit();
150 //    } catch (SQLException e) {
151 //      con.rollback();
152 //      throw e;
153     } finally {
154     	if (cStmt != null) cStmt.close();
155     }
156   }
157 
158   /**
159    * Inserts a new transfer event into the <code>FUTURE_EVENTS</code> table.
160    *
161    * @param beforeId The enzyme ID of the original enzyme.
162    * @param afterId  The enzyme ID of the cloned enzyme.
163    * @param comment  History comment added to this transfer event.
164    * @param con      The connection.
165    * @throws SQLException
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 //      con.commit();
181 //    } catch (SQLException e) {
182 //      con.rollback();
183 //      throw e;
184     } finally {
185     	if (cStmt != null) cStmt.close();
186     }
187   }
188 
189   /**
190    * Updates a transferred enzyme (target and origin) event in the <code>FUTURE_EVENTS</code> table.
191    *
192    * @param groupId           The enzyme ID of the original enzyme.
193    * @param eventId           The enzyme ID of the cloned enzyme.
194    * @param newHistoryComment ...
195    * @param newStatus         ...
196    * @param con               ...
197    * @throws SQLException
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 //      con.commit();
211 //    } catch (SQLException e) {
212 //      con.rollback();
213 //      throw e;
214     } finally {
215     	if (cStmt != null) cStmt.close();
216     }
217   }
218 
219   /**
220    * Inserts a new deletion event into the <code>FUTURE_EVENTS</code> table.
221    *
222    * @param beforeId The enzyme ID of the original enzyme.
223    * @param afterId  The enzyme ID of the cloned enzyme.
224    * @param comment  History comment added to this deletion event.
225    * @param con      The connection.
226    * @throws SQLException
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 //      con.commit();
240 //    } catch (SQLException e) {
241 //      con.rollback();
242 //      throw e;
243     } finally {
244     	if (cStmt != null) cStmt.close();
245     }
246   }
247 
248   /**
249    * Updates a future deletion event.
250    *
251    * @param groupId   ...
252    * @param eventId   ...
253    * @param comment   ...
254    * @param newStatus The new status of the enzyme.
255    * @param con       The connection.
256    * @throws SQLException
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 //      con.commit();
269 //    } catch (SQLException e) {
270 //      con.rollback();
271 //      throw e;
272     } finally {
273     	if (cStmt != null) cStmt.close();
274     }
275   }
276 }