Interface ReactivePanacheQuery<Entity>

Type Parameters:
Entity - The entity type being queried
All Known Implementing Classes:
ReactivePanacheQueryImpl

public interface ReactivePanacheQuery<Entity>
Interface representing an entity query, which abstracts the use of paging, getting the number of results, and operating on List or Stream. Instances of this interface cannot mutate the query itself or its parameters: only paging information can be modified, and instances of this interface can be reused to obtain multiple pages of results.
  • Method Details

    • project

      <T> ReactivePanacheQuery<T> project(Class<T> type)
      Defines a projection class: the getters, and the public fields, will be used to restrict which fields should be retrieved from the database.
      Returns:
    • page

      <T extends Entity> ReactivePanacheQuery<T> page(Page page)
      Sets the current page.
      Parameters:
      page - the new page
      Returns:
      this query, modified
      See Also:
    • page

      <T extends Entity> ReactivePanacheQuery<T> page(int pageIndex, int pageSize)
      Sets the current page.
      Parameters:
      pageIndex - the page index (0-based)
      pageSize - the page size
      Returns:
      this query, modified
      See Also:
    • nextPage

      <T extends Entity> ReactivePanacheQuery<T> nextPage()
      Sets the current page to the next page
      Returns:
      this query, modified
      Throws:
      UnsupportedOperationException - if a page hasn't been set or if a range is already set
      See Also:
    • previousPage

      <T extends Entity> ReactivePanacheQuery<T> previousPage()
      Sets the current page to the previous page (or the first page if there is no previous page)
      Returns:
      this query, modified
      Throws:
      UnsupportedOperationException - if a page hasn't been set or if a range is already set
      See Also:
    • firstPage

      <T extends Entity> ReactivePanacheQuery<T> firstPage()
      Sets the current page to the first page
      Returns:
      this query, modified
      Throws:
      UnsupportedOperationException - if a page hasn't been set or if a range is already set
      See Also:
    • lastPage

      <T extends Entity> io.smallrye.mutiny.Uni<ReactivePanacheQuery<T>> lastPage()
      Sets the current page to the last page. This will cause reading of the entity count.
      Returns:
      this query, modified
      Throws:
      UnsupportedOperationException - if a page hasn't been set or if a range is already set
      See Also:
    • hasNextPage

      io.smallrye.mutiny.Uni<Boolean> hasNextPage()
      Returns true if there is another page to read after the current one. This will cause reading of the entity count.
      Returns:
      true if there is another page to read
      Throws:
      UnsupportedOperationException - if a page hasn't been set or if a range is already set
      See Also:
    • hasPreviousPage

      boolean hasPreviousPage()
      Returns true if there is a page to read before the current one.
      Returns:
      true if there is a previous page to read
      Throws:
      UnsupportedOperationException - if a page hasn't been set or if a range is already set
      See Also:
    • pageCount

      io.smallrye.mutiny.Uni<Integer> pageCount()
      Returns the total number of pages to be read using the current page size. This will cause reading of the entity count.
      Returns:
      the total number of pages to be read using the current page size.
      Throws:
      UnsupportedOperationException - if a page hasn't been set or if a range is already set
    • page

      Page page()
      Returns the current page.
      Returns:
      the current page
      Throws:
      UnsupportedOperationException - if a page hasn't been set or if a range is already set
      See Also:
    • range

      <T extends Entity> ReactivePanacheQuery<T> range(int startIndex, int lastIndex)
      Switch the query to use a fixed range (start index - last index) instead of a page. As the range is fixed, subsequent pagination of the query is not possible.
      Parameters:
      startIndex - the index of the first element, starting at 0
      lastIndex - the index of the last element
      Returns:
      this query, modified
    • withCollation

      <T extends Entity> ReactivePanacheQuery<T> withCollation(com.mongodb.client.model.Collation collation)
      Define the collation used for this query.
      Parameters:
      collation - the collation to be used for this query.
      Returns:
      this query, modified
    • withReadPreference

      <T extends Entity> ReactivePanacheQuery<T> withReadPreference(com.mongodb.ReadPreference readPreference)
      Define the read preference used for this query.
      Parameters:
      readPreference - the read preference to be used for this query.
      Returns:
      this query, modified
    • withBatchSize

      <T extends Entity> ReactivePanacheQuery<T> withBatchSize(int batchSize)
      Define the batch size for this query.
      Parameters:
      batchSize - the batch size to be used for this query.
      Returns:
      this query, modified
    • count

      io.smallrye.mutiny.Uni<Long> count()
      Reads and caches the total number of entities this query operates on. This causes a database query with SELECT COUNT(*) and a query equivalent to the current query, minus ordering.
      Returns:
      the total number of entities this query operates on, cached.
    • list

      <T extends Entity> io.smallrye.mutiny.Uni<List<T>> list()
      Returns the current page of results as a List.
      Returns:
      the current page of results as a List.
      See Also:
    • stream

      <T extends Entity> io.smallrye.mutiny.Multi<T> stream()
      Returns the current page of results as a Stream.
      Returns:
      the current page of results as a Stream.
      See Also:
    • firstResult

      <T extends Entity> io.smallrye.mutiny.Uni<T> firstResult()
      Returns the first result of the current page index. This ignores the current page size to fetch a single result.
      Returns:
      the first result of the current page index, or null if there are no results.
      See Also:
    • firstResultOptional

      <T extends Entity> io.smallrye.mutiny.Uni<Optional<T>> firstResultOptional()
      Returns the first result of the current page index. This ignores the current page size to fetch a single result.
      Returns:
      if found, an optional containing the entity, else Optional.empty().
      See Also:
    • singleResult

      <T extends Entity> io.smallrye.mutiny.Uni<T> singleResult()
      Executes this query for the current page and return a single result.
      Returns:
      the single result.
      Throws:
      PanacheQueryException - if there are more than one result.
      See Also:
    • singleResultOptional

      <T extends Entity> io.smallrye.mutiny.Uni<Optional<T>> singleResultOptional()
      Executes this query for the current page and return a single result.
      Returns:
      if found, an optional containing the entity, else Optional.empty().
      Throws:
      PanacheQueryException - if there are more than one result.
      See Also: