Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
XenoAmess opened this issue Aug 8, 2024 · 2 comments

Comments

@XenoAmess
Copy link

XenoAmess commented Aug 8, 2024

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
Copy link
Member

harawata commented Aug 8, 2024

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.

@harawata harawata closed this as completed Aug 8, 2024
@XenoAmess
Copy link
Author

good, would have a try

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants