Class Query
oslc.where) and some paging information.
This class helps at producing a ResponseInfoCollection with the fetched resources and a reference for the next page, if any.- Since:
- 3.6.0
-
Constructor Summary
ConstructorsConstructorDescriptionQuery(HttpServletRequest request, QueryParameters parameters, int defaultPageSize, int maxPageSize) Creates a query instance with the given request parameters and desired paging information. -
Method Summary
Modifier and TypeMethodDescription<T> ResponseInfoCollection<T> createResponseInfo(Collection<T> resources) Returns aResponseInfoCollectionfor the given resources, with a undetermined total number of resources.<T> ResponseInfoCollection<T> createResponseInfo(Collection<T> resources, Integer totalCount) Returns aResponseInfoCollectionfor the given resources, with a known total number of resources.intgetPage()Return the page index that is requested, for which resources are to fetch.intReturns the size of page to use, which is the desired number of resources to fetch.intReturns the index of the first resource to fetch with this query.Returns the parsed query parameters.
-
Constructor Details
-
Query
public Query(HttpServletRequest request, QueryParameters parameters, int defaultPageSize, int maxPageSize) Creates a query instance with the given request parameters and desired paging information.The query will provide paging information that combines what is requested by the client, with the
oslc.pageSizeparameter, and the page size recommended by the application.This query assume a
"page"request parameter is used to indicate which page index is requested. If absent, it assumes the first page is requested.- Parameters:
request- the HTTP requestparameters- the query parameters parsed form the HTTP requestdefaultPageSize- the default size of a pagemaxPageSize- the maximum size of a page- Throws:
NullPointerException- if request or parameters is nullNumberFormatException- if the"page"request parameter is present but is not a valid integerIllegalArgumentException- if the"pageSize"is not a positive integer
-
-
Method Details
-
getParameters
Returns the parsed query parameters.- Returns:
- the parsed query parameters
-
getPage
public int getPage()Return the page index that is requested, for which resources are to fetch.- Returns:
- the requested page index
-
getPageSize
public int getPageSize()Returns the size of page to use, which is the desired number of resources to fetch. This page size is the one requested with theoslc.pageSizeparameter, or the default size recommended by the application if the parameter is absent, but limited to the maximum size in the constructor.- Returns:
- the page size
-
getPageStartIndex
public int getPageStartIndex()Returns the index of the first resource to fetch with this query. This index is the number of resources yet responded by previous pages of the query. When searching for an ordered list of resources matching the query filter, all resources below that index are to ignore and not to include in the response.- Returns:
- the index of the first resource to fetch with the query
-
createResponseInfo
Returns aResponseInfoCollectionfor the given resources, with a undetermined total number of resources.If the total number of resources can be determined by the application, prefer using
createResponseInfo(Collection, Integer)so that the client has more information.The
ResponseInfoCollectioncontains a reference to a next page if the number of fetched resources is greater than (or equal to) the desired page size, as this method assumes a next page may contain additional resources in this case.- Type Parameters:
T- the type of resources in the response- Parameters:
resources- the resources fetched in this page with the query- Returns:
- the response info collection
- Throws:
NullPointerException- if resources is null
-
createResponseInfo
public <T> ResponseInfoCollection<T> createResponseInfo(Collection<T> resources, Integer totalCount) Returns aResponseInfoCollectionfor the given resources, with a known total number of resources.The
ResponseInfoCollectioncontains a reference to a next page if thestart indexand number of fetched resources is lower than the total number of resources.- Type Parameters:
T- the type of resources in the response- Parameters:
resources- the resources fetched in this page with the querytotalCount- the known total number of resources in the application for this query filter, across all pages- Returns:
- the response info collection
- Throws:
NullPointerException- if resources is null
-