From a9ea918953ed9d1bc662629bf9c3044a63ccb5f3 Mon Sep 17 00:00:00 2001 From: Gavin King Date: Fri, 17 Jan 2025 01:33:07 +0100 Subject: [PATCH] fix use of raw types in AbstractSelectionQuery --- .../main/java/org/hibernate/ScrollableResults.java | 5 +++++ .../query/internal/ScrollableResultsIterator.java | 6 +++--- .../query/spi/AbstractSelectionQuery.java | 14 ++++++-------- .../query/spi/ScrollableResultsImplementor.java | 1 - 4 files changed, 14 insertions(+), 12 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/ScrollableResults.java b/hibernate-core/src/main/java/org/hibernate/ScrollableResults.java index 94b705a72523..06f35d6dba86 100644 --- a/hibernate-core/src/main/java/org/hibernate/ScrollableResults.java +++ b/hibernate-core/src/main/java/org/hibernate/ScrollableResults.java @@ -33,6 +33,11 @@ public interface ScrollableResults extends AutoCloseable { */ void close(); + /** + * @return {@code true} if {@link #close()} was already called + */ + boolean isClosed(); + /** * Advance to the next result. * diff --git a/hibernate-core/src/main/java/org/hibernate/query/internal/ScrollableResultsIterator.java b/hibernate-core/src/main/java/org/hibernate/query/internal/ScrollableResultsIterator.java index cdb724e84679..987d38cd1294 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/internal/ScrollableResultsIterator.java +++ b/hibernate-core/src/main/java/org/hibernate/query/internal/ScrollableResultsIterator.java @@ -5,8 +5,8 @@ package org.hibernate.query.internal; import org.hibernate.Incubating; +import org.hibernate.ScrollableResults; import org.hibernate.query.spi.CloseableIterator; -import org.hibernate.query.spi.ScrollableResultsImplementor; /** * @author Steve Ebersole @@ -15,9 +15,9 @@ */ @Incubating public class ScrollableResultsIterator implements CloseableIterator { - private final ScrollableResultsImplementor scrollableResults; + private final ScrollableResults scrollableResults; - public ScrollableResultsIterator(ScrollableResultsImplementor scrollableResults) { + public ScrollableResultsIterator(ScrollableResults scrollableResults) { this.scrollableResults = scrollableResults; } diff --git a/hibernate-core/src/main/java/org/hibernate/query/spi/AbstractSelectionQuery.java b/hibernate-core/src/main/java/org/hibernate/query/spi/AbstractSelectionQuery.java index 6c29f0f9d87c..022c9885fe7c 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/spi/AbstractSelectionQuery.java +++ b/hibernate-core/src/main/java/org/hibernate/query/spi/AbstractSelectionQuery.java @@ -18,6 +18,7 @@ import org.hibernate.CacheMode; import org.hibernate.FlushMode; +import org.hibernate.ScrollableResults; import org.hibernate.query.QueryFlushMode; import org.hibernate.HibernateException; import org.hibernate.LockMode; @@ -251,15 +252,12 @@ public Stream getResultStream() { return stream(); } - @SuppressWarnings( {"unchecked", "rawtypes"} ) @Override - public Stream stream() { - final ScrollableResultsImplementor scrollableResults = scroll( ScrollMode.FORWARD_ONLY ); - final ScrollableResultsIterator iterator = new ScrollableResultsIterator<>( scrollableResults ); - final Spliterator spliterator = spliteratorUnknownSize( iterator, Spliterator.NONNULL ); - - final Stream stream = StreamSupport.stream( spliterator, false ); - return (Stream) stream.onClose( scrollableResults::close ); + public Stream stream() { + final ScrollableResults results = scroll( ScrollMode.FORWARD_ONLY ); + final Spliterator spliterator = + spliteratorUnknownSize( new ScrollableResultsIterator<>( results ), Spliterator.NONNULL ); + return StreamSupport.stream( spliterator, false ).onClose( results::close ); } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/query/spi/ScrollableResultsImplementor.java b/hibernate-core/src/main/java/org/hibernate/query/spi/ScrollableResultsImplementor.java index b917e61059f7..9638dd0904ba 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/spi/ScrollableResultsImplementor.java +++ b/hibernate-core/src/main/java/org/hibernate/query/spi/ScrollableResultsImplementor.java @@ -14,5 +14,4 @@ */ @Incubating public interface ScrollableResultsImplementor extends ScrollableResults { - boolean isClosed(); }