Make the Java Stream close the underlying ScrollableResultsIterator upon calling a terminal operation

Description

The JPA 2.2 Query#getResultStream returns a Stream wrapping a Hibernate ScrollableResultsIterator.

However, even if a terminal Stream operation is called, the underlying ScrollableResultsIterator will stay open until the Session is closed.

More, the current implementation does not pass the closeHandler to the IntStream, LongStream, or DoubleStream when calling mapToInt or other methods that return a primitive stream.

We need to create a StreamDecorator, IntStreamDecorator, LongStreamDecorator, and DoubleStreamDecorator that can both delegate the stream calls and close the stream upon executing a terminal operation.

Environment

None

Activity

Show:
Vlad Mihalcea
February 20, 2020, 7:09 PM

Thanks, for merging it. I’ll write an article about it once 5.4.1 is released.

Andrei Ivanov
February 21, 2020, 10:02 AM

Hmm, is it me or the PR wasn’t yet merged?

Vlad Mihalcea
February 21, 2020, 10:33 AM

Good catch. I don’t see it merged either also the issue was marked as Fixed.

was it merged to some other branch than the master one?

Steve Ebersole
February 21, 2020, 12:01 PM

What is the PR again? Jira is still having trouble talking to GitHub apparently

Steve Ebersole
February 21, 2020, 12:02 PM

Ah, no it was not merged. I requested some changes (which you’ve made). I think what confused is that you said “thanks for merging”

Fixed

Assignee

Vlad Mihalcea

Reporter

Vlad Mihalcea

Fix versions

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

Priority

Major
Configure