Skip to content

Commit 4fd2434

Browse files
committed
refactoring update method
1 parent 1999ea1 commit 4fd2434

File tree

2 files changed

+9
-25
lines changed

2 files changed

+9
-25
lines changed

quickfixj-core/src/main/java/quickfix/JdbcStore.java

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import java.util.Collection;
2828
import java.util.Date;
2929
import java.util.TimeZone;
30+
import java.util.function.IntSupplier;
3031

3132
import javax.sql.DataSource;
3233

@@ -299,38 +300,21 @@ public boolean set(int sequence, String message) throws IOException {
299300

300301
public void setNextSenderMsgSeqNum(int next) throws IOException {
301302
cache.setNextSenderMsgSeqNum(next);
302-
storeOutgoingSequenceNumbers();
303+
storeSequenceNumber(SQL_UPDATE_OUTGOING_SEQNUM, cache::getNextSenderMsgSeqNum);
303304
}
304305

305306
public void setNextTargetMsgSeqNum(int next) throws IOException {
306307
cache.setNextTargetMsgSeqNum(next);
307-
storeIncomingSequenceNumbers();
308+
storeSequenceNumber(SQL_UPDATE_INCOMING_SEQNUM, cache::getNextTargetMsgSeqNum);
308309
}
309310

310-
private void storeIncomingSequenceNumbers() throws IOException {
311+
private void storeSequenceNumber(String sequenceUpdateSql, IntSupplier sequence) throws IOException {
311312
Connection connection = null;
312313
PreparedStatement update = null;
313314
try {
314315
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());
334318
setSessionIdParameters(update, 2);
335319
update.execute();
336320
} catch (SQLException e) {

quickfixj-core/src/main/java/quickfix/MemoryStore.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,15 @@ public Calendar getCreationTimeCalendar() throws IOException {
7474
return creationTime;
7575
}
7676

77-
/* package */void setCreationTime(Calendar creationTime) {
77+
void setCreationTime(Calendar creationTime) {
7878
this.creationTime = creationTime;
7979
}
8080

81-
public int getNextSenderMsgSeqNum() throws IOException {
81+
public int getNextSenderMsgSeqNum() {
8282
return nextSenderMsgSeqNum;
8383
}
8484

85-
public int getNextTargetMsgSeqNum() throws IOException {
85+
public int getNextTargetMsgSeqNum() {
8686
return nextTargetMsgSeqNum;
8787
}
8888

0 commit comments

Comments
 (0)