mybatis / mybatis-3

MyBatis SQL mapper framework for Java
http://mybatis.github.io/mybatis-3/
Apache License 2.0
19.8k stars 12.86k forks source link

change List<Object> handleResultSets(Statement stmt) to return Iterable or Stream #3213

Closed XenoAmess closed 3 months ago

XenoAmess commented 3 months ago

Feature request?

image

now we just loop the List out of stmt (and into a List), and then handle it. but it might be memory costy, so I would like to change this part to return a Iterable or a Stream, who not do

    while (rsw != null && resultMapCount > resultSetCount) {
      ResultMap resultMap = resultMaps.get(resultSetCount);
      handleResultSet(rsw, resultMap, multipleResults, null);
      rsw = getNextResultSet(stmt);
      cleanUpAfterHandlingResultSet();
      resultSetCount++;
    }

all at beginning, but do it when needed during the stream... I hope by doing this we can let the outer layers decide if read all, or just read some then stop, or read some skip others, and has the ability to avoid a giant List when return value is really big any +1 or -1s?

harawata commented 3 months ago

Hello @XenoAmess ,

There already is that functionality. It's called Cursor. https://mybatis.org/mybatis-3/java-api.html#statement-execution-methods

Search references to org.apache.ibatis.cursor.Cursor in the test cases. e.g. https://github.com/mybatis/mybatis-3/blob/master/src/test/java/org/apache/ibatis/submitted/cursor_simple/CursorSimpleTest.java

p.s. Please use text instead of image whenever possible. Texts can be copied/searched/edited, images are not.

XenoAmess commented 3 months ago

good, would have a try