Skip to content

Commit

Permalink
Hibernate reactive panache - remove all Multi<T> stream() methods
Browse files Browse the repository at this point in the history
- neither Hibernate Reactive nor reactive clients support streaming
- furthermore, we're not able to provide a Panache#withTransaction()
alternative for Multi without bypassing Hibernate Reactive API
  • Loading branch information
mkouba committed Feb 6, 2023
1 parent 47b10ae commit 99c4b70
Show file tree
Hide file tree
Showing 13 changed files with 15 additions and 943 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import io.quarkus.panache.common.Parameters;
import io.quarkus.panache.common.Sort;
import io.quarkus.panache.hibernate.common.runtime.PanacheJpaUtil;
import io.smallrye.mutiny.Multi;
import io.smallrye.mutiny.Uni;

public abstract class AbstractJpaOperations<PanacheQueryType> {
Expand All @@ -30,8 +29,6 @@ protected abstract PanacheQueryType createPanacheQuery(Uni<Mutiny.Session> sessi

protected abstract Uni<List<?>> list(PanacheQueryType query);

protected abstract Multi<?> stream(PanacheQueryType query);

//
// Instance methods

Expand Down Expand Up @@ -177,30 +174,6 @@ public Uni<List<?>> list(Class<?> entityClass, String query, Sort sort, Paramete
return list(find(entityClass, query, sort, params));
}

public Multi<?> stream(Class<?> entityClass, String query, Object... params) {
return stream(find(entityClass, query, params));
}

public Multi<?> stream(Class<?> entityClass, String query, Sort sort, Object... params) {
return stream(find(entityClass, query, sort, params));
}

public Multi<?> stream(Class<?> entityClass, String query, Map<String, Object> params) {
return stream(find(entityClass, query, params));
}

public Multi<?> stream(Class<?> entityClass, String query, Sort sort, Map<String, Object> params) {
return stream(find(entityClass, query, sort, params));
}

public Multi<?> stream(Class<?> entityClass, String query, Parameters params) {
return stream(find(entityClass, query, params));
}

public Multi<?> stream(Class<?> entityClass, String query, Sort sort, Parameters params) {
return stream(find(entityClass, query, sort, params));
}

public PanacheQueryType findAll(Class<?> entityClass) {
String query = "FROM " + PanacheJpaUtil.getEntityName(entityClass);
Uni<Mutiny.Session> session = getSession();
Expand All @@ -221,14 +194,6 @@ public Uni<List<?>> listAll(Class<?> entityClass, Sort sort) {
return list(findAll(entityClass, sort));
}

public Multi<?> streamAll(Class<?> entityClass) {
return stream(findAll(entityClass));
}

public Multi<?> streamAll(Class<?> entityClass, Sort sort) {
return stream(findAll(entityClass, sort));
}

@SuppressWarnings({ "rawtypes", "unchecked" })
public Uni<Long> count(Class<?> entityClass) {
return (Uni) getSession()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import io.quarkus.panache.common.Parameters
import io.quarkus.panache.common.Sort
import io.quarkus.panache.common.impl.GenerateBridge
import io.smallrye.common.annotation.CheckReturnValue
import io.smallrye.mutiny.Multi
import io.smallrye.mutiny.Uni
import jakarta.persistence.LockModeType
import org.hibernate.reactive.mutiny.Mutiny
Expand Down Expand Up @@ -54,7 +53,6 @@ interface PanacheCompanionBase<Entity : PanacheEntityBase, Id : Any> {
* @param params optional sequence of indexed parameters
* @return a new [PanacheQuery] instance for the given query
* @see [list] list
* @see [stream] stream
*/
@GenerateBridge
fun find(query: String, vararg params: Any): PanacheQuery<Entity> = injectionMissing()
Expand All @@ -67,7 +65,6 @@ interface PanacheCompanionBase<Entity : PanacheEntityBase, Id : Any> {
* @param params optional sequence of indexed parameters
* @return a new [PanacheQuery] instance for the given query
* @see [list] list
* @see [stream] stream
*/
@GenerateBridge
fun find(query: String, sort: Sort, vararg params: Any): PanacheQuery<Entity> = injectionMissing()
Expand All @@ -79,7 +76,6 @@ interface PanacheCompanionBase<Entity : PanacheEntityBase, Id : Any> {
* @param params [Map] of named parameters
* @return a new [PanacheQuery] instance for the given query
* @see [list] list
* @see [stream] stream
*/
@GenerateBridge
fun find(query: String, params: Map<String, Any>): PanacheQuery<Entity> = injectionMissing()
Expand All @@ -92,7 +88,6 @@ interface PanacheCompanionBase<Entity : PanacheEntityBase, Id : Any> {
* @param params [Map] of indexed parameters
* @return a new [PanacheQuery] instance for the given query
* @see [list] list
* @see [stream] stream
*/
@GenerateBridge
fun find(query: String, sort: Sort, params: Map<String, Any>): PanacheQuery<Entity> = injectionMissing()
Expand All @@ -104,7 +99,6 @@ interface PanacheCompanionBase<Entity : PanacheEntityBase, Id : Any> {
* @param params [Parameters] of named parameters
* @return a new [PanacheQuery] instance for the given query
* @see [list] list
* @see [stream] stream
*/
@GenerateBridge
fun find(query: String, params: Parameters): PanacheQuery<Entity> = injectionMissing()
Expand All @@ -117,7 +111,6 @@ interface PanacheCompanionBase<Entity : PanacheEntityBase, Id : Any> {
* @param params [Parameters] of indexed parameters
* @return a new [PanacheQuery] instance for the given query
* @see [list] list
* @see [stream] stream
*/
@GenerateBridge
fun find(query: String, sort: Sort, params: Parameters): PanacheQuery<Entity> = injectionMissing()
Expand All @@ -127,7 +120,6 @@ interface PanacheCompanionBase<Entity : PanacheEntityBase, Id : Any> {
*
* @return a new [PanacheQuery] instance to find all entities of this type.
* @see [listAll] listAll
* @see [streamAll] streamAll
*/
@GenerateBridge
fun findAll(): PanacheQuery<Entity> = injectionMissing()
Expand All @@ -138,7 +130,6 @@ interface PanacheCompanionBase<Entity : PanacheEntityBase, Id : Any> {
* @param sort the sort order to use
* @return a new [PanacheQuery] instance to find all entities of this type.
* @see [listAll] listAll
* @see [streamAll] streamAll
*/
@GenerateBridge
fun findAll(sort: Sort): PanacheQuery<Entity> = injectionMissing()
Expand All @@ -151,7 +142,6 @@ interface PanacheCompanionBase<Entity : PanacheEntityBase, Id : Any> {
* @param params optional sequence of indexed parameters
* @return a [List] containing all results, without paging
* @see [find] find
* @see [stream] stream
*/
@CheckReturnValue
@GenerateBridge
Expand All @@ -166,7 +156,6 @@ interface PanacheCompanionBase<Entity : PanacheEntityBase, Id : Any> {
* @param params optional sequence of indexed parameters
* @return a [List] containing all results, without paging
* @see [find] find
* @see [stream] stream
*/
@CheckReturnValue
@GenerateBridge
Expand All @@ -180,7 +169,6 @@ interface PanacheCompanionBase<Entity : PanacheEntityBase, Id : Any> {
* @param params [Map] of named parameters
* @return a [List] containing all results, without paging
* @see [find] find
* @see [stream] stream
*/
@CheckReturnValue
@GenerateBridge
Expand All @@ -195,7 +183,6 @@ interface PanacheCompanionBase<Entity : PanacheEntityBase, Id : Any> {
* @param params [Map] of indexed parameters
* @return a [List] containing all results, without paging
* @see [find] find
* @see [stream] stream
*/
@CheckReturnValue
@GenerateBridge
Expand All @@ -209,7 +196,6 @@ interface PanacheCompanionBase<Entity : PanacheEntityBase, Id : Any> {
* @param params [Parameters] of named parameters
* @return a [List] containing all results, without paging
* @see [find] find
* @see [stream] stream
*/
@CheckReturnValue
@GenerateBridge
Expand All @@ -224,7 +210,6 @@ interface PanacheCompanionBase<Entity : PanacheEntityBase, Id : Any> {
* @param params [Parameters] of indexed parameters
* @return a [List] containing all results, without paging
* @see [find] find
* @see [stream] stream
*/
@CheckReturnValue
@GenerateBridge
Expand All @@ -236,7 +221,6 @@ interface PanacheCompanionBase<Entity : PanacheEntityBase, Id : Any> {
*
* @return a [List] containing all results, without paging
* @see [findAll] findAll
* @see [streamAll] streamAll
*/
@CheckReturnValue
@GenerateBridge
Expand All @@ -249,140 +233,11 @@ interface PanacheCompanionBase<Entity : PanacheEntityBase, Id : Any> {
* @param sort the sort order to use
* @return a [List] containing all results, without paging
* @see [findAll] findAll
* @see [streamAll] streamAll
*/
@CheckReturnValue
@GenerateBridge
fun listAll(sort: Sort): Uni<List<Entity>> = injectionMissing()

/**
* Find entities matching a query, with optional indexed parameters.
* This method is a shortcut for `find(query, params).stream()`.
* It requires a transaction to work.
* Without a transaction, the underlying cursor can be closed before the end of the stream.
*
* @param query a query string
* @param params optional sequence of indexed parameters
* @return a [Stream] containing all results, without paging
* @see [find] find
* @see [list] list
*/
@CheckReturnValue
@GenerateBridge
fun stream(query: String, vararg params: Any): Multi<Entity> = injectionMissing()

/**
* Find entities matching a query and the given sort options, with optional indexed parameters.
* This method is a shortcut for `find(query, sort, params).stream()`.
* It requires a transaction to work.
* Without a transaction, the underlying cursor can be closed before the end of the stream.
*
* @param query a query string
* @param sort the sort strategy to use
* @param params optional sequence of indexed parameters
* @return a [Stream] containing all results, without paging
* @see [find] find
* @see [list] list
*/
@CheckReturnValue
@GenerateBridge
fun stream(query: String, sort: Sort, vararg params: Any): Multi<Entity> = injectionMissing()

/**
* Find entities matching a query, with named parameters.
* This method is a shortcut for `find(query, params).stream()`.
* It requires a transaction to work.
* Without a transaction, the underlying cursor can be closed before the end of the stream.
*
* @param query a query string
* @param params [Map] of named parameters
* @return a [Stream] containing all results, without paging
* @see [find] find
* @see [list] list
*/
@CheckReturnValue
@GenerateBridge
fun stream(query: String, params: Map<String, Any>): Multi<Entity> = injectionMissing()

/**
* Find entities matching a query and the given sort options, with named parameters.
* This method is a shortcut for `find(query, sort, params).stream()`.
* It requires a transaction to work.
* Without a transaction, the underlying cursor can be closed before the end of the stream.
*
* @param query a query string
* @param sort the sort strategy to use
* @param params [Map] of indexed parameters
* @return a [Stream] containing all results, without paging
* @see [find] find
* @see [list] list
*/
@CheckReturnValue
@GenerateBridge
fun stream(query: String, sort: Sort, params: Map<String, Any>): Multi<Entity> = injectionMissing()

/**
* Find entities matching a query, with named parameters.
* This method is a shortcut for `find(query, params).stream()`.
* It requires a transaction to work.
* Without a transaction, the underlying cursor can be closed before the end of the stream.
*
* @param query a query string
* @param params [Parameters] of named parameters
* @return a [Stream] containing all results, without paging
* @see [find] find
* @see [list] list
*/
@CheckReturnValue
@GenerateBridge
fun stream(query: String, params: Parameters): Multi<Entity> = injectionMissing()

/**
* Find entities matching a query and the given sort options, with named parameters.
* This method is a shortcut for `find(query, sort, params).stream()`.
* It requires a transaction to work.
* Without a transaction, the underlying cursor can be closed before the end of the stream.
*
* @param query a query string
* @param sort the sort strategy to use
* @param params [Parameters] of indexed parameters
* @return a [Stream] containing all results, without paging
* @see [find] find
* @see [list] list
*/
@CheckReturnValue
@GenerateBridge
fun stream(query: String, sort: Sort, params: Parameters): Multi<Entity> = injectionMissing()

/**
* Find all entities of this type.
* This method is a shortcut for `findAll().stream()`.
* It requires a transaction to work.
* Without a transaction, the underlying cursor can be closed before the end of the stream.
*
* @return a [Stream] containing all results, without paging
* @see [findAll] findAll
* @see [listAll] listAll
*/
@CheckReturnValue
@GenerateBridge
fun streamAll(): Multi<Entity> = injectionMissing()

/**
* Find all entities of this type, in the given order.
* This method is a shortcut for `findAll(sort).stream()`.
* It requires a transaction to work.
* Without a transaction, the underlying cursor can be closed before the end of the stream.
*
* @param sort the sort order to use
* @return a [Stream] containing all results, without paging
* @see [findAll] findAll
* @see [listAll] listAll
*/
@CheckReturnValue
@GenerateBridge
fun streamAll(sort: Sort): Multi<Entity> = injectionMissing()

/**
* Counts the number of this type of entity in the database.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package io.quarkus.hibernate.reactive.panache.kotlin
import io.quarkus.panache.common.Page
import io.quarkus.panache.common.Parameters
import io.smallrye.common.annotation.CheckReturnValue
import io.smallrye.mutiny.Multi
import io.smallrye.mutiny.Uni
import jakarta.persistence.LockModeType
import jakarta.persistence.NonUniqueResultException
Expand Down Expand Up @@ -208,22 +207,11 @@ interface PanacheQuery<Entity : Any> {
* Returns the current page of results as a [List].
*
* @return the current page of results as a [List].
* @see [PanacheQuery.stream]
* @see [PanacheQuery.page]
*/
@CheckReturnValue
fun list(): Uni<List<Entity>>

/**
* Returns the current page of results as a Stream.
*
* @return the current page of results as a Stream.
* @see [PanacheQuery.list]
* @see [PanacheQuery.page]
*/
@CheckReturnValue
fun stream(): Multi<Entity>

/**
* Returns the first result of the current page index. This ignores the current page size to fetch
* a single result.
Expand Down
Loading

0 comments on commit 99c4b70

Please sign in to comment.