public void reset() throws IOException { cache.reset(); Connection connection = null; PreparedStatement deleteMessages = null; PreparedStatement updateTime = null; try { connection = dataSource.getConnection(); deleteMessages = connection.prepareStatement(SQL_DELETE_MESSAGES); setSessionIdParameters(deleteMessages, 1); deleteMessages.execute(); updateTime = connection.prepareStatement(SQL_UPDATE_SESSION); updateTime.setTimestamp( 1, new Timestamp(Calendar.getInstance(TimeZone.getTimeZone("UTC")).getTimeInMillis())); updateTime.setInt(2, getNextTargetMsgSeqNum()); updateTime.setInt(3, getNextSenderMsgSeqNum()); setSessionIdParameters(updateTime, 4); updateTime.execute(); } catch (SQLException e) { throw (IOException) new IOException(e.getMessage()).initCause(e); } catch (IOException e) { throw e; } finally { JdbcUtil.close(sessionID, deleteMessages); JdbcUtil.close(sessionID, updateTime); JdbcUtil.close(sessionID, connection); } }
private void storeSequenceNumbers() throws IOException { Connection connection = null; PreparedStatement update = null; try { connection = dataSource.getConnection(); update = connection.prepareStatement(SQL_UPDATE_SEQNUMS); update.setInt(1, cache.getNextTargetMsgSeqNum()); update.setInt(2, cache.getNextSenderMsgSeqNum()); setSessionIdParameters(update, 3); update.execute(); } catch (SQLException e) { throw (IOException) new IOException(e.getMessage()).initCause(e); } finally { JdbcUtil.close(sessionID, update); JdbcUtil.close(sessionID, connection); } }
private void loadCache() throws SQLException, IOException { Connection connection = null; PreparedStatement query = null; PreparedStatement insert = null; ResultSet rs = null; try { connection = dataSource.getConnection(); query = connection.prepareStatement(SQL_GET_SEQNUMS); setSessionIdParameters(query, 1); rs = query.executeQuery(); if (rs.next()) { cache.setCreationTime(SystemTime.getUtcCalendar(rs.getTimestamp(1))); cache.setNextTargetMsgSeqNum(rs.getInt(2)); cache.setNextSenderMsgSeqNum(rs.getInt(3)); } else { insert = connection.prepareStatement(SQL_INSERT_SESSION); int offset = setSessionIdParameters(insert, 1); insert.setTimestamp(offset++, new Timestamp(cache.getCreationTime().getTime())); insert.setInt(offset++, cache.getNextTargetMsgSeqNum()); insert.setInt(offset, cache.getNextSenderMsgSeqNum()); insert.execute(); } } finally { JdbcUtil.close(sessionID, rs); JdbcUtil.close(sessionID, query); JdbcUtil.close(sessionID, insert); JdbcUtil.close(sessionID, connection); } }
public void setNextTargetMsgSeqNum(int next) throws IOException { cache.setNextTargetMsgSeqNum(next); storeSequenceNumbers(); }
public void incrNextTargetMsgSeqNum() throws IOException { cache.incrNextTargetMsgSeqNum(); setNextTargetMsgSeqNum(cache.getNextTargetMsgSeqNum()); }
public int getNextTargetMsgSeqNum() throws IOException { return cache.getNextTargetMsgSeqNum(); }
public int getNextSenderMsgSeqNum() throws IOException { return cache.getNextSenderMsgSeqNum(); }
public Date getCreationTime() throws IOException { return cache.getCreationTime(); }