allow query and finder methods to return Stream
required by Jakarta Data spec
This commit is contained in:
parent
18bbbbb865
commit
b039eecd8e
|
@ -99,6 +99,8 @@ import static java.lang.annotation.RetentionPolicy.CLASS;
|
|||
* or one of the following types:
|
||||
* <ul>
|
||||
* <li>{@link java.util.List java.util.List<E>},
|
||||
* <li>{@link java.util.stream.Stream java.util.stream.Stream<E>},
|
||||
* <li>{@link java.util.Optional java.util.Optional<E>},
|
||||
* <li>{@code io.smallrye.mutiny.Uni<E>}, when used with Hibernate Reactive,
|
||||
* <li>{@link org.hibernate.query.Query org.hibernate.query.Query<E>},
|
||||
* <li>{@link org.hibernate.query.SelectionQuery org.hibernate.query.SelectionQuery<E>},
|
||||
|
|
|
@ -81,8 +81,13 @@ import static java.lang.annotation.RetentionPolicy.CLASS;
|
|||
* For a {@code select} query, the return type of an annotated method
|
||||
* must be:
|
||||
* <ul>
|
||||
* <li>an entity type, or {@link java.util.List List<E>} where
|
||||
* {@code E} is an entity type,
|
||||
* <li>an entity type, or {@link java.util.Optional Optional<E>}
|
||||
* where {@code E} is an entity type,
|
||||
* <li>{@link java.util.List List<E>} or
|
||||
* {@link java.util.stream.Stream Stream<E>}
|
||||
* where {@code E} is an entity type,
|
||||
* <li>{@link java.util.List List<Object[]>} or
|
||||
* {@link java.util.stream.Stream Stream<Object[]>}
|
||||
* <li>a record type or JavaBean class with a constructor signature
|
||||
* matching the types in the query {@code select} list, or
|
||||
* {@link java.util.List List<R>} where {@code R} is such
|
||||
|
|
|
@ -77,8 +77,8 @@ import static java.lang.annotation.RetentionPolicy.CLASS;
|
|||
* <p>
|
||||
* The return type of an annotated method must be:
|
||||
* <ul>
|
||||
* <li>an entity type,
|
||||
* <li>{@link java.util.List},
|
||||
* <li>an entity type or {@link java.util.Optional},
|
||||
* <li>{@link java.util.List} or {@link java.util.stream.Stream},
|
||||
* <li>{@code io.smallrye.mutiny.Uni}, when used with Hibernate Reactive,
|
||||
* <li>{@link org.hibernate.query.Query},
|
||||
* <li>{@link jakarta.persistence.Query}, or
|
||||
|
|
|
@ -630,6 +630,7 @@ public class AnnotationMetaEntity extends AnnotationMeta {
|
|||
|
||||
private static boolean isLegalGenericResultType(String containerTypeName) {
|
||||
return containerTypeName.equals(Constants.LIST)
|
||||
|| containerTypeName.equals(Constants.STREAM)
|
||||
|| containerTypeName.equals(Constants.OPTIONAL)
|
||||
|| containerTypeName.equals(Constants.TYPED_QUERY)
|
||||
|| containerTypeName.equals(Constants.HIB_QUERY)
|
||||
|
|
|
@ -133,6 +133,13 @@ public class CriteriaFinderMethod extends AbstractFinderMethod {
|
|||
declaration
|
||||
.append("\n\t\t\t.uniqueResultOptional()");
|
||||
}
|
||||
else if ( containerType.equals(Constants.STREAM) ) {
|
||||
if ( unwrap || hasOrderParameter || hasEnabledFetchProfiles ) {
|
||||
declaration.append("\n\t\t\t");
|
||||
}
|
||||
declaration
|
||||
.append(".getResultStream()");
|
||||
}
|
||||
else if ( containerType.equals(Constants.LIST) ) {
|
||||
if ( unwrap || hasOrderParameter || hasEnabledFetchProfiles ) {
|
||||
declaration.append("\n\t\t\t");
|
||||
|
|
|
@ -157,6 +157,10 @@ public class QueryMethod extends AbstractQueryMethod {
|
|||
declaration
|
||||
.append("\n\t\t\t.uniqueResultOptional()");
|
||||
}
|
||||
else if ( containerTypeName.equals(Constants.STREAM) ) {
|
||||
declaration
|
||||
.append("\n\t\t\t.getResultStream()");
|
||||
}
|
||||
else if ( containerTypeName.equals(Constants.LIST) ) {
|
||||
declaration
|
||||
.append("\n\t\t\t.getResultList()");
|
||||
|
|
|
@ -101,6 +101,7 @@ public final class Constants {
|
|||
public static final String MAP = java.util.Map.class.getName();
|
||||
public static final String SET = java.util.Set.class.getName();
|
||||
public static final String OPTIONAL = java.util.Optional.class.getName();
|
||||
public static final String STREAM = java.util.stream.Stream.class.getName();
|
||||
|
||||
public static final Map<String, String> COLLECTIONS = Map.of(
|
||||
COLLECTION, Constants.COLLECTION_ATTRIBUTE,
|
||||
|
|
Loading…
Reference in New Issue