Interface QueryRequest
-
- All Superinterfaces:
Request
public interface QueryRequest extends Request
A request to search for all JSON resources matching a user specified set of criteria.There are four types of query request:
- default query: when neither a filter, expression or query ID are specified all resources will be returned
- query by filter: returns all resources which match the
QueryFiltersspecified usingsetQueryFilter(QueryFilter) - query by ID: returns all resources which match
the named prepared query specified using
setQueryId(String) - query by expression: returns all resources
which match a native expression specified using
setQueryExpression(String). Note that this type of query should only be used in very rare cases since it introduces a tight coupling between the application and the underlying JSON resource. In addition, applications should take care to prevent users from directly accessing this form of query for security reasons.
In addition to the above mentioned query types queries may also be paged when a page size is found via
getPageSize(). Paged requests should be used in most cases when an unknown number of query results will be returned.
-
-
Field Summary
Fields Modifier and Type Field Description static StringFIELD_COUNT_ONLYThe name of the field which specifies whether the query request is to return only the count of the results.static StringFIELD_PAGE_SIZEThe name of the field which contains the page size in the JSON representation.static StringFIELD_PAGED_RESULTS_COOKIEThe name of the field which contains the paged results cookie in the JSON representation.static StringFIELD_PAGED_RESULTS_OFFSETThe name of the field which contains the paged results offset in the JSON representation.static StringFIELD_QUERY_EXPRESSIONThe name of the field which contains the query expression in the JSON representation.static StringFIELD_QUERY_FILTERThe name of the field which contains the query filter in the JSON representation.static StringFIELD_QUERY_IDThe name of the field which contains the query ID in the JSON representation.static StringFIELD_SORT_KEYSThe name of the field which contains the sort keys in the JSON representation.static StringFIELD_TOTAL_PAGED_RESULTS_POLICYThe name of the field which contains the policy used for calculating the total number of paged results.-
Fields inherited from interface org.forgerock.json.resource.Request
FIELD_ADDITIONAL_PARAMETERS, FIELD_FIELDS, FIELD_RESOURCE_PATH, FIELD_VALUE_ALL
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description <R,P>
Raccept(RequestVisitor<R,P> v, P p)Applies aRequestVisitorto thisRequest.QueryRequestaddField(String... fields)Adds one or more fields which should be included with each JSON resource returned by this request.QueryRequestaddField(JsonPointer... fields)Adds one or more fields which should be included with each JSON resource returned by this request.QueryRequestaddSortKey(String... keys)Adds one or more sort keys which will be used for ordering the JSON resources returned by this query request.QueryRequestaddSortKey(SortKey... keys)Adds one or more sort keys which will be used for ordering the JSON resources returned by this query request.StringgetAdditionalParameter(String name)Returns the additional parameter which should be used to control the behavior of this action request.Map<String,String>getAdditionalParameters()Returns the additional parameters which should be used to control the behavior of this action request.List<JsonPointer>getFields()Returns the list of fields which should be included with each JSON resource returned by this request.StringgetPagedResultsCookie()Returns the opaque cookie which is used by the resource provider to track its position in the set of query results.intgetPagedResultsOffset()Returns the zero-based index of the first resource which should be included in the query results.intgetPageSize()Returns the requested page results page size or0if paged results are not required.PreferredLocalesgetPreferredLocales()Get the locale preference for the request.StringgetQueryExpression()Returns the native query expression which will be used for processing the query request.QueryFilter<JsonPointer>getQueryFilter()Returns the query filter which will be used for selecting which JSON resources will be returned.StringgetQueryId()Returns the query identifier for pre-defined queries.RequestTypegetRequestType()Returns the type of this request.StringgetResourcePath()Returns the non-nullpath of the JSON resource to which this request should be targeted.ResourcePathgetResourcePathObject()Returns the non-nullpath of the JSON resource to which this request should be targeted.VersiongetResourceVersion()Gets the requested API version of the resource.List<SortKey>getSortKeys()Returns the sort keys which should be used for ordering the JSON resources returned by this query request.CountPolicygetTotalPagedResultsPolicy()Returns theCountPolicyused to calculateQueryResponse.getTotalPagedResults().booleanisCountOnly()Return if the request should only return resource count.default booleanpagingRequested()Returns whether paged results are requested.QueryRequestsetAdditionalParameter(String name, String value)Sets an additional parameter which should be used to control the behavior of this action request.QueryRequestsetCountOnly(boolean countOnly)Sets whether the request was to only provide a count of the query results.QueryRequestsetPagedResultsCookie(String cookie)Sets the opaque cookie which is used by the resource provider to track its position in the set of query results.QueryRequestsetPagedResultsOffset(int offset)Sets the zero-based index of the first resource which should be included in the query results.QueryRequestsetPageSize(int size)Sets the requested page results page size or0if paged results are not required.QueryRequestsetPreferredLocales(PreferredLocales preferredLocales)Set the locale preference for the request.QueryRequestsetQueryExpression(String expression)Sets the native query expression which will be used for processing the query request.QueryRequestsetQueryFilter(QueryFilter<JsonPointer> filter)Sets the query filter which will be used for selecting which JSON resources will be returned.QueryRequestsetQueryId(String id)Sets the query identifier for pre-defined queries.QueryRequestsetResourcePath(String path)Sets the non-nullpath of the JSON resource to which this request should be targeted.QueryRequestsetResourcePath(ResourcePath path)Sets the non-nullpath of the JSON resource to which this request should be targeted.QueryRequestsetResourceVersion(Version resourceVersion)Sets the requested API version of the resource.QueryRequestsetTotalPagedResultsPolicy(CountPolicy policy)Sets the policy for calculating the total number of paged results.JsonValuetoJsonValue()Return a JsonValue representation of this request.
-
-
-
Field Detail
-
FIELD_PAGED_RESULTS_COOKIE
static final String FIELD_PAGED_RESULTS_COOKIE
The name of the field which contains the paged results cookie in the JSON representation.- See Also:
- Constant Field Values
-
FIELD_PAGED_RESULTS_OFFSET
static final String FIELD_PAGED_RESULTS_OFFSET
The name of the field which contains the paged results offset in the JSON representation.- See Also:
- Constant Field Values
-
FIELD_PAGE_SIZE
static final String FIELD_PAGE_SIZE
The name of the field which contains the page size in the JSON representation.- See Also:
- Constant Field Values
-
FIELD_QUERY_EXPRESSION
static final String FIELD_QUERY_EXPRESSION
The name of the field which contains the query expression in the JSON representation.- See Also:
- Constant Field Values
-
FIELD_QUERY_FILTER
static final String FIELD_QUERY_FILTER
The name of the field which contains the query filter in the JSON representation.- See Also:
- Constant Field Values
-
FIELD_QUERY_ID
static final String FIELD_QUERY_ID
The name of the field which contains the query ID in the JSON representation.- See Also:
- Constant Field Values
-
FIELD_SORT_KEYS
static final String FIELD_SORT_KEYS
The name of the field which contains the sort keys in the JSON representation.- See Also:
- Constant Field Values
-
FIELD_TOTAL_PAGED_RESULTS_POLICY
static final String FIELD_TOTAL_PAGED_RESULTS_POLICY
The name of the field which contains the policy used for calculating the total number of paged results.- See Also:
- Constant Field Values
-
FIELD_COUNT_ONLY
static final String FIELD_COUNT_ONLY
The name of the field which specifies whether the query request is to return only the count of the results.- See Also:
- Constant Field Values
-
-
Method Detail
-
accept
<R,P> R accept(RequestVisitor<R,P> v, P p)
Description copied from interface:RequestApplies aRequestVisitorto thisRequest.
-
addField
QueryRequest addField(JsonPointer... fields)
Description copied from interface:RequestAdds one or more fields which should be included with each JSON resource returned by this request.
-
addField
QueryRequest addField(String... fields)
Description copied from interface:RequestAdds one or more fields which should be included with each JSON resource returned by this request.
-
addSortKey
QueryRequest addSortKey(SortKey... keys)
Adds one or more sort keys which will be used for ordering the JSON resources returned by this query request.- Parameters:
keys- The sort keys which will be used for ordering the JSON resources returned by this query request.- Returns:
- This query request.
- Throws:
UnsupportedOperationException- If this query request does not permit changes to the sort keys.
-
addSortKey
QueryRequest addSortKey(String... keys)
Adds one or more sort keys which will be used for ordering the JSON resources returned by this query request.- Parameters:
keys- The sort keys which will be used for ordering the JSON resources returned by this query request.- Returns:
- This query request.
- Throws:
IllegalArgumentException- If one or more of the provided sort keys could not be parsed.UnsupportedOperationException- If this query request does not permit changes to the sort keys.
-
getAdditionalParameter
String getAdditionalParameter(String name)
Description copied from interface:RequestReturns the additional parameter which should be used to control the behavior of this action request.- Specified by:
getAdditionalParameterin interfaceRequest- Parameters:
name- The name of the additional parameter.- Returns:
- The additional parameter which should be used to control the behavior of this action request
-
getAdditionalParameters
Map<String,String> getAdditionalParameters()
Description copied from interface:RequestReturns the additional parameters which should be used to control the behavior of this action request. The returned map may be modified if permitted by this action request.- Specified by:
getAdditionalParametersin interfaceRequest- Returns:
- The additional parameters which should be used to control the behavior of this action request (never
null).
-
getFields
List<JsonPointer> getFields()
Description copied from interface:RequestReturns the list of fields which should be included with each JSON resource returned by this request. The returned list may be modified if permitted by this query request. An empty list indicates that all fields should be included.NOTE: field filtering alters the structure of a JSON resource and MUST only be performed once while processing a request. It is therefore the responsibility of front-end implementations (e.g. HTTP listeners, Servlets, etc) to perform field filtering. Request handler and resource provider implementations SHOULD NOT filter fields, but MAY choose to optimise their processing in order to return a resource containing only the fields targeted by the field filters.
-
getPageSize
int getPageSize()
Returns the requested page results page size or0if paged results are not required. For all paged result requests other than the initial request, a cookie should be provided with the query request. SeegetPagedResultsCookie()for more information.- Returns:
- The requested page results page size or
0if paged results are not required. - See Also:
getPagedResultsCookie(),getPagedResultsOffset()
-
pagingRequested
default boolean pagingRequested()
Returns whether paged results are requested.- Returns:
trueif paged results are requested,falseotherwise.- See Also:
getPageSize()
-
getPagedResultsCookie
String getPagedResultsCookie()
Returns the opaque cookie which is used by the resource provider to track its position in the set of query results. Paged results will be enabled if and only if the page size is non-zero.The cookie must be
nullin the initial query request sent by the client. For subsequent query requests the client must include the cookie returned with the previous query result, until the resource provider returns anullcookie indicating that the final page of results has been returned.Note: Cookies and offsets are mutually exclusive.
- Returns:
- The opaque cookie which is used by the resource provider to track its position in the set of query
results, or
nullif paged results are not requested (when the page size is 0) or if the first page of results is being requested (when the page size is non-zero). - See Also:
pagingRequested(),getPageSize(),getPagedResultsOffset()
-
getPagedResultsOffset
int getPagedResultsOffset()
Returns the zero-based index of the first resource which should be included in the query results. An offset of 0 (default) will return the first resource in the collection. An offset of1will return the second, and so on ...Note: Offsets and cookies are mutually exclusive. When a cookie is supplied only the default
0offset is supported.Offset must be a zero-based integer denoting the number of records to skip. This is very similar to the
LIMITandSKIPclauses in SQL databases.- Returns:
- The zero-based index within the result set of the first result which should be returned.
- See Also:
pagingRequested(),getPageSize(),getPagedResultsCookie()
-
getPreferredLocales
PreferredLocales getPreferredLocales()
Description copied from interface:RequestGet the locale preference for the request.- Specified by:
getPreferredLocalesin interfaceRequest- Returns:
- The
PreferredLocalesinstance for the request.
-
getQueryExpression
String getQueryExpression()
Returns the native query expression which will be used for processing the query request. An example of a native query expression is a SQL statement.NOTE: the native query expression, query filter, and query ID parameters are mutually exclusive and only one of them may be specified.
- Returns:
- The native query expression which will be used for processing the query request, or
nullif another type of query is to be performed. - See Also:
getQueryFilter(),getQueryId()
-
getQueryFilter
QueryFilter<JsonPointer> getQueryFilter()
Returns the query filter which will be used for selecting which JSON resources will be returned.NOTE: the native query expression, query filter, and query ID parameters are mutually exclusive and only one of them may be specified.
- Returns:
- The query filter which will be used for selecting which JSON resources will be returned, or
nullif another type of query is to be performed. - See Also:
getQueryExpression(),getQueryId()
-
getQueryId
String getQueryId()
Returns the query identifier for pre-defined queries.NOTE: the native query expression, query filter, and query ID parameters are mutually exclusive and only one of them may be specified.
- Returns:
- The query identifier for pre-defined queries, or
nullif a pre-defined query is not to be used, ornullif another type of query is to be performed. - See Also:
getQueryExpression(),getQueryFilter()
-
getRequestType
RequestType getRequestType()
Description copied from interface:RequestReturns the type of this request.- Specified by:
getRequestTypein interfaceRequest- Returns:
- The type of this request.
-
getResourcePath
String getResourcePath()
Description copied from interface:RequestReturns the non-nullpath of the JSON resource to which this request should be targeted. The resource path is relative and never begins or ends with a forward slash, but may be empty.NOTE: for resource provider implementations the resource path is relative to the current resource being accessed. See the description of
UriRouterContextfor more information.- Specified by:
getResourcePathin interfaceRequest- Returns:
- The non-
nullpath of the JSON resource to which this request should be targeted, which may be the empty string.
-
getResourcePathObject
ResourcePath getResourcePathObject()
Description copied from interface:RequestReturns the non-nullpath of the JSON resource to which this request should be targeted. The resource path is relative and never begins or ends with a forward slash, but may be empty.NOTE: for resource provider implementations the resource path is relative to the current resource being accessed. See the description of
UriRouterContextfor more information.- Specified by:
getResourcePathObjectin interfaceRequest- Returns:
- The non-
nullpath of the JSON resource to which this request should be targeted, which may be the empty string.
-
getResourceVersion
Version getResourceVersion()
Description copied from interface:RequestGets the requested API version of the resource.- Specified by:
getResourceVersionin interfaceRequest- Returns:
- The requested API version of the resource.
-
getSortKeys
List<SortKey> getSortKeys()
Returns the sort keys which should be used for ordering the JSON resources returned by this query request. The returned list may be modified if permitted by this query request.- Returns:
- The sort keys which should be used for ordering the JSON resources returned by this query request (never
null).
-
getTotalPagedResultsPolicy
CountPolicy getTotalPagedResultsPolicy()
Returns theCountPolicyused to calculateQueryResponse.getTotalPagedResults().- Returns:
- The count policy.
- See Also:
QueryResponse.getTotalPagedResults()
-
isCountOnly
boolean isCountOnly()
Return if the request should only return resource count.- Returns:
- whether the request should only return the resource count.
-
setAdditionalParameter
QueryRequest setAdditionalParameter(String name, String value) throws BadRequestException
Description copied from interface:RequestSets an additional parameter which should be used to control the behavior of this action request.- Specified by:
setAdditionalParameterin interfaceRequest- Parameters:
name- The name of the additional parameter.value- The additional parameter's value.- Returns:
- This request.
- Throws:
BadRequestException- If this request does not permit the additional parameter to be set.
-
setPageSize
QueryRequest setPageSize(int size)
Sets the requested page results page size or0if paged results are not required. For all paged result requests other than the initial request, a cookie should be provided with the query request. SeesetPagedResultsCookie(String)for more information.- Parameters:
size- The requested page results page size or0if paged results are not required.- Returns:
- This query request.
- Throws:
UnsupportedOperationException- If this query request does not permit changes to the page size.- See Also:
getPagedResultsCookie(),setPagedResultsOffset(int)
-
setPagedResultsCookie
QueryRequest setPagedResultsCookie(String cookie)
Sets the opaque cookie which is used by the resource provider to track its position in the set of query results. Paged results will be enabled if and only if the page size is non-zero.The cookie must be
nullin the initial query request sent by the client. For subsequent query requests the client must include the cookie returned with the previous query result, until the resource provider returns anullcookie indicating that the final page of results has been returned.When subsequent paged requests are being made no query parameters may be altered; doing so will result in undefined behavior. The only parameter that may be changed during paged requests is the page size.
- Parameters:
cookie- The opaque cookie which is used by the resource provider to track its position in the set of query results.- Returns:
- This query request.
- Throws:
UnsupportedOperationException- If this query request does not permit changes to the paged results cookie.- See Also:
setPageSize(int),addSortKey(SortKey...),addSortKey(String...)
-
setPagedResultsOffset
QueryRequest setPagedResultsOffset(int offset)
Sets the zero-based index of the first resource which should be included in the query results. An offset of 0 (default) will return the first resource in the collection. An offset of1will return the second, and so on ...Note: Offsets and cookies are mutually exclusive. When a cookie is supplied only the default
0offset is supported.Offset must be a zero-based integer denoting the number of records to skip. This is very similar to the
LIMITandSKIPclauses in SQL databases.- Parameters:
offset- The index within the result set of the first result which should be returned.- Returns:
- This query request.
- Throws:
UnsupportedOperationException- If this query request does not permit changes to the paged results offset.- See Also:
setPageSize(int),setPagedResultsCookie(String)
-
setPreferredLocales
QueryRequest setPreferredLocales(PreferredLocales preferredLocales)
Description copied from interface:RequestSet the locale preference for the request.- Specified by:
setPreferredLocalesin interfaceRequest- Parameters:
preferredLocales- ThePreferredLocalesinstance for the request.- Returns:
- This request.
-
setQueryExpression
QueryRequest setQueryExpression(String expression)
Sets the native query expression which will be used for processing the query request. An example of a native query expression is a SQL statement.NOTE: the native query expression, query filter, and query ID parameters are mutually exclusive and only one of them may be specified.
- Parameters:
expression- The native query expression which will be used for processing the query request, ornullif another type of query is to be performed.- Returns:
- This query request.
- Throws:
UnsupportedOperationException- If this query request does not permit changes to the query identifier.- See Also:
setQueryFilter(QueryFilter),setQueryId(String)
-
setQueryFilter
QueryRequest setQueryFilter(QueryFilter<JsonPointer> filter)
Sets the query filter which will be used for selecting which JSON resources will be returned.NOTE: the native query expression, query filter, and query ID parameters are mutually exclusive and only one of them may be specified.
- Parameters:
filter- The query filter which will be used for selecting which JSON resources will be returned, ornullif another type of query is to be performed.- Returns:
- This query request.
- Throws:
UnsupportedOperationException- If this query request does not permit changes to the query filter.- See Also:
setQueryExpression(String),setQueryId(String)
-
setQueryId
QueryRequest setQueryId(String id)
Sets the query identifier for pre-defined queries.NOTE: the native query expression, query filter, and query ID parameters are mutually exclusive and only one of them may be specified.
- Parameters:
id- The query identifier for pre-defined queries, ornullif another type of query is to be performed.- Returns:
- This query request.
- Throws:
UnsupportedOperationException- If this query request does not permit changes to the query identifier.- See Also:
setQueryExpression(String),setQueryFilter(QueryFilter)
-
setResourcePath
QueryRequest setResourcePath(ResourcePath path)
Description copied from interface:RequestSets the non-nullpath of the JSON resource to which this request should be targeted. The resource path is relative and never begins or ends with a forward slash, but may be empty.NOTE: for resource provider implementations the resource path is relative to the current resource being accessed. See the description of
UriRouterContextfor more information.- Specified by:
setResourcePathin interfaceRequest- Parameters:
path- The non-nullpath of the JSON resource to which this request should be targeted, which may be the empty string.- Returns:
- This request.
-
setResourcePath
QueryRequest setResourcePath(String path)
Description copied from interface:RequestSets the non-nullpath of the JSON resource to which this request should be targeted. The resource path is relative and never begins or ends with a forward slash, but may be empty.NOTE: for resource provider implementations the resource path is relative to the current resource being accessed. See the description of
UriRouterContextfor more information.- Specified by:
setResourcePathin interfaceRequest- Parameters:
path- The non-nullpath of the JSON resource to which this request should be targeted, which may be the empty string. The path should be URL-encoded.- Returns:
- This request.
-
setResourceVersion
QueryRequest setResourceVersion(Version resourceVersion)
Description copied from interface:RequestSets the requested API version of the resource.- Specified by:
setResourceVersionin interfaceRequest- Parameters:
resourceVersion- The requested API version of the resource.- Returns:
- This request.
-
setTotalPagedResultsPolicy
QueryRequest setTotalPagedResultsPolicy(CountPolicy policy)
Sets the policy for calculating the total number of paged results. If no count policy is supplied or paged results are not requested a default ofCountPolicy.NONEwill be used. This will result in no count being performed and no overhead incurred.- Parameters:
policy- The policy used to calculate total paged results- Returns:
- This query request.
- See Also:
QueryResponse.getTotalPagedResultsPolicy(),QueryResponse.getTotalPagedResults()
-
setCountOnly
QueryRequest setCountOnly(boolean countOnly)
Sets whether the request was to only provide a count of the query results.- Parameters:
countOnly- whether to return result count only.- Returns:
- this query request
-
toJsonValue
JsonValue toJsonValue()
Description copied from interface:RequestReturn a JsonValue representation of this request.- Specified by:
toJsonValuein interfaceRequest- Returns:
- this request as a JsonValue
-
-