|
27 | 27 | import java.util.Collection; |
28 | 28 | import java.util.Date; |
29 | 29 | import java.util.TimeZone; |
| 30 | +import java.util.function.IntSupplier; |
30 | 31 |
|
31 | 32 | import javax.sql.DataSource; |
32 | 33 |
|
@@ -299,38 +300,21 @@ public boolean set(int sequence, String message) throws IOException { |
299 | 300 |
|
300 | 301 | public void setNextSenderMsgSeqNum(int next) throws IOException { |
301 | 302 | cache.setNextSenderMsgSeqNum(next); |
302 | | - storeOutgoingSequenceNumbers(); |
| 303 | + storeSequenceNumber(SQL_UPDATE_OUTGOING_SEQNUM, cache::getNextSenderMsgSeqNum); |
303 | 304 | } |
304 | 305 |
|
305 | 306 | public void setNextTargetMsgSeqNum(int next) throws IOException { |
306 | 307 | cache.setNextTargetMsgSeqNum(next); |
307 | | - storeIncomingSequenceNumbers(); |
| 308 | + storeSequenceNumber(SQL_UPDATE_INCOMING_SEQNUM, cache::getNextTargetMsgSeqNum); |
308 | 309 | } |
309 | 310 |
|
310 | | - private void storeIncomingSequenceNumbers() throws IOException { |
| 311 | + private void storeSequenceNumber(String sequenceUpdateSql, IntSupplier sequence) throws IOException { |
311 | 312 | Connection connection = null; |
312 | 313 | PreparedStatement update = null; |
313 | 314 | try { |
314 | 315 | connection = dataSource.getConnection(); |
315 | | - update = connection.prepareStatement(SQL_UPDATE_INCOMING_SEQNUM); |
316 | | - update.setInt(1, cache.getNextTargetMsgSeqNum()); |
317 | | - setSessionIdParameters(update, 2); |
318 | | - update.execute(); |
319 | | - } catch (SQLException e) { |
320 | | - throw new IOException(e.getMessage(), e); |
321 | | - } finally { |
322 | | - JdbcUtil.close(sessionID, update); |
323 | | - JdbcUtil.close(sessionID, connection); |
324 | | - } |
325 | | - } |
326 | | - |
327 | | - private void storeOutgoingSequenceNumbers() throws IOException { |
328 | | - Connection connection = null; |
329 | | - PreparedStatement update = null; |
330 | | - try { |
331 | | - connection = dataSource.getConnection(); |
332 | | - update = connection.prepareStatement(SQL_UPDATE_OUTGOING_SEQNUM); |
333 | | - update.setInt(1, cache.getNextSenderMsgSeqNum()); |
| 316 | + update = connection.prepareStatement(sequenceUpdateSql); |
| 317 | + update.setInt(1, sequence.getAsInt()); |
334 | 318 | setSessionIdParameters(update, 2); |
335 | 319 | update.execute(); |
336 | 320 | } catch (SQLException e) { |
|
0 commit comments