File tree Expand file tree Collapse file tree 2 files changed +16
-3
lines changed
main/java/org/apache/ibatis/cursor/defaults
test/java/org/apache/ibatis/submitted/cursor_simple Expand file tree Collapse file tree 2 files changed +16
-3
lines changed Original file line number Diff line number Diff line change @@ -94,12 +94,12 @@ public int getCurrentIndex() {
94
94
95
95
@ Override
96
96
public Iterator <T > iterator () {
97
- if (isClosed ()) {
98
- throw new IllegalStateException ("A Cursor is already closed." );
99
- }
100
97
if (iteratorRetrieved ) {
101
98
throw new IllegalStateException ("Cannot open more than one iterator on a Cursor" );
102
99
}
100
+ if (isClosed ()) {
101
+ throw new IllegalStateException ("A Cursor is already closed." );
102
+ }
103
103
iteratorRetrieved = true ;
104
104
return cursorIterator ;
105
105
}
Original file line number Diff line number Diff line change @@ -373,6 +373,19 @@ public void shouldThrowIllegalStateExceptionUsingIteratorOnSessionClosed() {
373
373
} catch (IllegalStateException e ) {
374
374
Assert .assertEquals ("A Cursor is already closed." , e .getMessage ());
375
375
}
376
+
377
+ // verify for checking order
378
+ try (SqlSession sqlSession = sqlSessionFactory .openSession ()) {
379
+ usersCursor = sqlSession .getMapper (Mapper .class ).getAllUsers ();
380
+ usersCursor .iterator ();
381
+ }
382
+ try {
383
+ usersCursor .iterator ();
384
+ Assert .fail ("Should throws the IllegalStateException when call the iterator already." );
385
+ } catch (IllegalStateException e ) {
386
+ Assert .assertEquals ("Cannot open more than one iterator on a Cursor" , e .getMessage ());
387
+ }
388
+
376
389
}
377
390
378
391
}
You can’t perform that action at this time.
0 commit comments