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 3, 2023
1 parent c47ee9b commit f7f931e
Show file tree
Hide file tree
Showing 10 changed files with 15 additions and 469 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 @@ -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 org.hibernate.Session
import org.hibernate.annotations.Filter
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
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package io.quarkus.hibernate.reactive.panache.kotlin.runtime

import io.quarkus.hibernate.reactive.panache.common.runtime.AbstractJpaOperations
import io.smallrye.mutiny.Multi
import io.smallrye.mutiny.Uni
import org.hibernate.reactive.mutiny.Mutiny

Expand All @@ -11,8 +10,6 @@ class KotlinJpaOperations : AbstractJpaOperations<PanacheQueryImpl<*>>() {

override fun list(query: PanacheQueryImpl<*>): Uni<MutableList<*>> = query.list() as Uni<MutableList<*>>

override fun stream(query: PanacheQueryImpl<*>): Multi<*> = query.stream()

companion object {
/**
* Provides the default implementations for quarkus to wire up. Should not be used by third party developers.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import io.quarkus.hibernate.reactive.panache.common.runtime.CommonPanacheQueryIm
import io.quarkus.hibernate.reactive.panache.kotlin.PanacheQuery
import io.quarkus.panache.common.Page
import io.quarkus.panache.common.Parameters
import io.smallrye.mutiny.Multi
import io.smallrye.mutiny.Uni
import org.hibernate.reactive.mutiny.Mutiny
import javax.persistence.LockModeType
Expand Down Expand Up @@ -105,8 +104,6 @@ class PanacheQueryImpl<Entity : Any> : PanacheQuery<Entity> {

override fun list(): Uni<List<Entity>> = delegate.list()

override fun stream(): Multi<Entity> = delegate.stream()

override fun firstResult(): Uni<Entity?> = delegate.firstResult()

override fun singleResult(): Uni<Entity> = delegate.singleResult()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
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;

/**
Expand Down Expand Up @@ -422,170 +421,6 @@ public static <T extends PanacheEntityBase> Uni<List<T>> listAll(Sort sort) {
throw INSTANCE.implementationInjectionMissing();
}

/**
* Find entities matching a query, with optional indexed parameters.
* This method is a shortcut for <code>find(query, params).stream()</code>.
* It requires a transaction to work.
* Without a transaction, the underlying cursor can be closed before the end of the stream.
*
* @param query a {@link io.quarkus.hibernate.reactive.panache query string}
* @param params optional sequence of indexed parameters
* @return a {@link Stream} containing all results, without paging
* @see #stream(String, Sort, Object...)
* @see #stream(String, Map)
* @see #stream(String, Parameters)
* @see #find(String, Object...)
* @see #list(String, Object...)
*/
@CheckReturnValue
@GenerateBridge
public static <T extends PanacheEntityBase> Multi<T> stream(String query, Object... params) {
throw INSTANCE.implementationInjectionMissing();
}

/**
* Find entities matching a query and the given sort options, with optional indexed parameters.
* This method is a shortcut for <code>find(query, sort, params).stream()</code>.
* It requires a transaction to work.
* Without a transaction, the underlying cursor can be closed before the end of the stream.
*
* @param query a {@link io.quarkus.hibernate.reactive.panache query string}
* @param sort the sort strategy to use
* @param params optional sequence of indexed parameters
* @return a {@link Stream} containing all results, without paging
* @see #stream(String, Object...)
* @see #stream(String, Sort, Map)
* @see #stream(String, Sort, Parameters)
* @see #find(String, Sort, Object...)
* @see #list(String, Sort, Object...)
*/
@CheckReturnValue
@GenerateBridge
public static <T extends PanacheEntityBase> Multi<T> stream(String query, Sort sort, Object... params) {
throw INSTANCE.implementationInjectionMissing();
}

/**
* Find entities matching a query, with named parameters.
* This method is a shortcut for <code>find(query, params).stream()</code>.
* It requires a transaction to work.
* Without a transaction, the underlying cursor can be closed before the end of the stream.
*
* @param query a {@link io.quarkus.hibernate.reactive.panache query string}
* @param params {@link Map} of named parameters
* @return a {@link Stream} containing all results, without paging
* @see #stream(String, Sort, Map)
* @see #stream(String, Object...)
* @see #stream(String, Parameters)
* @see #find(String, Map)
* @see #list(String, Map)
*/
@CheckReturnValue
@GenerateBridge
public static <T extends PanacheEntityBase> Multi<T> stream(String query, Map<String, Object> params) {
throw INSTANCE.implementationInjectionMissing();
}

/**
* Find entities matching a query and the given sort options, with named parameters.
* This method is a shortcut for <code>find(query, sort, params).stream()</code>.
* It requires a transaction to work.
* Without a transaction, the underlying cursor can be closed before the end of the stream.
*
* @param query a {@link io.quarkus.hibernate.reactive.panache query string}
* @param sort the sort strategy to use
* @param params {@link Map} of indexed parameters
* @return a {@link Stream} containing all results, without paging
* @see #stream(String, Map)
* @see #stream(String, Sort, Object...)
* @see #stream(String, Sort, Parameters)
* @see #find(String, Sort, Map)
* @see #list(String, Sort, Map)
*/
@CheckReturnValue
@GenerateBridge
public static <T extends PanacheEntityBase> Multi<T> stream(String query, Sort sort, Map<String, Object> params) {
throw INSTANCE.implementationInjectionMissing();
}

/**
* Find entities matching a query, with named parameters.
* This method is a shortcut for <code>find(query, params).stream()</code>.
* It requires a transaction to work.
* Without a transaction, the underlying cursor can be closed before the end of the stream.
*
* @param query a {@link io.quarkus.hibernate.reactive.panache query string}
* @param params {@link Parameters} of named parameters
* @return a {@link Stream} containing all results, without paging
* @see #stream(String, Sort, Parameters)
* @see #stream(String, Object...)
* @see #stream(String, Map)
* @see #find(String, Parameters)
* @see #list(String, Parameters)
*/
@CheckReturnValue
@GenerateBridge
public static <T extends PanacheEntityBase> Multi<T> stream(String query, Parameters params) {
throw INSTANCE.implementationInjectionMissing();
}

/**
* Find entities matching a query and the given sort options, with named parameters.
* This method is a shortcut for <code>find(query, sort, params).stream()</code>.
* It requires a transaction to work.
* Without a transaction, the underlying cursor can be closed before the end of the stream.
*
* @param query a {@link io.quarkus.hibernate.reactive.panache query string}
* @param sort the sort strategy to use
* @param params {@link Parameters} of indexed parameters
* @return a {@link Stream} containing all results, without paging
* @see #stream(String, Parameters)
* @see #stream(String, Sort, Object...)
* @see #stream(String, Sort, Map)
* @see #find(String, Sort, Parameters)
* @see #list(String, Sort, Parameters)
*/
@CheckReturnValue
@GenerateBridge
public static <T extends PanacheEntityBase> Multi<T> stream(String query, Sort sort, Parameters params) {
throw INSTANCE.implementationInjectionMissing();
}

/**
* Find all entities of this type.
* This method is a shortcut for <code>findAll().stream()</code>.
* It requires a transaction to work.
* Without a transaction, the underlying cursor can be closed before the end of the stream.
*
* @return a {@link Stream} containing all results, without paging
* @see #streamAll(Sort)
* @see #findAll()
* @see #listAll()
*/
@CheckReturnValue
@GenerateBridge
public static <T extends PanacheEntityBase> Multi<T> streamAll() {
throw INSTANCE.implementationInjectionMissing();
}

/**
* Find all entities of this type, in the given order.
* This method is a shortcut for <code>findAll(sort).stream()</code>.
* 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 {@link Stream} containing all results, without paging
* @see #streamAll()
* @see #findAll(Sort)
* @see #listAll(Sort)
*/
@CheckReturnValue
@GenerateBridge
public static <T extends PanacheEntityBase> Multi<T> streamAll(Sort sort) {
throw INSTANCE.implementationInjectionMissing();
}

/**
* 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 @@ -2,7 +2,6 @@

import java.util.List;
import java.util.Map;
import java.util.stream.Stream;

import javax.persistence.LockModeType;
import javax.persistence.NoResultException;
Expand All @@ -14,13 +13,12 @@
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;

/**
* <p>
* Interface representing an entity query, which abstracts the use of paging, getting the number of results, and
* operating on {@link List} or {@link Stream}.
* operating on {@link List}.
* </p>
* <p>
* Instances of this interface cannot mutate the query itself or its parameters: only paging information can be
Expand Down Expand Up @@ -232,24 +230,12 @@ public interface PanacheQuery<Entity> {
* Returns the current page of results as a {@link List}.
*
* @return the current page of results as a {@link List}.
* @see #stream()
* @see #page(Page)
* @see #page()
*/
@CheckReturnValue
public <T extends Entity> Uni<List<T>> list();

/**
* Returns the current page of results as a {@link Stream}.
*
* @return the current page of results as a {@link Stream}.
* @see #list()
* @see #page(Page)
* @see #page()
*/
@CheckReturnValue
public <T extends Entity> Multi<T> stream();

/**
* Returns the first result of the current page index. This ignores the current page size to fetch
* a single result.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
import org.hibernate.reactive.mutiny.Mutiny;

import io.quarkus.hibernate.reactive.panache.common.runtime.AbstractJpaOperations;
import io.smallrye.mutiny.Multi;
import io.smallrye.mutiny.Uni;

public class JpaOperations extends AbstractJpaOperations<PanacheQueryImpl<?>> {

public static final JpaOperations INSTANCE = new JpaOperations();

@Override
Expand All @@ -23,8 +23,4 @@ protected Uni<List<?>> list(PanacheQueryImpl<?> query) {
return (Uni) query.list();
}

@Override
protected Multi<?> stream(PanacheQueryImpl<?> query) {
return query.stream();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import io.quarkus.hibernate.reactive.panache.common.runtime.CommonPanacheQueryImpl;
import io.quarkus.panache.common.Page;
import io.quarkus.panache.common.Parameters;
import io.smallrye.mutiny.Multi;
import io.smallrye.mutiny.Uni;

public class PanacheQueryImpl<Entity> implements PanacheQuery<Entity> {
Expand Down Expand Up @@ -149,11 +148,6 @@ public <T extends Entity> Uni<List<T>> list() {
return delegate.list();
}

@Override
public <T extends Entity> Multi<T> stream() {
return delegate.stream();
}

@Override
public <T extends Entity> Uni<T> firstResult() {
return delegate.firstResult();
Expand Down
Loading

0 comments on commit f7f931e

Please sign in to comment.