Class PaginationResult<T extends BaseEntity>
java.lang.Object
com.github.collinalpert.java2db.pagination.PaginationResult<T>
- Direct Known Subclasses:
CacheablePaginationResult
public class PaginationResult<T extends BaseEntity>
extends java.lang.Object
Class for a simple pagination implementation.
- Author:
- Collin Alpert
-
Field Summary
Fields Modifier and Type Field Description protected java.util.List<EntityQuery<T>>queries -
Constructor Summary
Constructors Constructor Description PaginationResult(java.util.List<EntityQuery<T>> queries) -
Method Summary
Modifier and Type Method Description intgetNumberOfPages()Gets the amount of pages created to split up a query.java.util.List<T>getPage(int number)Retrieves a specific page represented by aList.T[]getPageAsArray(int number)Retrieves a specific page represented by an array.java.util.concurrent.CompletableFuture<java.lang.Void>getPageAsArrayAsync(int number, java.util.function.Consumer<? super T[]> callback)The asynchronous version of thegetPageAsArray(int)method.java.util.stream.Stream<T>getPageAsStream(int number)Retrieves a specific page represented by aStream.java.util.concurrent.CompletableFuture<java.lang.Void>getPageAsStreamAsync(int number, java.util.function.Consumer<? super java.util.stream.Stream<T>> callback)The asynchronous version of thegetPageAsStream(int)method.java.util.concurrent.CompletableFuture<java.lang.Void>getPageAsync(int number, java.util.function.Consumer<? super java.util.List<T>> callback)The asynchronous version of thegetPage(int)method.PaginationResult<T>orderBy(OrderTypes orderType, com.github.collinalpert.lambda2sql.functions.SqlFunction<T,?>... orderFunctions)Adds ORDER BY statements to the queries executed for the pages in a coalescing manner.PaginationResult<T>orderBy(com.github.collinalpert.lambda2sql.functions.SqlFunction<T,?>... orderFunctions)Adds ascending ORDER BY statements to the queries executed for the pages in a coalescing manner.
-
Field Details
-
Constructor Details
-
Method Details
-
getNumberOfPages
public int getNumberOfPages()Gets the amount of pages created to split up a query.- Returns:
- The number of pages created for the result.
-
getPage
Retrieves a specific page represented by aList. Only then will a query to the database be executed.- Parameters:
number- The number of the page. The first page has the number 1.- Returns:
- A
Listof entities on this page.
-
getPageAsync
public java.util.concurrent.CompletableFuture<java.lang.Void> getPageAsync(int number, java.util.function.Consumer<? super java.util.List<T>> callback)The asynchronous version of thegetPage(int)method.- Parameters:
number- The number of the page. The first page has the number 1.callback- The callback to be executed once the page has been fetched.- Returns:
- A
CompletableFuturerepresenting the asynchronous operation. - See Also:
getPage(int)
-
getPageAsStream
Retrieves a specific page represented by aStream. Only then will a query to the database be executed.- Parameters:
number- The number of the page. The first page has the number 1.- Returns:
- A
Streamof entities on this page.
-
getPageAsStreamAsync
public java.util.concurrent.CompletableFuture<java.lang.Void> getPageAsStreamAsync(int number, java.util.function.Consumer<? super java.util.stream.Stream<T>> callback)The asynchronous version of thegetPageAsStream(int)method.- Parameters:
number- The number of the page. The first page has the number 1.callback- The callback to be executed once the page has been fetched.- Returns:
- A
CompletableFuturerepresenting the asynchronous operation. - See Also:
getPageAsStream(int)
-
getPageAsArray
Retrieves a specific page represented by an array. Only then will a query to the database be executed.- Parameters:
number- The number of the page. The first page has the number 1.- Returns:
- An array of entities on this page.
-
getPageAsArrayAsync
public java.util.concurrent.CompletableFuture<java.lang.Void> getPageAsArrayAsync(int number, java.util.function.Consumer<? super T[]> callback)The asynchronous version of thegetPageAsArray(int)method.- Parameters:
number- The number of the page. The first page has the number 1.callback- The callback to be executed once the page has been fetched.- Returns:
- A
CompletableFuturerepresenting the asynchronous operation. - See Also:
getPageAsArray(int)
-
orderBy
@SafeVarargs public final PaginationResult<T> orderBy(com.github.collinalpert.lambda2sql.functions.SqlFunction<T,?>... orderFunctions)Adds ascending ORDER BY statements to the queries executed for the pages in a coalescing manner. Note that this will order the entire pagination structure and not every page separately.- Parameters:
orderFunctions- The columns to order by.- Returns:
- The object with an ORDER BY statement
-
orderBy
@SafeVarargs public final PaginationResult<T> orderBy(OrderTypes orderType, com.github.collinalpert.lambda2sql.functions.SqlFunction<T,?>... orderFunctions)Adds ORDER BY statements to the queries executed for the pages in a coalescing manner. Note that this will order the entire pagination structure and not every page separately.- Parameters:
orderType- The direction of order.orderFunctions- The columns to order by.- Returns:
- The object with an ORDER BY statement
-