Skip to content

Commit

Permalink
Make the cursor status transition consistent.
Browse files Browse the repository at this point in the history
  • Loading branch information
harawata committed Sep 16, 2018
1 parent d14c67e commit b21ad1e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,11 @@ protected T fetchNextObjectFromDatabase() {
return null;
}

final boolean resultSetClosed;
try {
status = CursorStatus.OPEN;
resultSetHandler.handleRowValues(rsw, resultMap, objectWrapperResultHandler, RowBounds.DEFAULT, null);
// ResultSet might have been closed by the driver (e.g. DB2).
resultSetClosed = rsw.getResultSet().isClosed();
if (!rsw.getResultSet().isClosed()) {
resultSetHandler.handleRowValues(rsw, resultMap, objectWrapperResultHandler, RowBounds.DEFAULT, null);
}
} catch (SQLException e) {
throw new RuntimeException(e);
}
Expand All @@ -154,7 +153,7 @@ protected T fetchNextObjectFromDatabase() {
indexWithRowBound++;
}
// No more object or limit reached
if (resultSetClosed || next == null || getReadItemsCount() == rowBounds.getOffset() + rowBounds.getLimit()) {
if (next == null || getReadItemsCount() == rowBounds.getOffset() + rowBounds.getLimit()) {
close();
status = CursorStatus.CONSUMED;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,13 @@ public void shouldCloseImmediatelyIfResultSetIsClosed() throws Exception {
Map<String, Object> map = (Map<String, Object>) iter.next();
assertEquals(Integer.valueOf(1), map.get("id"));
assertEquals("CEO", ((Map<String, Object>) map.get("roles")).get("role"));

assertFalse(cursor.isConsumed());
assertTrue(cursor.isOpen());

assertFalse(iter.hasNext());
assertTrue(cursor.isConsumed());
assertFalse(cursor.isOpen());
assertFalse(iter.hasNext());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ public void shouldGetAllUser() {
Assert.assertEquals(2, user.getGroups().size());
Assert.assertEquals(2, user.getRoles().size());

Assert.assertTrue(usersCursor.isOpen());
Assert.assertFalse(usersCursor.isConsumed());

// Check no more elements
Assert.assertFalse(iterator.hasNext());
Assert.assertFalse(usersCursor.isOpen());
Expand Down

0 comments on commit b21ad1e

Please sign in to comment.